summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/strtoul.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/strtoul.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/strtoul.c')
-rw-r--r--src/lib/libc/stdlib/strtoul.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lib/libc/stdlib/strtoul.c b/src/lib/libc/stdlib/strtoul.c
index a236365d2f..2aa41b76e4 100644
--- a/src/lib/libc/stdlib/strtoul.c
+++ b/src/lib/libc/stdlib/strtoul.c
@@ -1,6 +1,6 @@
1/* $OpenBSD: strtoul.c,v 1.8 2013/04/17 17:40:35 tedu Exp $ */ 1/* $OpenBSD: strtoul.c,v 1.9 2014/09/13 20:10:12 schwarze Exp $ */
2/* 2/*
3 * Copyright (c) 1990 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 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,13 @@ strtoul(const char *nptr, char **endptr, int base)
50 /* 50 /*
51 * See strtol for comments as to the logic used. 51 * See strtol for comments as to the logic used.
52 */ 52 */
53 if (base < 0 || base == 1 || base > 36) {
54 if (endptr != 0)
55 *endptr = (char *)nptr;
56 errno = EINVAL;
57 return 0;
58 }
59
53 s = nptr; 60 s = nptr;
54 do { 61 do {
55 c = (unsigned char) *s++; 62 c = (unsigned char) *s++;