From c1dcaff9417ba8697d9686185002ab03fee83fe5 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 5 Sep 2016 17:33:20 -0700 Subject: [PATCH] Use get_positive_int() to parse signed positive arguments. Clean up indentation while we're at it. Change-Id: Ie7223f96c758bd71d2435203635db9c2b28e2249 Reviewed-on: https://code.wireshark.org/review/17508 Reviewed-by: Guy Harris --- randpkt.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/randpkt.c b/randpkt.c index 4346afb52c..58ff3b1aaa 100644 --- a/randpkt.c +++ b/randpkt.c @@ -27,6 +27,8 @@ #include #include +#include +#include #include #include #include @@ -47,7 +49,6 @@ #include "randpkt_core/randpkt_core.h" -#ifdef HAVE_PLUGINS /* * General errors are reported with an console message in randpkt. */ @@ -58,7 +59,16 @@ failure_message(const char *msg_format, va_list ap) vfprintf(stderr, msg_format, ap); fprintf(stderr, "\n"); } -#endif + +/* + * Report additional information for an error in command-line arguments. + */ +static void +failure_message_cont(const char *msg_format, va_list ap) +{ + vfprintf(stderr, msg_format, ap); + fprintf(stderr, "\n"); +} /* Print usage statement and exit program */ static void @@ -118,11 +128,13 @@ main(int argc, char **argv) char *init_progfile_dir_error; #endif - /* - * Get credential information for later use. - */ - init_process_policies(); - init_open_routines(); + /* + * Get credential information for later use. + */ + init_process_policies(); + init_open_routines(); + + cmdarg_err_init(failure_message, failure_message_cont); #ifdef _WIN32 arg_list_utf_16to8(argc, argv); @@ -157,15 +169,14 @@ main(int argc, char **argv) while ((opt = getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) { switch (opt) { case 'b': /* max bytes */ - produce_max_bytes = atoi(optarg); + produce_max_bytes = get_positive_int(optarg, "max bytes"); if (produce_max_bytes > 65536) { - fprintf(stderr, "randpkt: Max bytes is 65536\n"); - return 1; + cmdarg_err("max bytes is > 65536"); } break; case 'c': /* count */ - produce_count = atoi(optarg); + produce_count = get_positive_int(optarg, "count"); break; case 't': /* type of packet to produce */