aboutsummaryrefslogtreecommitdiff
path: root/uxd.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-12-17 04:05:25 -0500
committerB. Watson <urchlay@slackware.uk>2024-12-17 04:05:25 -0500
commit1cf3a186985712d9b210b451949a0742dcb9261f (patch)
tree78eea4770ce5460ae41f8fc5c7a9e4dffbbba892 /uxd.c
parent50dd5dadf5b7d37ef9becc95063540d991fed591 (diff)
downloaduxd-1cf3a186985712d9b210b451949a0742dcb9261f.tar.gz
require at least 1 digit for parse_number()
Diffstat (limited to 'uxd.c')
-rw-r--r--uxd.c15
1 files 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;