summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2018-09-06 10:08:44 +0300
committerJagan Teki <jagan@amarulasolutions.com>2018-09-20 17:41:01 +0300
commitb87b0d8d79e05f85e4f18200eac4283d513c3f3c (patch)
treefd7d9f081c794c300828f3eb2c479ff983e8e2dc /lib
parenta353e6aa8ec8f0aa101cc7e9543fe7843ddc6d98 (diff)
downloadu-boot-b87b0d8d79e05f85e4f18200eac4283d513c3f3c.tar.xz
lib: strto: fix metric suffix parsing in strtoul[l]
While 1kB or 1kiB will be parsed correctly, 1k will return the right amount, but the metric suffix will not be escaped once the char pointer updated. Fix this situation by simplifying the move of the endp pointer. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/strto.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/strto.c b/lib/strto.c
index b7fc31d6e5..55ff9f7437 100644
--- a/lib/strto.c
+++ b/lib/strto.c
@@ -94,12 +94,11 @@ unsigned long ustrtoul(const char *cp, char **endp, unsigned int base)
/* fall through */
case 'k':
result *= 1024;
- if ((*endp)[1] == 'i') {
- if ((*endp)[2] == 'B')
- (*endp) += 3;
- else
- (*endp) += 2;
- }
+ (*endp)++;
+ if (**endp == 'i')
+ (*endp)++;
+ if (**endp == 'B')
+ (*endp)++;
}
return result;
}
@@ -116,12 +115,11 @@ unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base)
/* fall through */
case 'k':
result *= 1024;
- if ((*endp)[1] == 'i') {
- if ((*endp)[2] == 'B')
- (*endp) += 3;
- else
- (*endp) += 2;
- }
+ (*endp)++;
+ if (**endp == 'i')
+ (*endp)++;
+ if (**endp == 'B')
+ (*endp)++;
}
return result;
}