rps test: be more flexible in printing
authorJulius Bünger <buenger@mytum.de>
Sun, 8 Apr 2018 22:17:57 +0000 (00:17 +0200)
committerJulius Bünger <buenger@mytum.de>
Sun, 8 Apr 2018 22:17:57 +0000 (00:17 +0200)
src/rps/rps-test_util.h
src/rps/test_rps.c

index e8e352ff60dcf8eea1bd0849c022010fc04a5342..725be815c85b2c45d65e8ad4745b9d90346f9c21 100644 (file)
@@ -58,8 +58,18 @@ create_file (const char *name);
     else\
       to_file_(file_name,tmp_buf);\
   } while (0);
+#  define to_file_w_len(file_name, len, ...) do {char tmp_buf[len];\
+    int size;\
+    size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
+    if (0 > size)\
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
+           "Failed to create tmp_buf\n");\
+    else\
+      to_file_(file_name,tmp_buf);\
+  } while (0);
 #else /* TO_FILE */
 #  define to_file(file_name, ...)
+#  define to_file_w_len(file_name, len, ...)
 #endif /* TO_FILE */
 
 #endif /* RPS_TEST_UTIL_H */
index b4c5e6cb17c8407034ad911378b882105815ed71..b46fc0c1e573e435b0d55a7c18f496a4961b9e81 100644 (file)
@@ -2017,7 +2017,9 @@ static void compute_probabilities (uint32_t peer_idx)
     GNUNET_assert (0 <= tmp);
   }
 
-  to_file (rps_peers[peer_idx].file_name_probs, probs_as_str);
+  to_file_w_len (rps_peers[peer_idx].file_name_probs,
+                 probs_as_str_size,
+                 probs_as_str);
   GNUNET_free (probs_as_str);
 }