mbpfan-josie

Make cppcheck conf added, test mallocs guarded

ded1bf7c0dca1d73563fb6de44eed51377a64719
cjosie <administrator@josie-c.com> · 2026-11-16T15:56 · browse files at this commit

parents: c8cb0d5

diff --git a/Makefile b/Makefile
index 9f829e5..f2a14dd 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ OBJS := $(patsubst %.$(C),%.$(OBJ),$(wildcard $(SOURCE_PATH)*.$(C)))
 TESTS_OBJS := $(patsubst %.$(C),%.$(OBJ),$(wildcard $(TESTS_PATH)*.$(C)))
 TESTS_OBJS += $(filter-out %main.$(OBJ),$(OBJS))
 
-.PHONY: all clean tests uninstall install rebuild
+.PHONY: all clean tests uninstall install rebuild cppcheck clang-tidy
 
 %.$(OBJ):%.$(C)
 	mkdir -p bin
@@ -54,6 +54,9 @@ tests: all
 clang-tidy:
 	clang-tidy src/*.[ch]
 
+cppcheck:
+	cppcheck --std=c99 --enable=warning,performance,portability --inline-suppr --quiet src/ tests/
+
 uninstall:
 	rm /usr/sbin/mbpfan
 	rm /etc/mbpfan.conf
diff --git a/tests/minunit.c b/tests/minunit.c
index 5a54299..f1c7c76 100644
--- a/tests/minunit.c
+++ b/tests/minunit.c
@@ -153,6 +153,7 @@ static const char *test_config_file()
 static const char *test_settings()
 {
     t_fans* fan = (t_fans *) malloc( sizeof( t_fans ) );
+    if (fan == NULL) return "test_settings: fan malloc failed";
     fan->fan_id = 1;
     fan->fan_max_speed = -1; 
     fan->next = NULL;
@@ -168,6 +169,7 @@ static const char *test_settings()
     mu_assert("polling_interval is not 7", polling_interval == 7);
     
     t_fans* fan2 = (t_fans *)malloc(sizeof(t_fans));
+    if (fan2 == NULL) return "test_settings: fan2 malloc failed";
     fan2->fan_id = 2;
     fan2->fan_max_speed = -1;
     fan2->next = NULL;
@@ -189,6 +191,7 @@ int received = 0;
 static void handler(int signal)
 {
     t_fans* fan = (t_fans *) malloc( sizeof( t_fans ) );
+    if (fan == NULL) return;
     fan->fan_id = 1;
     fan->next = NULL;
 
@@ -218,6 +221,7 @@ static const char *test_sighup_receive()
 static const char *test_settings_reload()
 {
     t_fans* fan = (t_fans *) malloc( sizeof( t_fans ) );
+    if (fan == NULL) return "test_settings_reload: fan malloc failed";
     fan->fan_id = 1;
     fan->fan_min_speed = -1;
     fan->fan_manual_path = NULL;