path: root/lib
diff options
authorTomohiro Kusumi <>2018-10-26 09:35:45 -0700
committerJens Axboe <>2018-10-26 10:24:26 -0600
commita9d95828998ba65eff5a60df217d8d6ede6175bc (patch)
treee045cfa494e2d590d610fa2b6b62275bd12532dd /lib
parent2f84d0c71475264d6e14d782ecb38f63a22bc3a7 (diff)
lib: fix strntol's end pointer when str has leading spaces
Fix unittests/lib/strntol.c test case failure. Given behavior of strtol(3), "end" pointer should be calculated based on "beg" pointer instead of "str" on success. Otherwise if "str" has leading spaces (which are explicitly ignored by strntol()), "end" won't point to "the first invalid character" for not counting those spaces. Glibc's strtol(3) says as follows. -- If endptr is not NULL, strtol() stores the address of the first invalid character in *endptr. If there were no digits at all, strtol() stores the original value of nptr in *endptr (and returns 0). In particular, if *nptr is not '\0' but **endptr is '\0' on return, the entire string is valid. Signed-off-by: Tomohiro Kusumi <> Signed-off-by: Jens Axboe <>
Diffstat (limited to 'lib')
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/strntol.c b/lib/strntol.c
index f622c8dc..c3a55a11 100644
--- a/lib/strntol.c
+++ b/lib/strntol.c
@@ -28,6 +28,6 @@ long strntol(const char *str, size_t sz, char **end, int base)
if (ret == LONG_MIN || ret == LONG_MAX)
return ret;
if (end)
- *end = (char *)str + (*end - buf);
+ *end = (char *)beg + (*end - buf);
return ret;