This is mostly to simplify the code. It also fixes a difftime gotcha that does not affect TZDB proper. * zdump.c (delta, xstrsize, xmalloc, my_snprintf): * zic.c (emalloc, estrdup): Remove function attributes, as GCC no longer generates a false positive if these attributes are absent. (In general GCC should not need to warn about static functions lacking attributes.) * private.h (ATTRIBUTE_UNSEQUENCED, ATTRIBUTE_CONST, ATTRIBUTE_MALLOC): Remove; no longer used. (difftime): ATTRIBUTE_PURE, not ATTRIBUTE_CONST, since its observable behavior can depend on floating-point environment. This change does not fix a tzcode bug, as tzcode never calls difftime. However, it could fix a bug elsewhere, if code is taken from private.h and used elsewhere. --- private.h | 19 +++---------------- zdump.c | 8 ++++---- zic.c | 4 ++-- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/private.h b/private.h index 9aec6fc2..cf2370c8 100644 --- a/private.h +++ b/private.h @@ -551,27 +551,14 @@ typedef unsigned long uintmax_t; # define ATTRIBUTE_REPRODUCIBLE /* empty */ #endif -#if HAVE___HAS_C_ATTRIBUTE -# if __has_c_attribute(unsequenced) -# define ATTRIBUTE_UNSEQUENCED [[unsequenced]] -# endif -#endif -#ifndef ATTRIBUTE_UNSEQUENCED -# define ATTRIBUTE_UNSEQUENCED /* empty */ -#endif - -/* __attribute__((const)) is stricter than [[unsequenced]] and +/* GCC attributes that are useful in tzcode. __attribute__((pure)) is stricter than [[reproducible]], - so the latter are adequate substitutes in non-GCC C23 platforms. */ + so the latter is an adequate substitute in non-GCC C23 platforms. */ #if __GNUC__ < 3 -# define ATTRIBUTE_CONST ATTRIBUTE_UNSEQUENCED # define ATTRIBUTE_FORMAT(spec) /* empty */ -# define ATTRIBUTE_MALLOC /* empty */ # define ATTRIBUTE_PURE ATTRIBUTE_REPRODUCIBLE #else -# define ATTRIBUTE_CONST __attribute__((const)) # define ATTRIBUTE_FORMAT(spec) __attribute__((format spec)) -# define ATTRIBUTE_MALLOC __attribute__((malloc)) # define ATTRIBUTE_PURE __attribute__((pure)) #endif @@ -706,7 +693,7 @@ DEPRECATED_IN_C23 char *ctime(time_t const *); char *asctime_r(struct tm const *restrict, char *restrict); char *ctime_r(time_t const *, char *); #endif -ATTRIBUTE_CONST double difftime(time_t, time_t); +ATTRIBUTE_PURE double difftime(time_t, time_t); size_t strftime(char *restrict, size_t, char const *restrict, struct tm const *restrict); # if HAVE_STRFTIME_L diff --git a/zdump.c b/zdump.c index edc4d666..86aceb45 100644 --- a/zdump.c +++ b/zdump.c @@ -89,7 +89,7 @@ static bool warned; static bool errout; static char const *abbr(struct tm const *); -ATTRIBUTE_PURE static intmax_t delta(struct tm *, struct tm *); +static intmax_t delta(struct tm *, struct tm *); static void dumptime(struct tm const *); static time_t hunt(timezone_t, time_t, time_t, bool); static void show(timezone_t, char *, time_t, bool); @@ -151,7 +151,7 @@ sumsize(ptrdiff_t a, ptrdiff_t b) /* Return the size of of the string STR, including its trailing NUL. Report an error and exit if this would exceed INDEX_MAX which means pointer subtraction wouldn't work. */ -static ptrdiff_t +ATTRIBUTE_PURE static ptrdiff_t xstrsize(char const *str) { size_t len = strlen(str); @@ -162,7 +162,7 @@ xstrsize(char const *str) /* Return a pointer to a newly allocated buffer of size SIZE, exiting on failure. SIZE should be positive. */ -ATTRIBUTE_MALLOC static void * +static void * xmalloc(ptrdiff_t size) { void *p = malloc(size); @@ -932,7 +932,7 @@ showextrema(timezone_t tz, char *zone, time_t lo, struct tm *lotmp, time_t hi) # include <stdarg.h> /* A substitute for snprintf that is good enough for zdump. */ -ATTRIBUTE_FORMAT((printf, 3, 4)) static int +static int my_snprintf(char *s, size_t size, char const *format, ...) { int n; diff --git a/zic.c b/zic.c index 36739cb0..19a0b953 100644 --- a/zic.c +++ b/zic.c @@ -523,7 +523,7 @@ memcheck(void *ptr) return ptr; } -ATTRIBUTE_MALLOC static void * +static void * emalloc(size_t size) { return memcheck(malloc(size)); @@ -535,7 +535,7 @@ erealloc(void *ptr, size_t size) return memcheck(realloc(ptr, size)); } -ATTRIBUTE_MALLOC static char * +static char * estrdup(char const *str) { return memcheck(strdup(str)); -- 2.43.0