Skip to content

Commit

Permalink
vis-menu: do not segfault if an option lacks an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Screwtapello authored and martanne committed May 21, 2016
1 parent 0e80bee commit 2931a5e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions vis-menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,22 @@ main(int argc, char **argv) {
else if(!strcmp(argv[i], "-b"))
barpos=-1;
/* double flags */
else if(!strcmp(argv[i], "-p"))
prompt=argv[++i];
else if(!strcmp(argv[i], "-l"))
lines = atoi(argv[++i]);
else if(!strcmp(argv[i], "-p")) {
if(argc > i+1)
prompt=argv[++i];
else {
fprintf(stderr, "Must provide a prompt\n");
exit(EXIT_FAILURE);
}
}
else if(!strcmp(argv[i], "-l")) {
if(argc > i+1)
lines = atoi(argv[++i]);
else {
fprintf(stderr, "Must provide a line count\n");
exit(EXIT_FAILURE);
}
}
else {
strncpy(text, argv[i], sizeof(text)-1);
cursor = strlen(text);
Expand Down

0 comments on commit 2931a5e

Please sign in to comment.