Use ws_strtoi32() in get_natural_int().

Change-Id: I9a95239de8db18cff0f6c62cb526f3ef0cb29f01
Reviewed-on: https://code.wireshark.org/review/17513
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2016-09-05 19:23:36 -07:00
parent 9ef70fce3c
commit 5eb9170227
1 changed files with 14 additions and 10 deletions

View File

@ -23,7 +23,9 @@
#include "config.h"
#include <stdlib.h>
#include <errno.h>
#include <wsutil/strtoi.h>
#include <wsutil/cmdarg_err.h>
#include <wsutil/clopts_common.h>
@ -31,23 +33,25 @@
int
get_natural_int(const char *string, const char *name)
{
long number;
char *p;
gint32 number;
number = strtol(string, &p, 10);
if (p == string || *p != '\0') {
cmdarg_err("The specified %s \"%s\" isn't a decimal number", name, string);
if (!ws_strtoi32(string, &number)) {
if (errno == EINVAL) {
cmdarg_err("The specified %s \"%s\" isn't a decimal number", name, string);
exit(1);
}
if (number < 0) {
cmdarg_err("The specified %s \"%s\" is a negative number", name, string);
exit(1);
}
cmdarg_err("The specified %s \"%s\" is too large (greater than %d)",
name, string, number);
exit(1);
}
if (number < 0) {
cmdarg_err("The specified %s \"%s\" is a negative number", name, string);
exit(1);
}
if (number > INT_MAX) {
cmdarg_err("The specified %s \"%s\" is too large (greater than %d)",
name, string, INT_MAX);
exit(1);
}
return (int)number;
}