fix for numeric parsing of empty string

This commit is contained in:
john30
2015-06-04 13:01:47 +02:00
parent 990a33476a
commit b8b52efde4
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ Device* Device::create(const char* name, const bool checkDevice, const bool read
if (pos != NULL) { if (pos != NULL) {
char* end = NULL; char* end = NULL;
unsigned long int port = strtoul(pos+1, &end, 10); unsigned long int port = strtoul(pos+1, &end, 10);
if (end == NULL || *end != 0 || port < 1 || port > 65535) { if (end == NULL || end == pos+1 || *end != 0 || port < 1 || port > 65535) {
return NULL; // invalid port return NULL; // invalid port
} }
struct sockaddr_in address; struct sockaddr_in address;
+1 -1
View File
@@ -102,7 +102,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state)
break; break;
case 'p': // --port=8888 case 'p': // --port=8888
port = strtoul(arg, &strEnd, 10); port = strtoul(arg, &strEnd, 10);
if (strEnd == NULL || *strEnd != 0 || port < 1 || port > 65535) { if (strEnd == NULL || strEnd == arg || *strEnd != 0 || port < 1 || port > 65535) {
argp_error(state, "invalid port"); argp_error(state, "invalid port");
return EINVAL; return EINVAL;
} }
+1 -1
View File
@@ -102,7 +102,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state)
break; break;
case 't': // --time=10000 case 't': // --time=10000
opt->time = (unsigned int)strtoul(arg, &strEnd, 10); opt->time = (unsigned int)strtoul(arg, &strEnd, 10);
if (strEnd == NULL || *strEnd != 0 || opt->time < 1000 || opt->time > 100000000) { if (strEnd == NULL || strEnd == arg || *strEnd != 0 || opt->time < 1000 || opt->time > 100000000) {
argp_error(state, "invalid time"); argp_error(state, "invalid time");
return EINVAL; return EINVAL;
} }