fix gratuitous undefined behavior in strptime
authorRich Felker <dalias@aerifal.cx>
Thu, 20 Oct 2016 17:22:20 +0000 (13:22 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 20 Oct 2016 17:22:20 +0000 (13:22 -0400)
accessing an object of type const char *restrict as if it had type
char * is not defined.

src/time/strptime.c

index f41f55f24cf4bcf8a100178440a15e8efdfc14ad..55c7ed1b4bc7f40d2983e4b382c946b6ec77cd0c 100644 (file)
@@ -22,8 +22,13 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
                }
                f++;
                if (*f == '+') f++;
-               if (isdigit(*f)) w=strtoul(f, (void *)&f, 10);
-               else w=-1;
+               if (isdigit(*f)) {
+                       char *new_f;
+                       w=strtoul(f, &new_f, 10);
+                       f = new_f;
+               } else {
+                       w=-1;
+               }
                adj=0;
                switch (*f++) {
                case 'a': case 'A':