From d844c2a3913e1c7d331b080a4a09631e515d9364 Mon Sep 17 00:00:00 2001 From: Bob Little Date: Sat, 17 Jun 2017 20:43:19 -0400 Subject: [PATCH] Added 'linty' target for make "make linty" does lots of error checking while compiling. Simplified the standard make's CFLAGS. Cleaned up code to eliminate resulting warnings generated by "make linty". --- Makefile | 7 ++++--- advent.h | 2 +- dungeon.c | 6 +++--- main.c | 4 ++-- misc.c | 2 +- newdungeon.py | 18 +++++++++--------- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index b0b06b9..62a4ee4 100644 --- a/Makefile +++ b/Makefile @@ -25,9 +25,7 @@ VERS=1.0 CC?=gcc -CCFLAGS+=-std=c99 -D _DEFAULT_SOURCE -Wall -Wpedantic -Wextra -g -CCFLAGS+=-Wstrict-prototypes -CCFLAGS+=-Wmissing-prototypes +CCFLAGS+=-std=c99 -D _DEFAULT_SOURCE -Wpedantic LIBS= UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Linux) @@ -118,5 +116,8 @@ refresh: advent.html dist: advent-$(VERS).tar.gz +linty: CCFLAGS += -W -Wall -Wextra -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wfloat-equal -Wcast-align -Wwrite-strings -Waggregate-return -Wcast-qual -Wswitch-enum -Wwrite-strings -Wunreachable-code -Winit-self -Wpointer-arith -O2 +linty: advent + debug: CCFLAGS += -O0 --coverage -g debug: advent diff --git a/advent.h b/advent.h index 1cc8784..c5abaa6 100644 --- a/advent.h +++ b/advent.h @@ -84,7 +84,7 @@ extern bool oldstyle, editline, prompt; #define WRITE_MODE "wb" extern char* xstrdup(const char*); extern void packed_to_token(long, char token[]); -extern void newspeak(char*); +extern void newspeak(const char*); extern void PSPEAK(vocab_t,int); extern void RSPEAK(vocab_t); extern void SETPRM(long,long,long); diff --git a/dungeon.c b/dungeon.c index dfc5b1c..5b94d95 100644 --- a/dungeon.c +++ b/dungeon.c @@ -487,12 +487,12 @@ static int read_database(FILE* database) { * whether the abbreviated description is printed. Counts modulo 5 * unless "LOOK" is used. */ -static void write_0d(FILE* header_file, long single, char* varname) +static void write_0d(FILE* header_file, long single, const char* varname) { fprintf(header_file, "LOCATION long %s INITIALIZE(= %ld);\n", varname, single); } -static void write_1d(FILE* header_file, long array[], long dim, char* varname) +static void write_1d(FILE* header_file, long array[], long dim, const char* varname) { fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname); for (int i = 0; i < dim; ++i) @@ -508,7 +508,7 @@ static void write_1d(FILE* header_file, long array[], long dim, char* varname) fprintf(header_file, "\n});\n"); } -static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, long dim2, char* varname) +static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, long dim2, const char* varname) { fprintf(header_file, "LOCATION long %s[][%ld] INITIALIZE(= {\n", varname, dim2); for (int i = 0; i < dim1; ++i) diff --git a/main.c b/main.c index 3d23c96..526eda1 100644 --- a/main.c +++ b/main.c @@ -913,7 +913,7 @@ static void listobjects(void) static bool do_command(FILE *cmdin) /* Get and execute a command */ { - long verb, V1, V2; + long verb=0, V1, V2; long kmod, defn; static long igo = 0; static long obj = 0; @@ -950,7 +950,7 @@ static bool do_command(FILE *cmdin) for (;;) { if (game.loc == 0) croak(cmdin); - char* msg = locations[game.loc].description.small; + const char* msg = locations[game.loc].description.small; if (MOD(game.abbrev[game.loc],game.abbnum) == 0 || msg == 0) msg=locations[game.loc].description.big; if (!FORCED(game.loc) && DARK(game.loc)) { diff --git a/misc.c b/misc.c index cf75e64..978e4b6 100644 --- a/misc.c +++ b/misc.c @@ -45,7 +45,7 @@ void packed_to_token(long packed, char token[6]) /* I/O routines (SPEAK, PSPEAK, RSPEAK, SETPRM, GETIN, YES) */ -void newspeak(char* msg) +void newspeak(const char* msg) { // Do nothing if we got a null pointer. if (msg == NULL) diff --git a/newdungeon.py b/newdungeon.py index a4b046e..2bd2a5a 100755 --- a/newdungeon.py +++ b/newdungeon.py @@ -28,7 +28,7 @@ def write_regular_messages(name, h, c): h += " {},\n".format(key) h += "};\n\n" - c += "char* {}[] = {{\n".format(name) + c += "const char* {}[] = {{\n".format(name) index = 0 for key, text in dungeon[name]: if text == None: @@ -47,13 +47,13 @@ with open(yaml_name, "r") as f: h = """#include typedef struct { - char* inventory; - char** longs; + const char* inventory; + const char** longs; } object_description_t; typedef struct { - char* small; - char* big; + const char* small; + const char* big; } descriptions_t; typedef struct { @@ -62,9 +62,9 @@ typedef struct { extern location_t locations[]; extern object_description_t object_descriptions[]; -extern char* arbitrary_messages[]; -extern char* class_messages[]; -extern char* turn_threshold_messages[]; +extern const char* arbitrary_messages[]; +extern const char* class_messages[]; +extern const char* turn_threshold_messages[]; extern size_t CLSSES; @@ -118,7 +118,7 @@ for key, data in dungeon["object_descriptions"]: c += " .inventory = {},\n".format(data["inventory"]) try: data["longs"][0] - c += " .longs = (char* []) {\n" + c += " .longs = (const char* []) {\n" for l in data["longs"]: l = c_escape(l) c += " \"{}\",\n".format(l) -- 2.31.1