Let's put some more safety to parse_arguments().
This commit is contained in:
parent
328cbc3b0c
commit
f24c7aafc1
7
main.c
7
main.c
@ -39,9 +39,12 @@ int parse_arguments(const int argc, const char *const *const argv,
|
|||||||
|
|
||||||
for (int i = 1, pos = 0; i < argc; ++i)
|
for (int i = 1, pos = 0; i < argc; ++i)
|
||||||
if (argv[i][0] == '-') {
|
if (argv[i][0] == '-') {
|
||||||
if (argv[i][1] == 'h' || argv[i][2] == 'h')
|
size_t l = strlen(argv[i]);
|
||||||
|
if (l < 2)
|
||||||
|
return 99;
|
||||||
|
if (argv[i][1] == 'h' || (argv[i][1] == '-' && l > 2 && argv[i][2] == 'h'))
|
||||||
return 1;
|
return 1;
|
||||||
else if (argv[i][1] == 'v' || argv[i][2] == 'v')
|
else if (argv[i][1] == 'v' || (argv[i][1] == '-' && l > 2 && argv[i][2] == 'v'))
|
||||||
return 2;
|
return 2;
|
||||||
else
|
else
|
||||||
return 99;
|
return 99;
|
||||||
|
Loading…
Reference in New Issue
Block a user