From 22cfe66265df6fabd7dd1c4036b1e500d0ed859f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 12 May 2017 11:15:34 +0200 Subject: [PATCH] lib/parse-date: don't use xalloc in lib-like code Signed-off-by: Karel Zak --- lib/parse-date.y | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/parse-date.y b/lib/parse-date.y index 66ec722ce4..75c8bb04b8 100644 --- a/lib/parse-date.y +++ b/lib/parse-date.y @@ -80,7 +80,6 @@ #include #include "cctype.h" #include "nls.h" -#include "xalloc.h" /** * Bison's skeleton tests _STDLIB_H, while some stdlib.h headers @@ -1263,7 +1262,7 @@ static char * get_tz(char tzbuf[TZBUFSIZE]) size_t tzsize = strlen (tz) + 1; tz = (tzsize <= TZBUFSIZE ? memcpy (tzbuf, tz, tzsize) - : xstrdup (tz)); + : strdup (tz)); } return tz; } @@ -1324,8 +1323,18 @@ int parse_date(struct timespec *result, char const *p, char tz1buf[TZBUFSIZE]; int large_tz = TZBUFSIZE < tzsize; int setenv_ok; + tz0 = get_tz (tz0buf); - z = tz1 = large_tz ? malloc (tzsize) : tz1buf; + if (!tz0) + goto fail; + + if (large_tz) { + z = tz1 = malloc (tzsize); + if (!tz1) + goto fail; + } else + z = tz1 = tz1buf; + for (s = tzbase; *s != '"'; s++) *z++ = *(s += *s == '\\'); *z = '\0'; -- 2.47.2