diff options
| author | B. Watson <urchlay@slackware.uk> | 2024-12-17 04:05:25 -0500 | 
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2024-12-17 04:05:25 -0500 | 
| commit | 1cf3a186985712d9b210b451949a0742dcb9261f (patch) | |
| tree | 78eea4770ce5460ae41f8fc5c7a9e4dffbbba892 /uxd.c | |
| parent | 50dd5dadf5b7d37ef9becc95063540d991fed591 (diff) | |
| download | uxd-1cf3a186985712d9b210b451949a0742dcb9261f.tar.gz | |
require at least 1 digit for parse_number()
Diffstat (limited to 'uxd.c')
| -rw-r--r-- | uxd.c | 15 | 
1 files changed, 11 insertions, 4 deletions
@@ -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;  | 
