fix: Improve type safety by adding const qualifiers to function parameters in logging and enhance read loop handling in HTTP2

This commit is contained in:
2025-12-20 22:11:01 +01:00
parent fcac920bc9
commit f433ae55e4
3 changed files with 9 additions and 9 deletions

View File

@@ -46,7 +46,7 @@ static ssize_t file_read_callback(nghttp2_session* session, int32_t stream_id,
int fd = source->fd; int fd = source->fd;
ssize_t nread; ssize_t nread;
while ((nread = read(fd, buf, length)) == -1 && errno == EINTR); while ((nread = read(fd, buf, length)) == -1 && errno == EINTR) {}
if (nread == -1) if (nread == -1)
{ {

View File

@@ -53,7 +53,7 @@ static PerfTracker g_perf_trackers[MAX_PERF_TRACKERS];
static pthread_mutex_t g_perf_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t g_perf_mutex = PTHREAD_MUTEX_INITIALIZER;
// Get color for log level // Get color for log level
static const char* get_level_color(LogLevel level) static const char* get_level_color(const LogLevel level)
{ {
switch (level) switch (level)
{ {
@@ -207,7 +207,7 @@ static void ensure_log_directory(void)
} }
} }
void log_init(LogConfig* config) void log_init(const LogConfig* config)
{ {
pthread_mutex_lock(&g_log_mutex); pthread_mutex_lock(&g_log_mutex);
@@ -233,21 +233,21 @@ void log_cleanup(void)
pthread_mutex_unlock(&g_log_mutex); pthread_mutex_unlock(&g_log_mutex);
} }
void log_set_level(LogLevel level) void log_set_level(const LogLevel level)
{ {
pthread_mutex_lock(&g_log_mutex); pthread_mutex_lock(&g_log_mutex);
g_log_config.level = level; g_log_config.level = level;
pthread_mutex_unlock(&g_log_mutex); pthread_mutex_unlock(&g_log_mutex);
} }
void log_set_categories(LogCategory categories) void log_set_categories(const LogCategory categories)
{ {
pthread_mutex_lock(&g_log_mutex); pthread_mutex_lock(&g_log_mutex);
g_log_config.categories = categories; g_log_config.categories = categories;
pthread_mutex_unlock(&g_log_mutex); pthread_mutex_unlock(&g_log_mutex);
} }
void log_write(LogLevel level, LogCategory category, const char* file, void log_write(const LogLevel level, const LogCategory category, const char* file,
int line, const char* func, const char* fmt, ...) int line, const char* func, const char* fmt, ...)
{ {
// Quick check without lock // Quick check without lock
@@ -376,7 +376,7 @@ void log_event(const char* message)
} }
// Secure logging - sanitizes potentially sensitive data // Secure logging - sanitizes potentially sensitive data
void log_secure(LogLevel level, LogCategory category, const char* fmt, ...) void log_secure(const LogLevel level, const LogCategory category, const char* fmt, ...)
{ {
char message[4096]; char message[4096];
va_list args; va_list args;
@@ -460,7 +460,7 @@ void log_perf_end(const char* operation)
if (g_perf_trackers[i].active && if (g_perf_trackers[i].active &&
strcmp(g_perf_trackers[i].operation, operation) == 0) strcmp(g_perf_trackers[i].operation, operation) == 0)
{ {
long elapsed_us = (end_time.tv_sec - g_perf_trackers[i].start_time.tv_sec) * 1000000 + const long elapsed_us = (end_time.tv_sec - g_perf_trackers[i].start_time.tv_sec) * 1000000 +
(end_time.tv_usec - g_perf_trackers[i].start_time.tv_usec); (end_time.tv_usec - g_perf_trackers[i].start_time.tv_usec);
g_perf_trackers[i].active = false; g_perf_trackers[i].active = false;

View File

@@ -55,7 +55,7 @@ typedef struct
} LogConfig; } LogConfig;
// Initialize the logging system // Initialize the logging system
void log_init(LogConfig* config); void log_init(const LogConfig* config);
// Cleanup logging system // Cleanup logging system
void log_cleanup(void); void log_cleanup(void);