diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2023-03-12 12:45:35 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2023-03-12 12:45:35 -0700 |
commit | 750270e29f3c1c8e28ce70ee7dfd0aed581abbf7 (patch) | |
tree | e4e8d92f6f805cd8b2319dad8e7fa5c5de6bcad9 | |
parent | 5fd1128e5066bea8880ab90d0054347e70ebba33 (diff) | |
download | tz-750270e29f3c1c8e28ce70ee7dfd0aed581abbf7.tar.gz |
One limit, not two, on tz abbr in localtime.c
* localtime.c (TZ_ABBR_MAX_LEN): Remove.
All uses replaced by MY_TZNAME_MAX, so that there’s
just one limit.
(scrub_abbrs): Compare to GRANDPARENTED only if the length is
plausible. In the usual case where MY_TZNAME_MAX is 255 and
GRANDPARENTED's length is less, the compiler can optimize
away the memcmp entirely.
-rw-r--r-- | localtime.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/localtime.c b/localtime.c index 3135ea3..1de6b55 100644 --- a/localtime.c +++ b/localtime.c @@ -28,10 +28,6 @@ static int lock(void) { return 0; } static void unlock(void) { } #endif -#ifndef TZ_ABBR_MAX_LEN -# define TZ_ABBR_MAX_LEN 16 -#endif /* !defined TZ_ABBR_MAX_LEN */ - #ifndef TZ_ABBR_CHAR_SET # define TZ_ABBR_CHAR_SET \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :+-._" @@ -361,10 +357,12 @@ scrub_abbrs(struct state *sp) for (i = 0; i < sp->typecnt; ++i) { register const struct ttinfo * const ttisp = &sp->ttis[i]; char *cp = &sp->chars[ttisp->tt_desigidx]; + size_t cplen = strlen(cp); + static char const gp[sizeof GRANDPARENTED - 1] = GRANDPARENTED; - if (strlen(cp) > TZ_ABBR_MAX_LEN && - strcmp(cp, GRANDPARENTED) != 0) - *(cp + TZ_ABBR_MAX_LEN) = '\0'; + if (MY_TZNAME_MAX < cplen + && ! (cplen == sizeof gp && memcmp(cp, gp, sizeof gp) == 0)) + *(cp + MY_TZNAME_MAX) = '\0'; } } |