summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/strtoumax.c
diff options
context:
space:
mode:
authorschwarze <>2014-09-13 20:10:12 +0000
committerschwarze <>2014-09-13 20:10:12 +0000
commit231db4657473247f753eff3dda736712538c9fd7 (patch)
treeccfd3c6e1313069066f96d0ac6a84b0d3540704b /src/lib/libc/stdlib/strtoumax.c
parentb7268ee743cd942f45105664ec1245058b7346d6 (diff)
downloadopenbsd-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/strtoumax.c')
-rw-r--r--src/lib/libc/stdlib/strtoumax.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/strtoumax.c b/src/lib/libc/stdlib/strtoumax.c
index ce6e2c00f1..c73f7e507c 100644
--- a/src/lib/libc/stdlib/strtoumax.c
+++ b/src/lib/libc/stdlib/strtoumax.c
@@ -1,6 +1,5 @@
1/* $OpenBSD: strtoumax.c,v 1.1 2006/01/13 17:58:09 millert Exp $ */ 1/* $OpenBSD: strtoumax.c,v 1.2 2014/09/13 20:10:12 schwarze Exp $ */
2 2/*
3/*-
4 * Copyright (c) 1992 The Regents of the University of California. 3 * Copyright (c) 1992 The Regents of the University of California.
5 * All rights reserved. 4 * All rights reserved.
6 * 5 *
@@ -48,8 +47,15 @@ strtoumax(const char *nptr, char **endptr, int base)
48 int neg, any, cutlim; 47 int neg, any, cutlim;
49 48
50 /* 49 /*
51 * See strtoq for comments as to the logic used. 50 * See strtoimax for comments as to the logic used.
52 */ 51 */
52 if (base < 0 || base == 1 || base > 36) {
53 if (endptr != 0)
54 *endptr = (char *)nptr;
55 errno = EINVAL;
56 return 0;
57 }
58
53 s = nptr; 59 s = nptr;
54 do { 60 do {
55 c = (unsigned char) *s++; 61 c = (unsigned char) *s++;
@@ -57,7 +63,7 @@ strtoumax(const char *nptr, char **endptr, int base)
57 if (c == '-') { 63 if (c == '-') {
58 neg = 1; 64 neg = 1;
59 c = *s++; 65 c = *s++;
60 } else { 66 } else {
61 neg = 0; 67 neg = 0;
62 if (c == '+') 68 if (c == '+')
63 c = *s++; 69 c = *s++;