aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-02-09 06:09:27 -0600
committerRob Landley <rob@landley.net>2012-02-09 06:09:27 -0600
commit5e6dca62869816709f4f6a16d9c191a9e93522a4 (patch)
tree7eb104ba25d0d2413819d935796fc78b18027701 /lib/lib.c
parent4cd7d19d653eaacff1da3b13eefac3938e888b3d (diff)
downloadtoybox-5e6dca62869816709f4f6a16d9c191a9e93522a4.tar.gz
Make atolx() error_exit() if fed a string that doesn't convert entirely into an integer.
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/lib.c b/lib/lib.c
index a71e20a6..887910fb 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -480,14 +480,18 @@ char *itoa(int n)
// atol() with the kilo/mega/giga/tera/peta/exa extensions.
// (zetta and yotta don't fit in 64 bits.)
-long atolx(char *c)
+long atolx(char *numstr)
{
- char *suffixes="kmgtpe", *end;
- long val = strtol(c, &c, 0);
+ char *c, *suffixes="kmgtpe", *end;
+ long val = strtol(numstr, &c, 0);
if (*c) {
end = strchr(suffixes, tolower(*c));
if (end) val *= 1024L<<((end-suffixes)*10);
+ else {
+ while (isspace(*c)) c++;
+ if (*c) error_exit("not integer: %s", numstr);
+ }
}
return val;