From b5507b3127f18e10ffd15160f1bcbd84a8a1173b Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Fri, 23 Nov 2012 02:23:22 +0000 Subject: [PATCH] Make it compile with -Wall and -pedantic --- Makefile | 3 +-- con.c | 2 +- ftepp.c | 3 ++- parser.c | 10 ++++++---- util.c | 21 ++++++++++++--------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index e7a648d..a8f7a79 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,11 @@ PREFIX := /usr/local BINDIR := $(PREFIX)/bin CC ?= clang -CFLAGS += -Wall -I. +CFLAGS += -Wall -I. -Wall -pedantic #turn on tons of warnings if clang is present ifeq ($(CC), clang) CFLAGS += \ -Weverything \ - -Wno-missing-prototypes \ -Wno-padded \ -Wno-format-nonliteral \ -Wno-disabled-macro-expansion \ diff --git a/con.c b/con.c index a784ab7..2d18d69 100644 --- a/con.c +++ b/con.c @@ -281,7 +281,7 @@ int con_change(const char *out, const char *err) { con_enablecolor(); } else if (!(console.handle_err = fopen(err, "w"))) return 0; - // no buffering + /* no buffering */ setvbuf(console.handle_out, NULL, _IONBF, 0); setvbuf(console.handle_err, NULL, _IONBF, 0); diff --git a/ftepp.c b/ftepp.c index 34ca698..158daa1 100644 --- a/ftepp.c +++ b/ftepp.c @@ -134,8 +134,9 @@ static void pptoken_delete(pptoken *self) static ppmacro *ppmacro_new(lex_ctx ctx, const char *name) { - (void)ctx; ppmacro *macro = (ppmacro*)mem_a(sizeof(ppmacro)); + + (void)ctx; memset(macro, 0, sizeof(*macro)); macro->name = util_strdup(name); return macro; diff --git a/parser.c b/parser.c index 5f61e7b..d61a416 100644 --- a/parser.c +++ b/parser.c @@ -2485,10 +2485,11 @@ static ast_expression *array_setter_node(parser_t *parser, ast_value *array, ast lex_ctx ctx = ast_ctx(array); if (from+1 == afterend) { - // set this value + /* set this value */ ast_block *block; ast_return *ret; ast_array_index *subscript; + ast_store *st; int assignop = type_store_instr[value->expression.vtype]; if (value->expression.vtype == TYPE_FIELD && value->expression.next->expression.vtype == TYPE_VECTOR) @@ -2498,7 +2499,7 @@ static ast_expression *array_setter_node(parser_t *parser, ast_value *array, ast if (!subscript) return NULL; - ast_store *st = ast_store_new(ctx, assignop, (ast_expression*)subscript, (ast_expression*)value); + st = ast_store_new(ctx, assignop, (ast_expression*)subscript, (ast_expression*)value); if (!st) { ast_delete(subscript); return NULL; @@ -2543,11 +2544,12 @@ static ast_expression *array_field_setter_node( lex_ctx ctx = ast_ctx(array); if (from+1 == afterend) { - // set this value + /* set this value */ ast_block *block; ast_return *ret; ast_entfield *entfield; ast_array_index *subscript; + ast_store *st; int assignop = type_storep_instr[value->expression.vtype]; if (value->expression.vtype == TYPE_FIELD && value->expression.next->expression.vtype == TYPE_VECTOR) @@ -2566,7 +2568,7 @@ static ast_expression *array_field_setter_node( return NULL; } - ast_store *st = ast_store_new(ctx, assignop, (ast_expression*)entfield, (ast_expression*)value); + st = ast_store_new(ctx, assignop, (ast_expression*)entfield, (ast_expression*)value); if (!st) { ast_delete(entfield); return NULL; diff --git a/util.c b/util.c index a15599a..6d94742 100644 --- a/util.c +++ b/util.c @@ -498,11 +498,23 @@ size_t util_strtononcmd(const char *in, char *out, size_t outsz) { *out = *in + 'a' - 'A'; else *out = *in; + + *out = (isalpha(*in) && isupper(*in)) ? *in + 'a' - 'A' : *in; } *out = 0; return sz-1; } + +bool util_filexists(const char *file) { + FILE *fp = fopen(file, "rb"); + if (!fp) return false; + + /* it exists */ + fclose(fp); + return true; +} + FILE *util_fopen(const char *filename, const char *mode) { #ifdef WIN32 @@ -515,15 +527,6 @@ FILE *util_fopen(const char *filename, const char *mode) #endif } -bool util_filexists(const char *file) { - FILE *fp = fopen(file, "rb"); - if (!fp) return false; - - /* it exists */ - fclose(fp); - return true; -} - void _util_vec_grow(void **a, size_t i, size_t s) { size_t m = *a ? 2*_vec_beg(*a)+i : i+1; void *p = mem_r((*a ? _vec_raw(*a) : NULL), s * m + sizeof(size_t)*2); -- 2.39.2