summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/strtoll.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/strtoll.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/strtoll.c')
-rw-r--r--src/lib/libc/stdlib/strtoll.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/lib/libc/stdlib/strtoll.c b/src/lib/libc/stdlib/strtoll.c
index 4bcc5565be..cf82c8e1a6 100644
--- a/src/lib/libc/stdlib/strtoll.c
+++ b/src/lib/libc/stdlib/strtoll.c
@@ -1,5 +1,5 @@
1/* $OpenBSD: strtoll.c,v 1.7 2013/03/28 18:09:38 martynas Exp $ */ 1/* $OpenBSD: strtoll.c,v 1.8 2014/09/13 20:10:12 schwarze Exp $ */
2/*- 2/*
3 * Copyright (c) 1992 The Regents of the University of California. 3 * Copyright (c) 1992 The Regents of the University of California.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
@@ -50,6 +50,17 @@ strtoll(const char *nptr, char **endptr, int base)
50 int neg, any, cutlim; 50 int neg, any, cutlim;
51 51
52 /* 52 /*
53 * Ensure that base is between 2 and 36 inclusive, or the special
54 * value of 0.
55 */
56 if (base < 0 || base == 1 || base > 36) {
57 if (endptr != 0)
58 *endptr = (char *)nptr;
59 errno = EINVAL;
60 return 0;
61 }
62
63 /*
53 * Skip white space and pick up leading +/- sign if any. 64 * Skip white space and pick up leading +/- sign if any.
54 * If base is 0, allow 0x for hex and 0 for octal, else 65 * If base is 0, allow 0x for hex and 0 for octal, else
55 * assume decimal; if base is already 16, allow 0x. 66 * assume decimal; if base is already 16, allow 0x.