mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-23 20:33:05 +00:00
Fix option string allocated/non allocated storage.
This commit is contained in:
parent
f53502c9ca
commit
b147602d78
3 changed files with 28 additions and 16 deletions
28
gmqcc.h
28
gmqcc.h
|
@ -1012,11 +1012,19 @@ typedef enum {
|
||||||
COMPILER_GMQCC /* this QuakeC */
|
COMPILER_GMQCC /* this QuakeC */
|
||||||
} opts_std_t;
|
} opts_std_t;
|
||||||
|
|
||||||
typedef union {
|
typedef struct {
|
||||||
bool B;
|
union {
|
||||||
uint16_t U16;
|
bool b;
|
||||||
uint32_t U32;
|
uint16_t u16;
|
||||||
char *STR;
|
uint32_t u32;
|
||||||
|
|
||||||
|
union {
|
||||||
|
char *p;
|
||||||
|
const char *c;
|
||||||
|
} str;
|
||||||
|
} data;
|
||||||
|
|
||||||
|
bool allocated;
|
||||||
} opt_value_t;
|
} opt_value_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1038,9 +1046,11 @@ extern opts_cmd_t opts;
|
||||||
#define OPTS_WARN(i) OPTS_GENERIC(opts.warn, (i))
|
#define OPTS_WARN(i) OPTS_GENERIC(opts.warn, (i))
|
||||||
#define OPTS_WERROR(i) OPTS_GENERIC(opts.werror, (i))
|
#define OPTS_WERROR(i) OPTS_GENERIC(opts.werror, (i))
|
||||||
#define OPTS_OPTIMIZATION(i) OPTS_GENERIC(opts.optimization, (i))
|
#define OPTS_OPTIMIZATION(i) OPTS_GENERIC(opts.optimization, (i))
|
||||||
#define OPTS_OPTION_BOOL(X) (opts.options[X].B)
|
#define OPTS_OPTION_DUPED(X) (opts.options[X].allocated)
|
||||||
#define OPTS_OPTION_U16(X) (opts.options[X].U16)
|
#define OPTS_OPTION_BOOL(X) (opts.options[X].data.b)
|
||||||
#define OPTS_OPTION_U32(X) (opts.options[X].U32)
|
#define OPTS_OPTION_U16(X) (opts.options[X].data.u16)
|
||||||
#define OPTS_OPTION_STR(X) (opts.options[X].STR)
|
#define OPTS_OPTION_U32(X) (opts.options[X].data.u32)
|
||||||
|
#define OPTS_OPTION_DUP(X) *(OPTS_OPTION_DUPED(X)=true, &(opts.options[X].data.str.p))
|
||||||
|
#define OPTS_OPTION_STR(X) (opts.options[X].data.str.c)
|
||||||
|
|
||||||
#endif /*! GMQCC_HDR */
|
#endif /*! GMQCC_HDR */
|
||||||
|
|
12
main.c
12
main.c
|
@ -557,7 +557,6 @@ static bool progs_nextline(char **out, size_t *alen, fs_file_t *src) {
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
size_t itr;
|
size_t itr;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
bool opts_output_free = false;
|
|
||||||
bool operators_free = false;
|
bool operators_free = false;
|
||||||
bool progs_src = false;
|
bool progs_src = false;
|
||||||
fs_file_t *outfile = NULL;
|
fs_file_t *outfile = NULL;
|
||||||
|
@ -690,8 +689,7 @@ int main(int argc, char **argv) {
|
||||||
item.type = TYPE_QC;
|
item.type = TYPE_QC;
|
||||||
vec_push(items, item);
|
vec_push(items, item);
|
||||||
} else if (!opts_output_wasset) {
|
} else if (!opts_output_wasset) {
|
||||||
OPTS_OPTION_STR(OPTION_OUTPUT) = util_strdup(line);
|
OPTS_OPTION_DUP(OPTION_OUTPUT) = util_strdup(line);
|
||||||
opts_output_free = true;
|
|
||||||
hasline = true;
|
hasline = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -780,8 +778,12 @@ cleanup:
|
||||||
|
|
||||||
if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY))
|
if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY))
|
||||||
if(parser) parser_cleanup(parser);
|
if(parser) parser_cleanup(parser);
|
||||||
if (opts_output_free)
|
|
||||||
mem_d(OPTS_OPTION_STR(OPTION_OUTPUT));
|
/* free allocated option strings */
|
||||||
|
for (itr = 0; itr < OPTION_COUNT; itr++)
|
||||||
|
if (OPTS_OPTION_DUPED(itr))
|
||||||
|
mem_d(OPTS_OPTION_STR(itr));
|
||||||
|
|
||||||
if (operators_free)
|
if (operators_free)
|
||||||
mem_d((void*)operators);
|
mem_d((void*)operators);
|
||||||
|
|
||||||
|
|
4
opts.c
4
opts.c
|
@ -60,7 +60,7 @@ opts_cmd_t opts; /* command line options */
|
||||||
static void opts_setdefault(void) {
|
static void opts_setdefault(void) {
|
||||||
memset(&opts, 0, sizeof(opts_cmd_t));
|
memset(&opts, 0, sizeof(opts_cmd_t));
|
||||||
OPTS_OPTION_BOOL(OPTION_CORRECTION) = true;
|
OPTS_OPTION_BOOL(OPTION_CORRECTION) = true;
|
||||||
OPTS_OPTION_STR(OPTION_PROGSRC) = (char*)"progs.src";
|
OPTS_OPTION_STR(OPTION_PROGSRC) = "progs.src";
|
||||||
|
|
||||||
/* warnings */
|
/* warnings */
|
||||||
opts_set(opts.warn, WARN_UNUSED_VARIABLE, true);
|
opts_set(opts.warn, WARN_UNUSED_VARIABLE, true);
|
||||||
|
@ -129,7 +129,7 @@ void opts_restore_non_Werror_all() {
|
||||||
void opts_init(const char *output, int standard, size_t arraysize) {
|
void opts_init(const char *output, int standard, size_t arraysize) {
|
||||||
opts_setdefault();
|
opts_setdefault();
|
||||||
|
|
||||||
OPTS_OPTION_STR(OPTION_OUTPUT) = (char*)output;
|
OPTS_OPTION_STR(OPTION_OUTPUT) = output;
|
||||||
OPTS_OPTION_U32(OPTION_STANDARD) = standard;
|
OPTS_OPTION_U32(OPTION_STANDARD) = standard;
|
||||||
OPTS_OPTION_U32(OPTION_MAX_ARRAY_SIZE) = arraysize;
|
OPTS_OPTION_U32(OPTION_MAX_ARRAY_SIZE) = arraysize;
|
||||||
OPTS_OPTION_U16(OPTION_MEMDUMPCOLS) = 16;
|
OPTS_OPTION_U16(OPTION_MEMDUMPCOLS) = 16;
|
||||||
|
|
Loading…
Reference in a new issue