diff --git a/src/main.c b/src/main.c index 382e565ce2..94b4d856f1 100644 --- a/src/main.c +++ b/src/main.c @@ -432,12 +432,16 @@ int main(int argc, char* argv[]) { fprintf(stderr, "%s: --indent takes one parameter\n", progname); die(); } - dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7)); - int indent = atoi(argv[i+1]); - if (indent < -1 || indent > 7) { + char* end = NULL; + errno = 0; + long indent = strtol(argv[i+1], &end, 10); + while (*end && isspace((unsigned char)*end)) + end++; + if (errno || indent < -1 || indent > 7 || *end) { fprintf(stderr, "%s: --indent takes a number between -1 and 7\n", progname); die(); } + dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7)); dumpopts |= JV_PRINT_INDENT_FLAGS(indent); i++; } else if (isoption(&text, 0, "seq", is_short)) {