aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-09-05 19:23:36 -0700
committerGuy Harris <guy@alum.mit.edu>2016-09-06 02:24:24 +0000
commit5eb9170227a590560003dfc3b654e7be1b942b9a (patch)
tree1578dc39ed7307a913ecf36328e8cbc28e117910
parent9ef70fce3c13d37527466ee67a47fa9bfd65f9fa (diff)
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>
-rw-r--r--wsutil/clopts_common.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/wsutil/clopts_common.c b/wsutil/clopts_common.c
index 7adc0ac7f5..695559eb02 100644
--- a/wsutil/clopts_common.c
+++ b/wsutil/clopts_common.c
@@ -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;
}