Let's put some more safety to parse_arguments().

This commit is contained in:
Alexander Andreev 2024-04-26 04:29:26 +04:00
parent 328cbc3b0c
commit f24c7aafc1
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34

7
main.c
View File

@ -39,9 +39,12 @@ int parse_arguments(const int argc, const char *const *const argv,
for (int i = 1, pos = 0; i < argc; ++i)
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;
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;
else
return 99;