diff options
author | 2014-09-13 20:10:12 +0000 | |
---|---|---|
committer | 2014-09-13 20:10:12 +0000 | |
commit | b252b5f6e1f8ed74b8fe0b3449eb72f4b9ca5f57 (patch) | |
tree | 5ae51484372ab07338f3115e93c87b33cf125245 /lib/libc/stdlib/strtoull.c | |
parent | Don't say or imply that using ifconfig has anything to do with whether the (diff) | |
download | wireguard-openbsd-b252b5f6e1f8ed74b8fe0b3449eb72f4b9ca5f57.tar.xz wireguard-openbsd-b252b5f6e1f8ed74b8fe0b3449eb72f4b9ca5f57.zip |
Make sure that the following functions return 0 and EINVAL as
required by the C standard when called with an invalid base:
strtoll(), strtoimax(), strtoul(), strtoull(), and strtoumax().
Same behaviour for strtoq() and strtouq() even though not standardized.
No functional change in strtol(), it was the only one already correct.
While here, simplify the conditional expression for checking the base
and sync whitespace and comments among the six files.
ok millert@
Diffstat (limited to 'lib/libc/stdlib/strtoull.c')
-rw-r--r-- | lib/libc/stdlib/strtoull.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/libc/stdlib/strtoull.c b/lib/libc/stdlib/strtoull.c index 28f613a0875..846417630f9 100644 --- a/lib/libc/stdlib/strtoull.c +++ b/lib/libc/stdlib/strtoull.c @@ -1,5 +1,5 @@ -/* $OpenBSD: strtoull.c,v 1.6 2013/03/28 18:09:38 martynas Exp $ */ -/*- +/* $OpenBSD: strtoull.c,v 1.7 2014/09/13 20:10:12 schwarze Exp $ */ +/* * Copyright (c) 1992 The Regents of the University of California. * All rights reserved. * @@ -50,8 +50,15 @@ strtoull(const char *nptr, char **endptr, int base) int neg, any, cutlim; /* - * See strtoq for comments as to the logic used. + * See strtoll for comments as to the logic used. */ + if (base < 0 || base == 1 || base > 36) { + if (endptr != 0) + *endptr = (char *)nptr; + errno = EINVAL; + return 0; + } + s = nptr; do { c = (unsigned char) *s++; @@ -59,7 +66,7 @@ strtoull(const char *nptr, char **endptr, int base) if (c == '-') { neg = 1; c = *s++; - } else { + } else { neg = 0; if (c == '+') c = *s++; |