commit 7021246581ac32b6a2010bf4afd4685b54369259
parent dae20dfe73b57ff796bda6379ae98486efa49881
Author: Christian Grothoff <christian@grothoff.org>
Date: Thu, 22 Feb 2018 18:19:02 +0100
fix memcpy calls with NULL and len 0 (pretty harmless, but causing compiler warnings)
Diffstat:
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/src/examples/demo.c b/src/examples/demo.c
@@ -433,7 +433,7 @@ struct UploadContext
* @param ret string to update, NULL or 0-terminated
* @param data data to append
* @param size number of bytes in 'data'
- * @return MHD_NO on allocation failure, MHD_YES on success
+ * @return #MHD_NO on allocation failure, #MHD_YES on success
*/
static int
do_append (char **ret,
@@ -447,13 +447,18 @@ do_append (char **ret,
old_len = 0;
else
old_len = strlen (*ret);
- buf = malloc (old_len + size + 1);
- if (NULL == buf)
+ if (NULL == (buf = malloc (old_len + size + 1)))
return MHD_NO;
- memcpy (buf, *ret, old_len);
if (NULL != *ret)
- free (*ret);
- memcpy (&buf[old_len], data, size);
+ {
+ memcpy (buf,
+ *ret,
+ old_len);
+ free (*ret);
+ }
+ memcpy (&buf[old_len],
+ data,
+ size);
buf[old_len + size] = '\0';
*ret = buf;
return MHD_YES;
@@ -476,8 +481,8 @@ do_append (char **ret,
* specified offset
* @param off offset of data in the overall value
* @param size number of bytes in data available
- * @return MHD_YES to continue iterating,
- * MHD_NO to abort the iteration
+ * @return #MHD_YES to continue iterating,
+ * #MHD_NO to abort the iteration
*/
static int
process_upload_data (void *cls,
diff --git a/src/examples/demo_https.c b/src/examples/demo_https.c
@@ -434,7 +434,7 @@ struct UploadContext
* @param ret string to update, NULL or 0-terminated
* @param data data to append
* @param size number of bytes in 'data'
- * @return MHD_NO on allocation failure, MHD_YES on success
+ * @return #MHD_NO on allocation failure, #MHD_YES on success
*/
static int
do_append (char **ret,
@@ -448,13 +448,18 @@ do_append (char **ret,
old_len = 0;
else
old_len = strlen (*ret);
- buf = malloc (old_len + size + 1);
- if (NULL == buf)
+ if (NULL == (buf = malloc (old_len + size + 1)))
return MHD_NO;
- memcpy (buf, *ret, old_len);
if (NULL != *ret)
- free (*ret);
- memcpy (&buf[old_len], data, size);
+ {
+ memcpy (buf,
+ *ret,
+ old_len);
+ free (*ret);
+ }
+ memcpy (&buf[old_len],
+ data,
+ size);
buf[old_len + size] = '\0';
*ret = buf;
return MHD_YES;