pruned clang-tidy, added splint and cppcheck
This commit is contained in:
parent
83b2988509
commit
f3e286e787
22
.clang-tidy
22
.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
|
||||
25
Makefile
25
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
|
||||
|
||||
2
build.sh
2
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
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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];
|
||||
|
||||
7
src/ui.c
7
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;
|
||||
|
||||
@ -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];
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user