From 231db4657473247f753eff3dda736712538c9fd7 Mon Sep 17 00:00:00 2001 From: schwarze <> Date: Sat, 13 Sep 2014 20:10:12 +0000 Subject: 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@ --- src/lib/libc/stdlib/strtoumax.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/lib/libc/stdlib/strtoumax.c') 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 @@ -/* $OpenBSD: strtoumax.c,v 1.1 2006/01/13 17:58:09 millert Exp $ */ - -/*- +/* $OpenBSD: strtoumax.c,v 1.2 2014/09/13 20:10:12 schwarze Exp $ */ +/* * Copyright (c) 1992 The Regents of the University of California. * All rights reserved. * @@ -48,8 +47,15 @@ strtoumax(const char *nptr, char **endptr, int base) int neg, any, cutlim; /* - * See strtoq for comments as to the logic used. + * See strtoimax 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++; @@ -57,7 +63,7 @@ strtoumax(const char *nptr, char **endptr, int base) if (c == '-') { neg = 1; c = *s++; - } else { + } else { neg = 0; if (c == '+') c = *s++; -- cgit v1.2.3-55-g6feb