diff options
author | schwarze <> | 2014-09-13 20:10:12 +0000 |
---|---|---|
committer | schwarze <> | 2014-09-13 20:10:12 +0000 |
commit | 231db4657473247f753eff3dda736712538c9fd7 (patch) | |
tree | ccfd3c6e1313069066f96d0ac6a84b0d3540704b /src/lib/libc/stdlib/strtol.c | |
parent | b7268ee743cd942f45105664ec1245058b7346d6 (diff) | |
download | openbsd-231db4657473247f753eff3dda736712538c9fd7.tar.gz openbsd-231db4657473247f753eff3dda736712538c9fd7.tar.bz2 openbsd-231db4657473247f753eff3dda736712538c9fd7.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 'src/lib/libc/stdlib/strtol.c')
-rw-r--r-- | src/lib/libc/stdlib/strtol.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/lib/libc/stdlib/strtol.c b/src/lib/libc/stdlib/strtol.c index dc2cf8871c..86cec35086 100644 --- a/src/lib/libc/stdlib/strtol.c +++ b/src/lib/libc/stdlib/strtol.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* $OpenBSD: strtol.c,v 1.9 2013/04/17 17:40:35 tedu Exp $ */ | 1 | /* $OpenBSD: strtol.c,v 1.10 2014/09/13 20:10:12 schwarze Exp $ */ |
2 | /*- | 2 | /* |
3 | * Copyright (c) 1990 The Regents of the University of California. | 3 | * Copyright (c) 1990 The Regents of the University of California. |
4 | * All rights reserved. | 4 | * All rights reserved. |
5 | * | 5 | * |
@@ -33,7 +33,6 @@ | |||
33 | #include <limits.h> | 33 | #include <limits.h> |
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | 35 | ||
36 | |||
37 | /* | 36 | /* |
38 | * Convert a string to a long integer. | 37 | * Convert a string to a long integer. |
39 | * | 38 | * |
@@ -52,7 +51,7 @@ strtol(const char *nptr, char **endptr, int base) | |||
52 | * Ensure that base is between 2 and 36 inclusive, or the special | 51 | * Ensure that base is between 2 and 36 inclusive, or the special |
53 | * value of 0. | 52 | * value of 0. |
54 | */ | 53 | */ |
55 | if (base != 0 && (base < 2 || base > 36)) { | 54 | if (base < 0 || base == 1 || base > 36) { |
56 | if (endptr != 0) | 55 | if (endptr != 0) |
57 | *endptr = (char *)nptr; | 56 | *endptr = (char *)nptr; |
58 | errno = EINVAL; | 57 | errno = EINVAL; |