bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] filevercmp, posixtm: avoid compiler warnings with -O3


From: Pádraig Brady
Subject: [PATCH] filevercmp, posixtm: avoid compiler warnings with -O3
Date: Fri, 5 Dec 2014 13:05:31 +0000

* 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.
---
 lib/filevercmp.h | 2 +-
 lib/posixtm.c    | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/filevercmp.h b/lib/filevercmp.h
index 72785cd..ad359eb 100644
--- a/lib/filevercmp.h
+++ b/lib/filevercmp.h
@@ -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 */
diff --git a/lib/posixtm.c b/lib/posixtm.c
index 2fe81ab..3023932 100644
--- a/lib/posixtm.c
+++ b/lib/posixtm.c
@@ -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 @@ posix_time_parse (struct tm *tm, const char *s, unsigned 
int syntax_bits)
   if (len != 8 && len != 10 && len != 12)
     return 1;
 
+  IF_LINT(if (len < 8) return 1;)
+
   if (dot)
     {
       if (!(syntax_bits & PDS_SECONDS))
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]