From 608c456a6849dadecab156657854f5335d86cb3d Mon Sep 17 00:00:00 2001 From: anryko Date: Sun, 7 Jan 2018 20:20:11 +0100 Subject: [PATCH] vsprintf returns negative on error. --- src/nse/gnunet-nse-profiler.c | 19 +++++++++++++------ src/util/common_allocation.c | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c index 4a10022e3..b665812e5 100644 --- a/src/nse/gnunet-nse-profiler.c +++ b/src/nse/gnunet-nse-profiler.c @@ -374,13 +374,14 @@ nse_disconnect_adapter (void *cls, */ static int stat_iterator (void *cls, - const char *subsystem, - const char *name, - uint64_t value, int is_persistent) + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) { char *output_buffer; struct GNUNET_TIME_Absolute now; - size_t size; + int size; unsigned int flag; GNUNET_assert (NULL != data_file); @@ -390,8 +391,14 @@ stat_iterator (void *cls, flag = 1; size = GNUNET_asprintf (&output_buffer, "%llu %llu %u\n", now.abs_value_us / 1000LL / 1000LL, - value, flag); - if (size != GNUNET_DISK_file_write (data_file, output_buffer, size)) + value, flag); + if (0 > size) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n"); + GNUNET_free (output_buffer); + return GNUNET_SYSERR; + } + if (size != GNUNET_DISK_file_write (data_file, output_buffer, (size_t) size)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); GNUNET_free (output_buffer); diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 80047bb52..1c55d72b5 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -475,8 +475,8 @@ GNUNET_xgrow_ (void **old, */ int GNUNET_asprintf (char **buf, - const char *format, - ...) + const char *format, + ...) { int ret; va_list args; -- 2.25.1