diff options
Diffstat (limited to 'src/examples/demo.c')
-rw-r--r-- | src/examples/demo.c | 21 |
1 files changed, 13 insertions, 8 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, |