summaryrefslogtreecommitdiff
path: root/lib/strto.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2016-10-05 20:42:11 -0600
committerBin Meng <bmeng.cn@gmail.com>2016-10-11 11:55:33 +0800
commitb91c6a1209e7da1a7f989d9ac35d0d8be0b7b710 (patch)
treed54528122107568533816e0e8629fd753a2bec24 /lib/strto.c
parenta5b8722532729c62370b6abb278420804d5d071b (diff)
Fix return value in trailing_strtoln()
This function should return -1 if there is no trailing integer in the string. Instead it returns 0. Fix it by checking for this condition at the start. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'lib/strto.c')
-rw-r--r--lib/strto.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/strto.c b/lib/strto.c
index a6c01574da..e93a4f5491 100644
--- a/lib/strto.c
+++ b/lib/strto.c
@@ -160,9 +160,11 @@ long trailing_strtoln(const char *str, const char *end)
if (!end)
end = str + strlen(str);
- for (p = end - 1; p > str; p--) {
- if (!isdigit(*p))
- return simple_strtoul(p + 1, NULL, 10);
+ if (isdigit(end[-1])) {
+ for (p = end - 1; p > str; p--) {
+ if (!isdigit(*p))
+ return simple_strtoul(p + 1, NULL, 10);
+ }
}
return -1;