Wrap the content of macro with do/while to make it safer as per code review comment
[collectd.git] / src / utils_cmd_putnotif.c
index d09eeb3..f8e734d 100644 (file)
 #include "utils_parse_option.h"
 
 #define print_to_socket(fh, ...) \
-  if (fprintf (fh, __VA_ARGS__) < 0) { \
-    char errbuf[1024]; \
-    WARNING ("handle_putnotif: failed to write to socket #%i: %s", \
-       fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
-    return -1; \
-  } \
-  fflush(fh);
+  do { \
+    if (fprintf (fh, __VA_ARGS__) < 0) { \
+      char errbuf[1024]; \
+      WARNING ("handle_putnotif: failed to write to socket #%i: %s", \
+          fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
+      return -1; \
+    } \
+    fflush(fh); \
+  } while (0);
 
 static int set_option_severity (notification_t *n, const char *value)
 {