fprintftime: wrap macro code argument in "do {...} while(0)"
authorJim Meyering <meyering@redhat.com>
Wed, 28 Oct 2009 10:25:29 +0000 (11:25 +0100)
committerJim Meyering <meyering@redhat.com>
Wed, 28 Oct 2009 10:25:29 +0000 (11:25 +0100)
* lib/strftime.c (cpy) [FPRINTFTIME]: The second argument to the
cpy macro must be a statement that can be followed by a semicolon.
Now that the else clause contains a comment and is hence longer
than one line, I require curly braces.  That in turn requires
that we wrap this code block in the standard do...while(0).

ChangeLog
lib/strftime.c

index 32405a9843f5b1d956f0ae355f3f9f80755ef318..7982453a86afada814c886c4cc6629d2780712bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-10-28  Jim Meyering  <meyering@redhat.com>
 
+       fprintftime: wrap macro code argument in "do {...} while(0)"
+       * lib/strftime.c (cpy) [FPRINTFTIME]: The second argument to the
+       cpy macro must be a statement that can be followed by a semicolon.
+       Now that the else clause contains a comment and is hence longer
+       than one line, I require curly braces.  That in turn requires
+       that we wrap this code block in the standard do...while(0).
+
        fprintftime: remove stray semicolon from previous change
        * lib/strftime.c (cpy) [FPRINTFTIME]: Remove trailing semicolon.
 
index 4467415a5ef67e602bd8db777f013aa2d5e15b26..7d64c15264634bf6df2eea42aa0a34b3af14711d 100644 (file)
@@ -199,6 +199,8 @@ extern char *tzname[];
 #if FPRINTFTIME
 # define cpy(n, s) \
     add ((n),                                                                \
+     do                                                                              \
+       {                                                                     \
         if (to_lowcase)                                                      \
           fwrite_lowcase (p, (s), _n);                                       \
         else if (to_uppcase)                                                 \
@@ -211,8 +213,11 @@ extern char *tzname[];
                is intended to be consistent with the one from ISO C,         \
                which permits failure due to ENOMEM *without* setting the     \
                stream's error indicator.  */                                 \
-            ignore_value (fwrite ((s), _n, 1, p)))                           \
-          }
+            ignore_value (fwrite ((s), _n, 1, p));                           \
+          }                                                                  \
+       }                                                                     \
+     while (0)                                                               \
+    )
 #else
 # define cpy(n, s)                                                           \
     add ((n),                                                                \