1
0
Fork 0
forked from lthn/blockchain

fixed a rare issue with printing random control characters to the console, breaking it

This commit is contained in:
sowle 2025-05-30 14:49:31 +02:00
parent be0b6ab35e
commit c4c8d65798
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC

View file

@ -34,7 +34,20 @@ namespace epee
{
namespace json
{
#define CHECK_ISSPACE() if(!isspace(*it)){ ASSERT_MES_AND_THROW("Wrong JSON character at: " << std::string(it, buf_end));}
namespace details
{
inline bool report_wrong_char_with_context(const std::string::const_iterator begin, const std::string::const_iterator it, const std::string::const_iterator end)
{
auto before_it = it - std::min(it - begin, static_cast<ptrdiff_t>(8));
auto after_it = it + std::min(end - it, static_cast<ptrdiff_t>(8));
std::string escaped_str(before_it, after_it);
std::replace_if(escaped_str.begin(), escaped_str.end(), [](int c){ return std::isprint(c); }, '?');
ASSERT_MES_AND_THROW("Wrong JSON character 0x" << std::hex << (int)*it << ", context: " << escaped_str);
}
}
#define CHECK_ISSPACE() if (!isspace(*it)) details::report_wrong_char_with_context(sec_buf_begin, it, buf_end)
/*inline void parse_error()
{