Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-6]: src Pull up following revision(s) (requested by joerg in tick...



details:   https://anonhg.NetBSD.org/src/rev/168f8f9ad266
branches:  netbsd-6
changeset: 777238:168f8f9ad266
user:      snj <snj%NetBSD.org@localhost>
date:      Sat Aug 26 16:36:19 2017 +0000

description:
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.

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 1a31d62b1007 -r 168f8f9ad266 common/lib/libc/stdlib/_strtol.h
--- a/common/lib/libc/stdlib/_strtol.h  Sat Aug 26 16:26:46 2017 +0000
+++ b/common/lib/libc/stdlib/_strtol.h  Sat Aug 26 16:36:19 2017 +0000
@@ -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 @@
                        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 1a31d62b1007 -r 168f8f9ad266 common/lib/libc/stdlib/_strtoul.h
--- a/common/lib/libc/stdlib/_strtoul.h Sat Aug 26 16:26:46 2017 +0000
+++ b/common/lib/libc/stdlib/_strtoul.h Sat Aug 26 16:36:19 2017 +0000
@@ -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 @@
                        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 1a31d62b1007 -r 168f8f9ad266 tests/lib/libc/stdlib/t_strtol.c
--- a/tests/lib/libc/stdlib/t_strtol.c  Sat Aug 26 16:26:46 2017 +0000
+++ b/tests/lib/libc/stdlib/t_strtol.c  Sat Aug 26 16:36:19 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.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 @@
                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