Skip to content

Commit

Permalink
prevents running when too much files given
Browse files Browse the repository at this point in the history
  • Loading branch information
mobius3 committed Jul 2, 2018
1 parent 68266ea commit 1a0ecaa
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/c-rez.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
#include <ctype.h>
#include <errno.h>


#define c_rez_xstr(value) c_rez_str(value)
#define c_rez_str(value) #value

#ifndef C_REZ_MAX_FILE_COUNT
#define C_REZ_MAX_FILE_COUNT 1024
#endif


#define C_REZ_MAX_ARG_COUNT (C_REZ_MAX_FILE_COUNT +1 +2 +2 +2)

/**
* help text for the program
*/
Expand Down Expand Up @@ -40,7 +51,7 @@ struct crez_opts {
const char * key;
const char * h_output;
const char * c_output;
const char * files[1024];
const char * files[C_REZ_MAX_FILE_COUNT];
unsigned file_count;
};

Expand Down Expand Up @@ -252,6 +263,13 @@ int opts_parse_or_exit(struct crez_opts * opts,
struct crez_arg state;
const char * opt;

if (argc >= C_REZ_MAX_ARG_COUNT) {
return print_help_and_exit("unexcpected file count. c-rez expects at max "
c_rez_xstr(C_REZ_MAX_FILE_COUNT)
" files"
);
}

arg_construct(&state, argc, argv);
arg_next(&state);
opts->c_output = opts->h_output = (void *)0;
Expand Down

0 comments on commit 1a0ecaa

Please sign in to comment.