diff options
| author | joerg <joerg@NetBSD.org> | 2017-07-06 21:08:44 +0000 |
|---|---|---|
| committer | joerg <joerg@NetBSD.org> | 2017-07-06 21:08:44 +0000 |
| commit | 8ed11f4fbc3980ef5b8b080bcd4d3f603f198c44 (patch) | |
| tree | fa48bdea72decbb8237d63e0682cd39016d528ac /common/lib/libc/stdlib | |
| parent | 6ca25f6f77e9dfc58aed787ee633c39f814b6b67 (diff) | |
Fix ISO C compliance: strtol of "0xX" should give the largest valid
numeric prefix, which is 0.
Diffstat (limited to 'common/lib/libc/stdlib')
| -rw-r--r-- | common/lib/libc/stdlib/_strtol.h | 10 | ||||
| -rw-r--r-- | common/lib/libc/stdlib/_strtoul.h | 10 |
2 files changed, 14 insertions, 6 deletions
diff --git a/common/lib/libc/stdlib/_strtol.h b/common/lib/libc/stdlib/_strtol.h index b4176a32122..51c71490ae5 100644 --- a/common/lib/libc/stdlib/_strtol.h +++ b/common/lib/libc/stdlib/_strtol.h @@ -1,4 +1,4 @@ -/* $NetBSD: _strtol.h,v 1.10 2015/11/13 16:02:07 christos Exp $ */ +/* $NetBSD: _strtol.h,v 1.11 2017/07/06 21:08:44 joerg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -101,13 +101,17 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr, 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; #if 0 } else if ((base == 0 || base == 2) && - c == '0' && (*s == 'b' || *s == 'B')) { + c == '0' && (*s == 'b' || *s == 'B') && + (s[1] >= '0' && s[1] <= '1')) { c = s[1]; s += 2; base = 2; diff --git a/common/lib/libc/stdlib/_strtoul.h b/common/lib/libc/stdlib/_strtoul.h index cb5c1c6a6aa..9b948fb914f 100644 --- a/common/lib/libc/stdlib/_strtoul.h +++ b/common/lib/libc/stdlib/_strtoul.h @@ -1,4 +1,4 @@ -/* $NetBSD: _strtoul.h,v 1.10 2016/11/05 21:11:30 riastradh Exp $ */ +/* $NetBSD: _strtoul.h,v 1.11 2017/07/06 21:08:44 joerg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -101,13 +101,17 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr, 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; #if 0 } else if ((base == 0 || base == 2) && - c == '0' && (*s == 'b' || *s == 'B')) { + c == '0' && (*s == 'b' || *s == 'B') && + (s[1] >= '0' && s[1] <= '1')) { c = s[1]; s += 2; base = 2; |
