diff options
author | Ian C <ianc@noddybox.co.uk> | 2004-08-22 23:05:59 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2004-08-22 23:05:59 +0000 |
commit | bce0956117d53d2a242c4bc4fe354bb5e78e0e5f (patch) | |
tree | f7fe81da192025cd96e805a22eaf48d1f7bd8159 /int2tap.c | |
parent | 6cee147b6b1f583a03844978c706a9a75749eef5 (diff) |
Improved number format error handling
Diffstat (limited to 'int2tap.c')
-rw-r--r-- | int2tap.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -54,10 +54,28 @@ static void Usage(void) { fprintf(stderr,"%s: usage %s [-b] [-s] [-a addr] [-c addr] " "output-file input-file ... \n",progname,progname); + exit(EXIT_FAILURE); } +static unsigned ToUnsigned(const char *p) +{ + char *end; + unsigned u; + + u=(unsigned)strtoul(p,&end,0); + + if (end==p || *end!=0) + { + fprintf(stderr,"%s: invalid number %s\n",progname,p); + exit(EXIT_FAILURE); + } + + return u; +} + + /* ---------------------------------------- MAIN */ int main(int argc, char *argv[]) @@ -108,6 +126,10 @@ int main(int argc, char *argv[]) { switch(argv[f][1]) { + case 'h': + Usage(); + break; + case 'b': bin_only=TRUE; break; @@ -123,7 +145,7 @@ int main(int argc, char *argv[]) } addr_defined=TRUE; - exec_addr=(unsigned)strtoul(argv[++f],NULL,0); + exec_addr=ToUnsigned(argv[++f]); break; @@ -134,7 +156,7 @@ int main(int argc, char *argv[]) } clear_defined=TRUE; - clear_addr=(unsigned)strtoul(argv[++f],NULL,0); + clear_addr=ToUnsigned(argv[++f]); break; |