From 0b947b701f1e3d4a21eb21aaf52f279e24c975b4 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 26 Apr 2016 10:22:34 -0400 Subject: [PATCH] Improve int argument parsing --- csim.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/csim.c b/csim.c index 4ca764e..12308f3 100644 --- a/csim.c +++ b/csim.c @@ -17,11 +17,14 @@ void print_usage() int parse_int_arg(char* arg) { - int i = atoi(arg); - if (i != 0) - return i; - else - exit(-1); + char* end; + int i = strtol(arg, &end, 0); + if (!i || *end != '\0') + { + printf("Invalid argument \"%s\"\n", arg); + print_usage(); + } + return i; } int main(int argc, char* argv[])