Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src Pull up following revision(s) (requested by joerg in tick...
details: https://anonhg.NetBSD.org/src/rev/4f5d03284b69
branches: netbsd-7
changeset: 800362:4f5d03284b69
user: snj <snj%NetBSD.org@localhost>
date: Fri Nov 17 20:08:29 2017 +0000
description:
Pull up following revision(s) (requested by joerg in ticket #1448):
common/lib/libc/stdlib/_strtol.h: revision 1.11
common/lib/libc/stdlib/_strtoul.h: revision 1.11
tests/lib/libc/stdlib/t_strtol.c: revision 1.7
Fix ISO C compliance: strtol of "0xX" should give the largest valid
numeric prefix, which is 0.
diffstat:
common/lib/libc/stdlib/_strtol.h | 7 ++++-
common/lib/libc/stdlib/_strtoul.h | 7 ++++-
tests/lib/libc/stdlib/t_strtol.c | 40 +++++++++++++++++++++++++++++---------
3 files changed, 40 insertions(+), 14 deletions(-)
diffs (130 lines):
diff -r d323420beba4 -r 4f5d03284b69 common/lib/libc/stdlib/_strtol.h
--- a/common/lib/libc/stdlib/_strtol.h Sun Nov 05 21:06:42 2017 +0000
+++ b/common/lib/libc/stdlib/_strtol.h Fri Nov 17 20:08:29 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: _strtol.h,v 1.7 2013/05/17 12:55:56 joerg Exp $ */
+/* $NetBSD: _strtol.h,v 1.7.6.1 2017/11/17 20:08:29 snj Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -101,7 +101,10 @@
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;
diff -r d323420beba4 -r 4f5d03284b69 common/lib/libc/stdlib/_strtoul.h
--- a/common/lib/libc/stdlib/_strtoul.h Sun Nov 05 21:06:42 2017 +0000
+++ b/common/lib/libc/stdlib/_strtoul.h Fri Nov 17 20:08:29 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: _strtoul.h,v 1.7.6.1 2016/12/18 06:23:22 snj Exp $ */
+/* $NetBSD: _strtoul.h,v 1.7.6.2 2017/11/17 20:08:29 snj Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -101,7 +101,10 @@
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;
diff -r d323420beba4 -r 4f5d03284b69 tests/lib/libc/stdlib/t_strtol.c
--- a/tests/lib/libc/stdlib/t_strtol.c Sun Nov 05 21:06:42 2017 +0000
+++ b/tests/lib/libc/stdlib/t_strtol.c Fri Nov 17 20:08:29 2017 +0000
@@ -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.22.1 2017/11/17 20:08:29 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.22.1 2017/11/17 20:08:29 snj Exp $");
#include <atf-c.h>
#include <errno.h>
@@ -59,9 +59,10 @@
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 @@
{ "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 @@
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 @@
{ "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 },
Home |
Main Index |
Thread Index |
Old Index