mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
MOX-6029 add null terminators
This commit is contained in:
parent
71a5abfb1a
commit
27f7a77d47
9
cJSON.c
9
cJSON.c
@ -405,9 +405,11 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (strlen(valuestring) <= strlen(object->valuestring))
|
int objectLen = strlen(object->valuestring);
|
||||||
|
if (strlen(valuestring) <= objectLen)
|
||||||
{
|
{
|
||||||
strncpy(object->valuestring, valuestring, strlen(object->valuestring));
|
strncpy(object->valuestring, valuestring, objectLen+1);
|
||||||
|
object->valuestring[objectLen] = '\0';
|
||||||
return object->valuestring;
|
return object->valuestring;
|
||||||
}
|
}
|
||||||
copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks);
|
copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks);
|
||||||
@ -1382,6 +1384,7 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
strncpy((char*)output, "null", 5);
|
strncpy((char*)output, "null", 5);
|
||||||
|
output[4] = 0;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case cJSON_False:
|
case cJSON_False:
|
||||||
@ -1391,6 +1394,7 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
strncpy((char*)output, "false", 6);
|
strncpy((char*)output, "false", 6);
|
||||||
|
output[5] = 0;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case cJSON_True:
|
case cJSON_True:
|
||||||
@ -1400,6 +1404,7 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
strncpy((char*)output, "true", 5);
|
strncpy((char*)output, "true", 5);
|
||||||
|
output[4] = 0;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case cJSON_Number:
|
case cJSON_Number:
|
||||||
|
Loading…
Reference in New Issue
Block a user