From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Date: Wed, 5 Oct 2016 20:42:11 -0600 Subject: [U-Boot] [PATCH v2 03/12] Fix return value in trailing_strtoln() In-Reply-To: <1475721740-15124-1-git-send-email-sjg@chromium.org> References: <1475721740-15124-1-git-send-email-sjg@chromium.org> Message-ID: <1475721740-15124-4-git-send-email-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 Reviewed-by: Bin Meng --- Changes in v2: None lib/strto.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; -- 2.8.0.rc3.226.g39d4020