]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/parse-date: don't use xalloc in lib-like code
authorKarel Zak <kzak@redhat.com>
Fri, 12 May 2017 09:15:34 +0000 (11:15 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 12 May 2017 09:17:02 +0000 (11:17 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/parse-date.y

index 66ec722ce4a6d9a10a6eda3fef55ac663961f215..75c8bb04b8218e9b711c4f8bc9b233ab2a7db30a 100644 (file)
@@ -80,7 +80,6 @@
 #include <stdarg.h>
 #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';