[tz] room for one more (char*) cast?
Paul Eggert
eggert at cs.ucla.edu
Thu Jun 19 06:38:40 UTC 2014
enh wrote:
> bionic/libc/tzcode/localtime.c:1357:27: warning: assignment discards
> 'const' qualifier from pointer target type [enabled by default]
> tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
Sorry, I don't see how that can happen with the current tzcode; 'sp' is
of type 'struct state *', so sp->chars is of type 'char *', with no
'const' qualifier. Maybe the bionic version has a 'const' that the tz
version doesn't, a 'const' that should be removed?
I did try a "make CFLAGS='$(GCC_DEBUG_FLAGS)'" on Ubuntu 14.04 and found
some opportunities for improvement and simplification in this area. I
pushed the attached patch to the experimental version on github to
address the problems I found. This patch is also tested with my build
of GCC 4.9.0 on Fedora 20.
-------------- next part --------------
From 99544d30aa2d71c13b42ec9109a4eb1ec53b5c4b Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert at cs.ucla.edu>
Date: Wed, 18 Jun 2014 23:25:57 -0700
Subject: [PATCH] Update to pacify recent GCC's static checking.
These changes pacify gcc 4.8.2-19ubuntu1 on Ubuntu 14.04,
and take advantage of recently-added GCC options when compiling
with GCC_DEBUG_FLAGS.
* Makefile (GCC_DEBUG_FLAGS): Add -Wdeclaration-after-statement,
-Wjump-misses-init, -Wsuggest-attribute=format.
* date.c (copyright, sccsid):
* strftime.c (sccsid):
Remove unused vars.
* date.c (main):
* localtime.c (tzparse):
Remove no-longer-needed uses of INITIALIZE; GCC is smart enough to
figure these out on its own now.
* localtime.c (gmtsub): Redo initialization of gmt_is_set to pacify GCC.
Retry malloc next time even if it failed this time.
* private.h, zdump.c (GNUC_or_lint): Remove, as it provoked a GCC
diagnostic about unused macros in some cases. Instead, just use
'lint'. All uses removed.
(TZ_DOMAIN): Don't define unless needed, as otherwise it provokes
a GCC diagnostic about unused macros.
* private.h (INITIALIZE): Simplify accordingly.
* NEWS: Document this.
---
Makefile | 6 ++++--
NEWS | 2 ++
date.c | 14 --------------
localtime.c | 7 ++++---
private.h | 28 +++++++---------------------
strftime.c | 6 ------
zdump.c | 16 +++-------------
7 files changed, 20 insertions(+), 59 deletions(-)
diff --git a/Makefile b/Makefile
index 0fab5a3..73147fb 100644
--- a/Makefile
+++ b/Makefile
@@ -134,14 +134,16 @@ LDLIBS=
GCC_DEBUG_FLAGS = -Dlint -g3 -O3 -fno-common -fstrict-aliasing \
-Wall -Wextra \
-Wbad-function-cast -Wcast-align -Wcast-qual \
- -Wformat=2 -Winit-self \
+ -Wdeclaration-after-statement \
+ -Wformat=2 -Winit-self -Wjump-misses-init \
-Wmissing-declarations -Wmissing-noreturn -Wmissing-prototypes \
-Wnested-externs -Wno-address -Wno-cast-qual \
-Wno-format-nonliteral -Wno-sign-compare -Wno-sign-conversion \
-Wno-type-limits \
-Wno-unused-parameter -Woverlength-strings -Wpointer-arith \
-Wshadow -Wstrict-prototypes -Wsuggest-attribute=const \
- -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines \
+ -Wsuggest-attribute=format -Wsuggest-attribute=noreturn \
+ -Wsuggest-attribute=pure -Wtrampolines \
-Wwrite-strings
#
# If you want to use System V compatibility code, add
diff --git a/NEWS b/NEWS
index ed55089..a2d5010 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ Unreleased, experimental changes
Error diagnostics of 'zic' and 'yearistype' have been reworded so that
they no longer use ASCII '-' as if it were a dash.
+ Some lint has been removed when using GCC_DEBUG_FLAGS with GCC 4.9.0.
+
Changes affecting documentation and commentary
Documentation and commentary now prefer UTF-8 to US-ASCII,
diff --git a/date.c b/date.c
index 42ed16a..a9ca67f 100644
--- a/date.c
+++ b/date.c
@@ -15,16 +15,6 @@
* WARRANTIES OF MERCHANT[A]BILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1985, 1987, 1988 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)date.c 4.23 (Berkeley) 9/20/88";
-#endif /* not lint */
-
#include "private.h"
#if HAVE_ADJTIME || HAVE_SETTIMEOFDAY
#include "sys/time.h" /* for struct timeval, struct timezone */
@@ -99,10 +89,6 @@ main(const int argc, char *argv[])
char * endarg;
INITIALIZE(dousg);
- INITIALIZE(minuteswest);
- INITIALIZE(dsttime);
- INITIALIZE(adjust);
- INITIALIZE(t);
#ifdef LC_ALL
(void) setlocale(LC_ALL, "");
#endif /* defined(LC_ALL) */
diff --git a/localtime.c b/localtime.c
index ec0715d..e2cf5c2 100644
--- a/localtime.c
+++ b/localtime.c
@@ -944,7 +944,6 @@ tzparse(const char *name, register struct state *const sp,
register int load_result;
static struct ttinfo zttinfo;
- INITIALIZE(dstname);
stdname = name;
if (lastditch) {
stdlen = strlen(name); /* length of standard zone name */
@@ -1368,11 +1367,13 @@ gmtsub(const time_t *const timep, const int_fast32_t offset,
register struct tm * result;
if (!gmt_is_set) {
- gmt_is_set = TRUE;
#ifdef ALL_STATE
gmtptr = malloc(sizeof *gmtptr);
+ gmt_is_set = gmtptr != NULL;
+#else
+ gmt_is_set = TRUE;
#endif /* defined ALL_STATE */
- if (gmtptr != NULL)
+ if (gmt_is_set)
gmtload(gmtptr);
}
result = timesub(timep, offset, gmtptr, tmp);
diff --git a/private.h b/private.h
index be0c8c2..42bf6e6 100644
--- a/private.h
+++ b/private.h
@@ -352,25 +352,11 @@ static time_t const time_t_max =
** INITIALIZE(x)
*/
-#ifndef GNUC_or_lint
#ifdef lint
-#define GNUC_or_lint
-#endif /* defined lint */
-#ifndef lint
-#ifdef __GNUC__
-#define GNUC_or_lint
-#endif /* defined __GNUC__ */
-#endif /* !defined lint */
-#endif /* !defined GNUC_or_lint */
-
-#ifndef INITIALIZE
-#ifdef GNUC_or_lint
-#define INITIALIZE(x) ((x) = 0)
-#endif /* defined GNUC_or_lint */
-#ifndef GNUC_or_lint
-#define INITIALIZE(x)
-#endif /* !defined GNUC_or_lint */
-#endif /* !defined INITIALIZE */
+# define INITIALIZE(x) ((x) = 0)
+#else
+# define INITIALIZE(x)
+#endif
/*
** For the benefit of GNU folk...
@@ -386,9 +372,9 @@ static time_t const time_t_max =
#endif /* !HAVE_GETTEXT */
#endif /* !defined _ */
-#ifndef TZ_DOMAIN
-#define TZ_DOMAIN "tz"
-#endif /* !defined TZ_DOMAIN */
+#if !defined TZ_DOMAIN && defined TZ_DOMAINDIR
+# define TZ_DOMAIN "tz"
+#endif
#if HAVE_INCOMPATIBLE_CTIME_R
#undef asctime_r
diff --git a/strftime.c b/strftime.c
index e9b60e1..9fbb1ec 100644
--- a/strftime.c
+++ b/strftime.c
@@ -24,12 +24,6 @@
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-#ifndef LIBC_SCCS
-#ifndef lint
-static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89";
-#endif /* !defined lint */
-#endif /* !defined LIBC_SCCS */
-
#include "tzfile.h"
#include "fcntl.h"
#include "locale.h"
diff --git a/zdump.c b/zdump.c
index 0b74c4c..f3e2a24 100644
--- a/zdump.c
+++ b/zdump.c
@@ -167,16 +167,6 @@ enum { SECSPER400YEARS_FITS = SECSPERLYEAR <= INTMAX_MAX / 400 };
#include "libintl.h"
#endif /* HAVE_GETTEXT */
-#ifndef GNUC_or_lint
-#ifdef lint
-#define GNUC_or_lint
-#else /* !defined lint */
-#ifdef __GNUC__
-#define GNUC_or_lint
-#endif /* defined __GNUC__ */
-#endif /* !defined lint */
-#endif /* !defined GNUC_or_lint */
-
#if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)
# define ATTRIBUTE_PURE __attribute__ ((__pure__))
#else
@@ -197,9 +187,9 @@ enum { SECSPER400YEARS_FITS = SECSPERLYEAR <= INTMAX_MAX / 400 };
#endif /* !HAVE_GETTEXT */
#endif /* !defined _ */
-#ifndef TZ_DOMAIN
-#define TZ_DOMAIN "tz"
-#endif /* !defined TZ_DOMAIN */
+#if !defined TZ_DOMAIN && defined TZ_DOMAINDIR
+# define TZ_DOMAIN "tz"
+#endif
extern char ** environ;
extern int getopt(int argc, char * const argv[],
--
1.9.1
More information about the tz
mailing list