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/demo_https.c | |
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/demo_https.c')
-rw-r--r-- | src/examples/demo_https.c | 17 |
1 files changed, 11 insertions, 6 deletions
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; |