tools/hash: protect against invalid arg count

This commit is contained in:
Danny Robson 2016-06-17 14:58:12 +10:00
parent 850fa0470f
commit e62af110b6

View File

@ -99,17 +99,29 @@ enum {
ARG_CMD, ARG_CMD,
ARG_HASH, ARG_HASH,
ARG_INPUT, ARG_INPUT,
NUM_ARGS
}; };
//-----------------------------------------------------------------------------
void
print_usage (int argc, char **argv)
{
(void)argc;
std::cerr << argv[ARG_CMD] << " [";
for (auto name: NAMES)
std::cerr << name << "|";
std::cerr << "] <input>\n";
}
//-----------------------------------------------------------------------------
int int
main (int argc, char **argv) { main (int argc, char **argv) {
if (argc < ARG_INPUT) { if (argc != NUM_ARGS) {
std::cerr << argv[ARG_CMD] << " ["; print_usage (argc, argv);
for (auto name: NAMES)
std::cerr << name << "|";
std::cerr << "] <input>\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }