From 3d9184e4ae0042ca8d06135168bf4eb9aff67cd8 Mon Sep 17 00:00:00 2001 From: Caio Luppi Date: Thu, 13 Aug 2015 13:37:51 -0400 Subject: [PATCH] Quick fix to address subsequent unicode chars prob sprintf prints a null character at the end of the string and overwrites the \\ character that was set during initalization (line 4625). Whenever there are two subsequent characters that are escaped, the first one ends up overwriting the second's backslash. In case there's a non-escaped string between them, the string itself overwrites the null character. Here's an easy way to reproduce this issue: string bytes{0x7, 0x7}; cout << "bytes: " << bytes << endl; json j; j["string"] = bytes; cout << j.dump() << endl; // expected result: \u0007\u0007 // actual result: \u0007\0u0007 --- src/json.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/json.hpp b/src/json.hpp index 993d12e2a..bdea958f1 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -4692,6 +4692,8 @@ class basic_json // print character c as \uxxxx sprintf(&result[pos + 1], "u%04x", int(c)); pos += 6; + // overwrite trailing null character + result[pos] = '\\'; } else {