diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-02-22 18:19:02 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-02-22 18:19:02 +0100 |
commit | 7021246581ac32b6a2010bf4afd4685b54369259 (patch) | |
tree | 9e2b993d93b6504e8fff4a1fb3cb5f0cf58ca06e /src/examples | |
parent | dae20dfe73b57ff796bda6379ae98486efa49881 (diff) | |
download | libmicrohttpd-7021246581ac32b6a2010bf4afd4685b54369259.tar.gz libmicrohttpd-7021246581ac32b6a2010bf4afd4685b54369259.zip |
fix memcpy calls with NULL and len 0 (pretty harmless, but causing compiler warnings)
Diffstat (limited to 'src/examples')
-rw-r--r-- | src/examples/demo.c | 21 | ||||
-rw-r--r-- | src/examples/demo_https.c | 17 |
2 files changed, 24 insertions, 14 deletions
diff --git a/src/examples/demo.c b/src/examples/demo.c index 6c9ad049..858fb735 100644 --- a/src/examples/demo.c +++ b/src/examples/demo.c | |||
@@ -433,7 +433,7 @@ struct UploadContext | |||
433 | * @param ret string to update, NULL or 0-terminated | 433 | * @param ret string to update, NULL or 0-terminated |
434 | * @param data data to append | 434 | * @param data data to append |
435 | * @param size number of bytes in 'data' | 435 | * @param size number of bytes in 'data' |
436 | * @return MHD_NO on allocation failure, MHD_YES on success | 436 | * @return #MHD_NO on allocation failure, #MHD_YES on success |
437 | */ | 437 | */ |
438 | static int | 438 | static int |
439 | do_append (char **ret, | 439 | do_append (char **ret, |
@@ -447,13 +447,18 @@ do_append (char **ret, | |||
447 | old_len = 0; | 447 | old_len = 0; |
448 | else | 448 | else |
449 | old_len = strlen (*ret); | 449 | old_len = strlen (*ret); |
450 | buf = malloc (old_len + size + 1); | 450 | if (NULL == (buf = malloc (old_len + size + 1))) |
451 | if (NULL == buf) | ||
452 | return MHD_NO; | 451 | return MHD_NO; |
453 | memcpy (buf, *ret, old_len); | ||
454 | if (NULL != *ret) | 452 | if (NULL != *ret) |
455 | free (*ret); | 453 | { |
456 | memcpy (&buf[old_len], data, size); | 454 | memcpy (buf, |
455 | *ret, | ||
456 | old_len); | ||
457 | free (*ret); | ||
458 | } | ||
459 | memcpy (&buf[old_len], | ||
460 | data, | ||
461 | size); | ||
457 | buf[old_len + size] = '\0'; | 462 | buf[old_len + size] = '\0'; |
458 | *ret = buf; | 463 | *ret = buf; |
459 | return MHD_YES; | 464 | return MHD_YES; |
@@ -476,8 +481,8 @@ do_append (char **ret, | |||
476 | * specified offset | 481 | * specified offset |
477 | * @param off offset of data in the overall value | 482 | * @param off offset of data in the overall value |
478 | * @param size number of bytes in data available | 483 | * @param size number of bytes in data available |
479 | * @return MHD_YES to continue iterating, | 484 | * @return #MHD_YES to continue iterating, |
480 | * MHD_NO to abort the iteration | 485 | * #MHD_NO to abort the iteration |
481 | */ | 486 | */ |
482 | static int | 487 | static int |
483 | process_upload_data (void *cls, | 488 | process_upload_data (void *cls, |
diff --git a/src/examples/demo_https.c b/src/examples/demo_https.c index 806464a2..88b01bbf 100644 --- a/src/examples/demo_https.c +++ b/src/examples/demo_https.c | |||
@@ -434,7 +434,7 @@ struct UploadContext | |||
434 | * @param ret string to update, NULL or 0-terminated | 434 | * @param ret string to update, NULL or 0-terminated |
435 | * @param data data to append | 435 | * @param data data to append |
436 | * @param size number of bytes in 'data' | 436 | * @param size number of bytes in 'data' |
437 | * @return MHD_NO on allocation failure, MHD_YES on success | 437 | * @return #MHD_NO on allocation failure, #MHD_YES on success |
438 | */ | 438 | */ |
439 | static int | 439 | static int |
440 | do_append (char **ret, | 440 | do_append (char **ret, |
@@ -448,13 +448,18 @@ do_append (char **ret, | |||
448 | old_len = 0; | 448 | old_len = 0; |
449 | else | 449 | else |
450 | old_len = strlen (*ret); | 450 | old_len = strlen (*ret); |
451 | buf = malloc (old_len + size + 1); | 451 | if (NULL == (buf = malloc (old_len + size + 1))) |
452 | if (NULL == buf) | ||
453 | return MHD_NO; | 452 | return MHD_NO; |
454 | memcpy (buf, *ret, old_len); | ||
455 | if (NULL != *ret) | 453 | if (NULL != *ret) |
456 | free (*ret); | 454 | { |
457 | memcpy (&buf[old_len], data, size); | 455 | memcpy (buf, |
456 | *ret, | ||
457 | old_len); | ||
458 | free (*ret); | ||
459 | } | ||
460 | memcpy (&buf[old_len], | ||
461 | data, | ||
462 | size); | ||
458 | buf[old_len + size] = '\0'; | 463 | buf[old_len + size] = '\0'; |
459 | *ret = buf; | 464 | *ret = buf; |
460 | return MHD_YES; | 465 | return MHD_YES; |