>From d1917dcdf83e4e754f2c5606a729faa6566e9939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Thu, 23 Nov 2017 17:01:04 -0800 Subject: [PATCH] posixtm: avoid maybe-uninitialized warnings * lib/posixtm.c (year): Ensure that tm_year is initialized. Since commit 619700e1, gcc-6.3 at least fails to compile with: lib/posixtm.c: In function 'posixtime': lib/posixtm.c:214:20: error: '*((void *)&tm0+20)' may be used uninitialized in this function [-Werror=maybe-uninitialized] if ((tm0.tm_year ^ tm->tm_year) ~~~~~~~~~~~~~^~~~~~~~~~~~~~ --- ChangeLog | 11 +++++++++++ lib/posixtm.c | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 700ee09..a24d7c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2017-11-23 Pádraig Brady + + posixtm: avoid maybe-uninitialized warnings + * lib/posixtm.c (year): Ensure that tm_year is initialized. + Since commit 619700e1, gcc-6.3 at least fails to compile with: + lib/posixtm.c: In function 'posixtime': + lib/posixtm.c:214:20: error: '*((void *)&tm0+20)' may be used + uninitialized in this function [-Werror=maybe-uninitialized] + if ((tm0.tm_year ^ tm->tm_year) + ~~~~~~~~~~~~~^~~~~~~~~~~~~~ + 2017-11-23 Paul Eggert stat: work around Solaris bug with tv_nsec < 0 diff --git a/lib/posixtm.c b/lib/posixtm.c index 030f704..bc75487 100644 --- a/lib/posixtm.c +++ b/lib/posixtm.c @@ -22,6 +22,7 @@ #include "posixtm.h" +#include #include #include #include @@ -96,7 +97,7 @@ year (struct tm *tm, const int *digit_pair, size_t n, unsigned int syntax_bits) break; default: - abort (); + assert (!"invalid year length"); } return true; @@ -110,6 +111,10 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) int *p; size_t i; + /* Ensure tm_year initialized */ + tm->tm_year = 0; /* Avoid uninitialized warnings */ + assert (syntax_bits & PDS_LEADING_YEAR || syntax_bits & PDS_TRAILING_YEAR); + size_t s_len = strlen (s); size_t len = s_len; -- 2.9.3