Bugfix: xadd command ID parse

strictly check the string to be converted,
strtoull() in libc may not set errno to EINVAL when the string contains
invalid digits.
This commit is contained in:
dejun.xdj 2018-04-10 17:05:48 +08:00
parent 24d4daaf7b
commit 7e18b1de90

View File

@ -917,8 +917,10 @@ int string2ull(const char *s, unsigned long long *value) {
return 1;
}
errno = 0;
*value = strtoull(s,NULL,10);
if (errno == EINVAL || errno == ERANGE) return 0; /* strtoull() failed. */
char *endptr = NULL;
*value = strtoull(s,&endptr,10);
if (errno == EINVAL || errno == ERANGE || !(*s != '\0' && *endptr == '\0'))
return 0; /* strtoull() failed. */
return 1; /* Conversion done! */
}