Skip to content

Commit 975c65c

Browse files
committed
Update static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) in cJSON.c
changes to the function: static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) The function: strcpy((char*)output, "false") causes memory crashes in ThreadX(at least in my case). The modification delivers the same results, but without the crash.
1 parent 87d8f09 commit 975c65c

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

cJSON.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,15 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp
13861386
{
13871387
return false;
13881388
}
1389-
strcpy((char*)output, "null");
1389+
//
1390+
// this modifications are made because the strcpy does not work in some cases
1391+
*output++ = 'n';
1392+
*output++ = 'u';
1393+
*output++ = 'l';
1394+
*output++ = 'l';
1395+
*output = '\0';
1396+
// this does not work
1397+
//strcpy((char*)output, "null");
13901398
return true;
13911399

13921400
case cJSON_False:
@@ -1395,7 +1403,16 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp
13951403
{
13961404
return false;
13971405
}
1398-
strcpy((char*)output, "false");
1406+
//
1407+
// this modifications are made because the strcpy does not work in some cases
1408+
*output++ = 'f';
1409+
*output++ = 'a';
1410+
*output++ = 'l';
1411+
*output++ = 's';
1412+
*output++ = 'e';
1413+
*output = '\0';
1414+
// this does not work
1415+
//strcpy((char*)output, "false");
13991416
return true;
14001417

14011418
case cJSON_True:
@@ -1404,7 +1421,15 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp
14041421
{
14051422
return false;
14061423
}
1407-
strcpy((char*)output, "true");
1424+
//
1425+
// this modifications are made because the strcpy does not work in some cases
1426+
*output++ = 't';
1427+
*output++ = 'r';
1428+
*output++ = 'u';
1429+
*output++ = 'e';
1430+
*output = '\0';
1431+
// this does not work
1432+
//strcpy((char*)output, "true");
14081433
return true;
14091434

14101435
case cJSON_Number:

0 commit comments

Comments
 (0)