diff --git a/.clang-tidy b/.clang-tidy index ed0a13a..760391e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,25 +1,15 @@ Checks: > -*, clang-diagnostic-*, - clang-analyzer-*, - readability-*, - -readability-identifier-length, - -readability-magic-numbers, - -readability-function-cognitive-complexity, - bugprone-*, - -bugprone-easily-swappable-parameters, - misc-*, - -misc-unused-parameters, - portability-* + bugprone-macro-parentheses, + bugprone-suspicious-string-compare, + bugprone-sizeof-expression, + bugprone-signed-char-misuse, + cert-dcl37-c, + readability-misleading-indentation WarningsAsErrors: '' HeaderFilterRegex: '.*' -CheckOptions: - - key: readability-function-size.LineThreshold - value: '100' - - key: readability-function-size.StatementThreshold - value: '50' - -FormatStyle: none \ No newline at end of file +FormatStyle: none diff --git a/Makefile b/Makefile index b611062..350b23b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # Compiler and flags CC = gcc -CFLAGS = -std=c90 -pedantic -Wpedantic -Wall -Wextra +CFLAGS = -std=c90 -pedantic -Wpedantic -Wall -Wextra -Wstrict-prototypes -Wold-style-definition # Platform detection ifdef COMSPEC @@ -95,3 +95,26 @@ help: @echo " - GNU Make" .PHONY: all clean install uninstall rebuild wordlists help + +# Static analysis targets +analyze: cppcheck + +# Relaxed splint (too noisy with +standard) +splint: + @echo "Running splint with relaxed checks..." + @splint -weak +posixlib -I./include src/*.c 2>&1 | grep -v "Definition of" || true + +# Strict splint (very verbose, use with caution) +splint-strict: + splint +standard -I./include src/*.c + +cppcheck: + @echo "Running cppcheck..." + @cppcheck --std=c90 --enable=warning,style,performance,portability \ + --suppress=missingIncludeSystem --quiet -I./include src/ + +strict-compile: + gcc -std=c90 -pedantic -Wpedantic -Wall -Wextra \ + -Wstrict-prototypes -Wold-style-definition \ + -Wmissing-prototypes -Wdeclaration-after-statement \ + -Iinclude -c src/*.c diff --git a/build.sh b/build.sh index a11a5f9..e1324fa 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ mkdir -p build/cordle echo "Building application." -gcc -v -std=c90 -pedantic -Wpedantic -o build/cordle/cordle src/*.c -Iinclude -lncurses > build/cordle-build.log 2>&1 +gcc -std=c90 -pedantic -Wpedantic -Wall -Wextra -Wstrict-prototypes -Wold-style-definition export RESULT=$? if (( RESULT == 0 )); then diff --git a/game.o b/game.o new file mode 100644 index 0000000..0ab6ff6 Binary files /dev/null and b/game.o differ diff --git a/include/words.h b/include/words.h index f84dc2f..b36d995 100644 --- a/include/words.h +++ b/include/words.h @@ -5,7 +5,7 @@ #include "game.h" int load_words(GameState* game, const char* filename); -int is_valid_word(GameState* game, const char* word); +int is_valid_word(const GameState* game, const char* word); void to_upper(char* str); #endif /* WORDS_H */ diff --git a/main.o b/main.o new file mode 100644 index 0000000..5c8fed2 Binary files /dev/null and b/main.o differ diff --git a/src/main.c b/src/main.c index 0e0529c..55697b5 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ #include "../include/ui.h" /* Parse command line arguments */ -void parse_arguments(int argc, char *argv[], char *filename, char *difficulty) { +static void parse_arguments(int argc, char **argv, char *filename, char *difficulty) { int i; /* Default values */ @@ -53,7 +53,7 @@ void parse_arguments(int argc, char *argv[], char *filename, char *difficulty) { } /* Main game loop */ -int main_game_loop(int argc, char *argv[]) { +static int main_game_loop(int argc, char *argv[]) { WINDOW *stdscr; GameState game; char filename[MAX_FILENAME]; diff --git a/src/ui.c b/src/ui.c index 34e9109..4a3acf1 100644 --- a/src/ui.c +++ b/src/ui.c @@ -31,14 +31,14 @@ void draw_title(WINDOW *win, int y, const char *difficulty) { /* Draw the game board */ void draw_board(WINDOW *win, GameState *game, int y) { int width, board_x; - int row, col, x_pos, y_pos; + int row, col, x_pos; char cell[4]; width = getmaxx(win); board_x = (width - (WORD_LENGTH * 4 - 1)) / 2; for (row = 0; row < MAX_GUESSES; row++) { - y_pos = y + row * 2; + int y_pos = y + row * 2; if (row < game->guess_count) { /* Draw a completed guess */ @@ -77,7 +77,7 @@ void draw_board(WINDOW *win, GameState *game, int y) { /* Draw visual keyboard */ void draw_keyboard(WINDOW *win, GameState *game, int y) { int width; - int row_idx, x, y_pos, i; + int row_idx, i; const char *row; char letter; int status, color; @@ -85,6 +85,7 @@ void draw_keyboard(WINDOW *win, GameState *game, int y) { width = getmaxx(win); for (row_idx = 0; row_idx < 3; row_idx++) { + int x, y_pos; row = keyboard_rows[row_idx]; x = (width - strlen(row) * 2 + 1) / 2; y_pos = y + row_idx; diff --git a/src/words.c b/src/words.c index e9284e5..21df5e8 100644 --- a/src/words.c +++ b/src/words.c @@ -56,7 +56,6 @@ int load_words(GameState *game, const char *filename) { FILE *file; char line[32]; char word[WORD_LENGTH + 1]; - int len; /* Try to open the file */ file = open_wordlist(filename); @@ -67,7 +66,7 @@ int load_words(GameState *game, const char *filename) { game->word_count = 0; while (fgets(line, sizeof(line), file) && game->word_count < MAX_WORDS) { /* Remove newline and whitespace */ - len = strlen(line); + int len = strlen(line); while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r' || line[len - 1] == ' ')) { line[--len] = '\0'; } @@ -94,7 +93,7 @@ int load_words(GameState *game, const char *filename) { } /* Check if word exists in a word list */ -int is_valid_word(GameState *game, const char *word) { +int is_valid_word(const GameState *game, const char *word) { int i; char upper_word[WORD_LENGTH + 1]; diff --git a/ui.o b/ui.o new file mode 100644 index 0000000..74fc151 Binary files /dev/null and b/ui.o differ diff --git a/words.o b/words.o new file mode 100644 index 0000000..494348d Binary files /dev/null and b/words.o differ