vsprintf returns negative on error.
authoranryko <a.shvenke@gmail.com>
Sun, 7 Jan 2018 19:20:11 +0000 (20:20 +0100)
committeranryko <a.shvenke@gmail.com>
Sun, 7 Jan 2018 19:20:11 +0000 (20:20 +0100)
src/nse/gnunet-nse-profiler.c
src/util/common_allocation.c

index 4a10022e3ce81b5a308a37d78ad9c77bb34186b5..b665812e53bb35d22445be03147e7b6bb8b833a3 100644 (file)
@@ -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);
index 80047bb5269d01b0bb4a787962e3a483b2d8e311..1c55d72b5657f5951284d4b692f45e21413c3c9f 100644 (file)
@@ -475,8 +475,8 @@ GNUNET_xgrow_ (void **old,
  */
 int
 GNUNET_asprintf (char **buf,
-                const char *format,
-                ...)
+                 const char *format,
+                 ...)
 {
   int ret;
   va_list args;