Skip to content

Safeguard for function to_upper()

In the command-line parsing logic, there is a construct which may not be completely safe:

strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 );
to_upper( argv_to_upper );

because strncpy() is not guaranteed to terminate the string in argv_to_upper with a 0, while to_upper() loops over the contents in argv_to_upper[] until a 0 is encountered. This could happen with a very long word as an argument.

In practice, this is not likely to cause problems as the argument parsing will likely fail in that case and the application will just exit but it is still safer to have a safeguard for it.