Fix JSMN unescape function

Fix JSMN unescape function (#10107)
This commit is contained in:
Theo Arends 2020-12-13 17:31:46 +01:00
parent 5a57ec3dab
commit 9c5162672b
1 changed files with 6 additions and 1 deletions

View File

@ -399,6 +399,7 @@ void json_unescape(char* string) {
c = string[++i];
switch (c) {
case 0:
string[outlength++] = 0;
return; // end of stream
case '\"':
case '/':
@ -427,7 +428,10 @@ void json_unescape(char* string) {
uint32_t hexval = 0;
for (uint32_t j = 0; j < 4; ++j) {
char val = string[++i];
if (0 == val) { return; } // we reached end of string
if (0 == val) {
string[outlength++] = 0;
return; // we reached end of string
}
uint32_t uival = 0;
if ((val >= 'a') && (val <= 'f'))
uival = 10 + (val - 'a');
@ -450,4 +454,5 @@ void json_unescape(char* string) {
string[outlength++] = c;
}
}
string[outlength++] = 0;
}