Module Name:    src
Committed By:   snj
Date:           Sat Aug 26 16:36:19 UTC 2017

Modified Files:
        src/common/lib/libc/stdlib [netbsd-6]: _strtol.h _strtoul.h
        src/tests/lib/libc/stdlib [netbsd-6]: t_strtol.c

Log Message:
Pull up following revision(s) (requested by joerg in ticket #1460):
        common/lib/libc/stdlib/_strtol.h: 1.11 via patch
        common/lib/libc/stdlib/_strtoul.h: 1.11 via patch
        tests/lib/libc/stdlib/t_strtol.c: 1.6-1.7
Fix testing of returned entptr, and fix three affected tests.
>From kamil@ via PR lib/49632
--
Fix ISO C compliance: strtol of "0xX" should give the largest valid
numeric prefix, which is 0.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.8.1 src/common/lib/libc/stdlib/_strtol.h
cvs rdiff -u -r1.1.22.1 -r1.1.22.2 src/common/lib/libc/stdlib/_strtoul.h
cvs rdiff -u -r1.5 -r1.5.6.1 src/tests/lib/libc/stdlib/t_strtol.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/stdlib/_strtol.h
diff -u src/common/lib/libc/stdlib/_strtol.h:1.2 src/common/lib/libc/stdlib/_strtol.h:1.2.8.1
--- src/common/lib/libc/stdlib/_strtol.h:1.2	Wed May 20 22:03:29 2009
+++ src/common/lib/libc/stdlib/_strtol.h	Sat Aug 26 16:36:19 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: _strtol.h,v 1.2 2009/05/20 22:03:29 christos Exp $ */
+/* $NetBSD: _strtol.h,v 1.2.8.1 2017/08/26 16:36:19 snj Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -84,7 +84,10 @@ _FUNCNAME(const char *nptr, char **endpt
 			c = *s++;
 	}
 	if ((base == 0 || base == 16) &&
-	    c == '0' && (*s == 'x' || *s == 'X')) {
+	    c == '0' && (*s == 'x' || *s == 'X') &&
+	    ((s[1] >= '0' && s[1] <= '9') ||
+	     (s[1] >= 'a' && s[1] <= 'f') ||
+	     (s[1] >= 'A' && s[1] <= 'F'))) {
 		c = s[1];
 		s += 2;
 		base = 16;

Index: src/common/lib/libc/stdlib/_strtoul.h
diff -u src/common/lib/libc/stdlib/_strtoul.h:1.1.22.1 src/common/lib/libc/stdlib/_strtoul.h:1.1.22.2
--- src/common/lib/libc/stdlib/_strtoul.h:1.1.22.1	Tue Jul 11 21:09:29 2017
+++ src/common/lib/libc/stdlib/_strtoul.h	Sat Aug 26 16:36:19 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: _strtoul.h,v 1.1.22.1 2017/07/11 21:09:29 snj Exp $ */
+/* $NetBSD: _strtoul.h,v 1.1.22.2 2017/08/26 16:36:19 snj Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -83,7 +83,10 @@ _FUNCNAME(const char *nptr, char **endpt
 			c = *s++;
 	}
 	if ((base == 0 || base == 16) &&
-	    c == '0' && (*s == 'x' || *s == 'X')) {
+	    c == '0' && (*s == 'x' || *s == 'X') &&
+	    ((s[1] >= '0' && s[1] <= '9') ||
+	     (s[1] >= 'a' && s[1] <= 'f') ||
+	     (s[1] >= 'A' && s[1] <= 'F'))) {
 		c = s[1];
 		s += 2;
 		base = 16;

Index: src/tests/lib/libc/stdlib/t_strtol.c
diff -u src/tests/lib/libc/stdlib/t_strtol.c:1.5 src/tests/lib/libc/stdlib/t_strtol.c:1.5.6.1
--- src/tests/lib/libc/stdlib/t_strtol.c:1.5	Tue Jun 14 02:45:58 2011
+++ src/tests/lib/libc/stdlib/t_strtol.c	Sat Aug 26 16:36:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp $ */
+/*	$NetBSD: t_strtol.c,v 1.5.6.1 2017/08/26 16:36:19 snj Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp $");
+__RCSID("$NetBSD: t_strtol.c,v 1.5.6.1 2017/08/26 16:36:19 snj Exp $");
 
 #include <atf-c.h>
 #include <errno.h>
@@ -59,9 +59,10 @@ check(struct test *t, long int li, long 
 		atf_tc_fail_nonfatal("strtoll(%s, NULL, %d) failed "
 		    "(rv = %lld)", t->str, t->base, lli);
 
-	if (t->end != NULL && strcmp(t->end, end) != 0)
-		atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
-		    "strtol(%s, &end, %d)", end, t->str, t->base);
+	if ((t->end != NULL && strcmp(t->end, end) != 0) ||
+	    (t->end == NULL && *end != '\0'))
+		atf_tc_fail_nonfatal("invalid end pointer (%p) from "
+		    "strtol(%p, &end, %d)", end, t->str, t->base);
 }
 
 ATF_TC(strtol_base);
@@ -89,15 +90,21 @@ ATF_TC_BODY(strtol_base, tc)
 		{ "12579781",			 123456789, 14, NULL	},
 		{ "AC89BC9",			 123456789, 15, NULL	},
 		{ "75BCD15",			 123456789, 16, NULL	},
-		{ "123456789",			    342391,  8, NULL	},
-		{ "0123456789",			    342391,  0, NULL	},
+		{ "1234567",			    342391,  8, NULL	},
+		{ "01234567",			    342391,  0, NULL	},
 		{ "0123456789",			 123456789, 10, NULL	},
-		{ "0x75bcd15",		         123456789,  0, NULL	},
+		{ "0x75bcd15",			 123456789,  0, NULL	},
+		{ " 0xX",			         0,  0, "xX"	},
+		{ " 0xX",			         0, 16, "xX"	},
+		{ " 0XX",			         0,  0, "XX"	},
+		{ " 0XX",			         0, 16, "XX"	},
 	};
 
 	long long int lli;
 	long int li;
-	char *end;
+	long long int ulli;
+	long int uli;
+	char *end, *end2;
 	size_t i;
 
 	for (i = 0; i < __arraycount(t); i++) {
@@ -105,7 +112,20 @@ ATF_TC_BODY(strtol_base, tc)
 		li = strtol(t[i].str, &end, t[i].base);
 		lli = strtoll(t[i].str, NULL, t[i].base);
 
+		uli = strtoul(t[i].str, &end2, t[i].base);
+		ulli = strtoull(t[i].str, NULL, t[i].base);
+
 		check(&t[i], li, lli, end);
+
+		if (li != uli)
+			atf_tc_fail_nonfatal("strtoul(%s, NULL, %d) failed "
+			    "(rv = %lu)", t[i].str, t[i].base, uli);
+		if (end != end2)
+			atf_tc_fail_nonfatal("invalid end pointer ('%p') from "
+			    "strtoul(%s, &end, %d)", end2, t[i].str, t[i].base);
+		if (lli != ulli)
+			atf_tc_fail_nonfatal("strtoull(%s, NULL, %d) failed "
+			    "(rv = %llu)", t[i].str, t[i].base, ulli);
 	}
 }
 
@@ -121,7 +141,7 @@ ATF_TC_BODY(strtol_case, tc)
 		{ "abcd",	0xabcd, 16, NULL	},
 		{ "     dcba",	0xdcba, 16, NULL	},
 		{ "abcd dcba",	0xabcd, 16, " dcba"	},
-		{ "abc0x123",	0xabc0, 16, NULL	},
+		{ "abc0x123",	0xabc0, 16, "x123"	},
 		{ "abcd\0x123",	0xabcd, 16, "\0x123"	},
 		{ "ABCD",	0xabcd, 16, NULL	},
 		{ "aBcD",	0xabcd, 16, NULL	},

Reply via email to