aboutsummaryrefslogtreecommitdiff
path: root/uxd.c
diff options
context:
space:
mode:
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;