changeset 12206:5b7b0b8645f1

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).
author Jim Meyering <meyering@redhat.com>
date Wed, 28 Oct 2009 11:25:29 +0100
parents bd01eb4a7146
children 35acba1c7bcd
files ChangeLog lib/strftime.c
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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.
 
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -199,6 +199,8 @@
 #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 @@
 		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),								      \