diff mbox

[U-Boot,03/12] Fix return value in trailing_strtoln()

Message ID 1475464365-18437-4-git-send-email-sjg@chromium.org
State Accepted
Commit b91c6a1209e7da1a7f989d9ac35d0d8be0b7b710
Delegated to: Bin Meng
Headers show

Commit Message

Simon Glass Oct. 3, 2016, 3:12 a.m. UTC
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>
---

 lib/strto.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Bin Meng Oct. 5, 2016, 9:20 a.m. UTC | #1
On Mon, Oct 3, 2016 at 11:12 AM, Simon Glass <sjg@chromium.org> wrote:
> 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>
> ---
>
>  lib/strto.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff mbox

Patch

diff --git a/lib/strto.c b/lib/strto.c
index a6c0157..e93a4f5 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;