Commit b91c6a1209e7da1a7f989d9ac35d0d8be0b7b710
Committed by
Bin Meng
1 parent
a5b8722532
Exists in
v2017.01-smarct4x
and in
25 other branches
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>
Showing 1 changed file with 5 additions and 3 deletions Side-by-side Diff
lib/strto.c
... | ... | @@ -160,9 +160,11 @@ |
160 | 160 | |
161 | 161 | if (!end) |
162 | 162 | end = str + strlen(str); |
163 | - for (p = end - 1; p > str; p--) { | |
164 | - if (!isdigit(*p)) | |
165 | - return simple_strtoul(p + 1, NULL, 10); | |
163 | + if (isdigit(end[-1])) { | |
164 | + for (p = end - 1; p > str; p--) { | |
165 | + if (!isdigit(*p)) | |
166 | + return simple_strtoul(p + 1, NULL, 10); | |
167 | + } | |
166 | 168 | } |
167 | 169 | |
168 | 170 | return -1; |