fix: replace unsafe fixed-size buffers with dynamic formatting helpers; add util format helpers; centralize log_on_line cleanup

This commit is contained in:
2026-04-26 22:39:55 +02:00
parent 70998643fb
commit 05dfb3725b
9 changed files with 156 additions and 45 deletions
+11 -6
View File
@@ -1,23 +1,28 @@
#include "test.h"
#include "log.h"
#include <string.h>
#include <stdlib.h>
#include "util.h"
static char s_lastLoggedError[256];
static char* s_lastLoggedError = NULL;
static void mock_log(const char* msg) {
strncpy(s_lastLoggedError, msg, sizeof(s_lastLoggedError) - 1);
s_lastLoggedError[sizeof(s_lastLoggedError) - 1] = '\0';
free(s_lastLoggedError);
s_lastLoggedError = format_string("%s", msg ? msg : "");
}
static void test_log_error(void) {
log_set_output(mock_log);
memset(s_lastLoggedError, 0, sizeof(s_lastLoggedError));
free(s_lastLoggedError);
s_lastLoggedError = NULL;
log_error("test error message");
assert_str("test error message", s_lastLoggedError, "expected 'test error message'");
log_set_output(NULL); // Reset to default
free(s_lastLoggedError);
s_lastLoggedError = NULL;
}
static void test_log_on_line(void) {