fix memcpy calls with NULL and len 0 (pretty harmless, but causing compiler warnings)

This commit is contained in:
Christian Grothoff
2018-02-22 18:19:02 +01:00
parent dae20dfe73
commit 7021246581
2 changed files with 24 additions and 14 deletions
+13 -8
View File
@@ -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,
+11 -6
View File
@@ -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;