[tz] [PROPOSED PATCH] Fix zdump problem with abbrevs like '-05'
Paul Eggert
eggert at cs.ucla.edu
Fri Jul 17 02:31:49 UTC 2015
* zdump.c (is_digit): New macro, copied from private.h.
(abbrok): Use it. Allow abbreviations that (when quoted) conform
to POSIX.1-2001 or later.
* NEWS: Document this.
---
NEWS | 3 ++-
zdump.c | 28 +++++++++++-----------------
2 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/NEWS b/NEWS
index 498e77b..101a1e5 100644
--- a/NEWS
+++ b/NEWS
@@ -21,7 +21,8 @@ Unreleased, experimental changes
Changes affecting code
- zic no longer warns about valid time zone abbreviations like '-05'.
+ zdump and zic no longer warn about valid time zone abbreviations
+ like '-05'.
Release 2015e - 2015-06-13 10:56:02 -0700
diff --git a/zdump.c b/zdump.c
index adb806c..64ff6ce 100644
--- a/zdump.c
+++ b/zdump.c
@@ -269,6 +269,9 @@ static void show(timezone_t, char *, time_t, bool);
static const char *tformat(void);
static time_t yeartot(intmax_t) ATTRIBUTE_PURE;
+/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
+#define is_digit(c) ((unsigned)(c) - '0' <= 9)
+
/* Is A an alphabetic character in the C locale? */
static bool
is_alpha(char a)
@@ -485,25 +488,16 @@ abbrok(const char *const abbrp, const char *const zone)
if (warned)
return;
cp = abbrp;
- wp = NULL;
- while (is_alpha(*cp))
+ while (is_alpha(*cp) || is_digit(*cp) || *cp == '-' || *cp == '+')
++cp;
- if (cp - abbrp == 0)
- wp = _("lacks alphabetic at start");
- else if (cp - abbrp < 3)
- wp = _("has fewer than 3 alphabetics");
+ if (cp - abbrp < 3)
+ wp = _("has fewer than 3 characters");
else if (cp - abbrp > 6)
- wp = _("has more than 6 alphabetics");
- if (wp == NULL && (*cp == '+' || *cp == '-')) {
- ++cp;
- if ('0' <= *cp && *cp <= '9')
- if (*cp++ == '1' && '0' <= *cp && *cp <= '4')
- cp++;
- if (*cp != '\0')
- wp = _("differs from POSIX standard");
- }
- if (wp == NULL)
- return;
+ wp = _("has more than 6 characters");
+ else if (*cp)
+ wp = _("has characters other than ASCII alphanumerics, '-' or '+'");
+ else
+ return;
fflush(stdout);
fprintf(stderr,
_("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"),
--
2.1.0
More information about the tz
mailing list