From 1cf3a186985712d9b210b451949a0742dcb9261f Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 17 Dec 2024 04:05:25 -0500 Subject: require at least 1 digit for parse_number() --- uxd.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/uxd.c b/uxd.c index 0347917..e675348 100644 --- a/uxd.c +++ b/uxd.c @@ -199,16 +199,24 @@ void parse_colors(char *arg) { bad_color = arg[3] - '0'; } +void number_err(int opt) { + fprintf(stderr, "%s: invalid number for -%c option.\n", self, opt); + exit(1); +} + long parse_number(int opt, const char *s) { char *e; long result; result = strtol(s, &e, 0); + /* require at least one digit (otherwise -sk would be allowed) */ + if(e == s) + number_err(opt); + /* buglets here: 100x is correctly rejected, but 100kx is allowed (the x is ignored). not gonna worry about it. some people might - even make use of it: 100kb or 100Kb will work. also, a suffix - by itself, like -sk, is accepted (and treated as zero). */ + even make use of it: 100kb or 100Kb will work. */ switch(*e) { case 0: break; case 'k': result *= 1024L; break; @@ -218,8 +226,7 @@ long parse_number(int opt, const char *s) { case 'M': result *= 1000000L; break; case 'G': result *= 1000000000L; break; default: - fprintf(stderr, "%s: invalid number for -%c option.\n", self, opt); - exit(1); + number_err(opt); } return result; -- cgit v1.2.3