diff options
author | Petr Machata <pmachata@redhat.com> | 2012-05-03 18:40:20 +0200 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2012-05-03 18:40:20 +0200 |
commit | 5bddfccaa50aa9de2f58cbe8fa754ded3c7ad2eb (patch) | |
tree | 1e791b7ce6ccb4c0ed49bca278bc023ea2893cef /options.c | |
parent | 61686c26634ea847c41470801572b49bebce5b99 (diff) | |
download | ltrace-5bddfccaa50aa9de2f58cbe8fa754ded3c7ad2eb.tar.gz |
Better checking for -n argument
Diffstat (limited to 'options.c')
-rw-r--r-- | options.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -494,9 +494,19 @@ process_options(int argc, char **argv) case 'L': libcalls = 0; break; - case 'n': - options.indent = atoi(optarg); + case 'n': { + char *endptr; + long int l = strtol(optarg, &endptr, 0); + /* Arbitrary cut-off. Nobody needs to indent + * more than, say, 8, anyway. */ + if (l < 0 || l > 20 || *optarg == 0 || *endptr != 0) { + fprintf(stderr, "Invalid argument to -n: '%s'." + " Use integer 0..20.\n", optarg); + exit(1); + } + options.indent = (int)l; break; + } case 'o': options.output = fopen(optarg, "w"); if (!options.output) { |