changeset 37496:c8a2b80de10d

filevercmp, posixtm: avoid compiler warnings with -O3 * lib/filevercmp.h (filevercmp): Tag with _GL_ATTRIBUTE_PURE * lib/posixtm.c: (IF_LINT): Define. (posix_time_parse): Use it to void a "may be used uninitialized" warning, seen only with -O3.
author Pádraig Brady <P@draigBrady.com>
date Fri, 05 Dec 2014 12:32:49 +0000
parents b3d5e81ca757
children c3bbb3ce357d
files ChangeLog lib/filevercmp.h lib/posixtm.c
diffstat 3 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Dec 05 11:30:27 2014 +0100
+++ b/ChangeLog	Fri Dec 05 12:32:49 2014 +0000
@@ -1,3 +1,11 @@
+2014-12-05  Pádraig Brady  <P@draigBrady.com>
+
+	filevercmp, posixtm: avoid compiler warnings with -O3
+	* lib/filevercmp.h (filevercmp): Tag with _GL_ATTRIBUTE_PURE
+	* lib/posixtm.c: (IF_LINT): Define.
+	(posix_time_parse): Use it to void a "may be used uninitialized"
+	warning, seen only with -O3.
+
 2014-12-05  Bruno Haible  <bruno@clisp.org>
 
 	Fix LDBL80_WORDS macro on big endian platforms.
--- a/lib/filevercmp.h	Fri Dec 05 11:30:27 2014 +0100
+++ b/lib/filevercmp.h	Fri Dec 05 12:32:49 2014 +0000
@@ -37,6 +37,6 @@
    PREFIX VER2 SUFFIX) < 0.
 
    This function is intended to be a replacement for strverscmp. */
-int filevercmp (const char *s1, const char *s2);
+int filevercmp (const char *s1, const char *s2) _GL_ATTRIBUTE_PURE;
 
 #endif /* FILEVERCMP_H */
--- a/lib/posixtm.c	Fri Dec 05 11:30:27 2014 +0100
+++ b/lib/posixtm.c	Fri Dec 05 12:32:49 2014 +0000
@@ -27,6 +27,13 @@
 #include <sys/types.h>
 #include <string.h>
 
+/* Use this to suppress gcc's "...may be used uninitialized" warnings. */
+#ifdef lint
+# define IF_LINT(Code) Code
+#else
+# define IF_LINT(Code) /* empty */
+#endif
+
 #if USE_UNLOCKED_IO
 # include "unlocked-io.h"
 #endif
@@ -118,6 +125,8 @@
   if (len != 8 && len != 10 && len != 12)
     return 1;
 
+  IF_LINT(if (len < 8) return 1;)
+
   if (dot)
     {
       if (!(syntax_bits & PDS_SECONDS))