fix(log): add printf format attributes and fix format mismatches

This commit is contained in:
2026-09-21 19:42:44 +02:00
parent 2021afe613
commit 391f76cd56
4 changed files with 15 additions and 6 deletions
+1 -1
View File
@@ -1967,7 +1967,7 @@ static int incremental_check(Client* client, File* file, const Config* config,
send_status(client->file_descriptor, STATUS_ERROR); send_status(client->file_descriptor, STATUS_ERROR);
return -1; return -1;
} }
log_debug_message(LOG_DEBUG_RECV, "recv: delta signature for %s (%d blocks)", log_debug_message(LOG_DEBUG_RECV, "recv: delta signature for %s (%u blocks)",
file_wire_path(file), sig->block_count); file_wire_path(file), sig->block_count);
*out_sig = sig; *out_sig = sig;
return 2; return 2;
+1 -1
View File
@@ -165,7 +165,7 @@ void print_usage(void) {
printf(" --no-delta, or --no-incremental)\n"); printf(" --no-delta, or --no-incremental)\n");
printf(" --no-fuzzy Disable --fuzzy\n"); printf(" --no-fuzzy Disable --fuzzy\n");
printf(" -B <n>, --block-size <n>, --delta-block <n>\n"); printf(" -B <n>, --block-size <n>, --delta-block <n>\n");
printf(" Delta block size in bytes (default: %d)\n", DELTA_BLOCK_SIZE_DEFAULT); printf(" Delta block size in bytes (default: %u)\n", DELTA_BLOCK_SIZE_DEFAULT);
printf(" --delta-max <n> Max file size for delta transfer (default: %llu)\n", printf(" --delta-max <n> Max file size for delta transfer (default: %llu)\n",
DELTA_MAX_FILE_SIZE); DELTA_MAX_FILE_SIZE);
printf(" -j, --threads[=N] Enable the multithreaded scanner/loader/sender\n"); printf(" -j, --threads[=N] Enable the multithreaded scanner/loader/sender\n");
+12 -3
View File
@@ -5,6 +5,15 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
/* Ask the compiler to type-check the printf-style arguments of the variadic
* logging helpers. Only enabled for GNU-compatible compilers (gcc/clang). */
#if defined(__GNUC__)
#define LOG_PRINTF_ATTR(fmt_idx, first_vararg_idx) \
__attribute__((format(printf, fmt_idx, first_vararg_idx)))
#else
#define LOG_PRINTF_ATTR(fmt_idx, first_vararg_idx)
#endif
typedef enum { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARNING, LOG_LEVEL_ERROR } LogLevel; typedef enum { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARNING, LOG_LEVEL_ERROR } LogLevel;
typedef enum { LOG_STDERR_ERRORS, LOG_STDERR_ALL } LogStderrMode; typedef enum { LOG_STDERR_ERRORS, LOG_STDERR_ALL } LogStderrMode;
@@ -59,7 +68,7 @@ typedef enum {
LOG_INFO_PROGRESS | LOG_INFO_MOUNT, LOG_INFO_PROGRESS | LOG_INFO_MOUNT,
} LogInfoFlag; } LogInfoFlag;
void log_message(LogLevel log_level, const char* message, ...); void log_message(LogLevel log_level, const char* message, ...) LOG_PRINTF_ATTR(2, 3);
void log_perror(const char* context); void log_perror(const char* context);
void set_log_level(LogLevel level); void set_log_level(LogLevel level);
void set_log_debug_flags(uint32_t flags); void set_log_debug_flags(uint32_t flags);
@@ -68,10 +77,10 @@ uint32_t get_log_debug_flags(void);
* the debug log level is enabled AND the flag is selected. Hot paths use this * the debug log level is enabled AND the flag is selected. Hot paths use this
* to skip expensive message formatting/escaping when the line is filtered. */ * to skip expensive message formatting/escaping when the line is filtered. */
bool log_debug_enabled(LogDebugFlag flag); bool log_debug_enabled(LogDebugFlag flag);
void log_debug_message(LogDebugFlag flag, const char* message, ...); void log_debug_message(LogDebugFlag flag, const char* message, ...) LOG_PRINTF_ATTR(2, 3);
void set_log_info_flags(uint32_t flags); void set_log_info_flags(uint32_t flags);
uint32_t get_log_info_flags(void); uint32_t get_log_info_flags(void);
void log_info_message(LogInfoFlag flag, const char* message, ...); void log_info_message(LogInfoFlag flag, const char* message, ...) LOG_PRINTF_ATTR(2, 3);
void log_set_file(FILE* fp); void log_set_file(FILE* fp);
void log_set_8_bit_output(bool enabled); void log_set_8_bit_output(bool enabled);
bool log_get_8_bit_output(void); bool log_get_8_bit_output(void);
+1 -1
View File
@@ -390,7 +390,7 @@ bool protocol_send_n_data(ProtocolSession* session, const void* data, size_t dat
if (session->ssl) if (session->ssl)
wait_events = POLLOUT; wait_events = POLLOUT;
} }
log_debug_message(LOG_DEBUG_IO, " Send n Data: %zu", total_bytes_send); log_debug_message(LOG_DEBUG_IO, " Send n Data: %zd", total_bytes_send);
atomic_fetch_add(&io_bytes_written, (unsigned long long)total_bytes_send); atomic_fetch_add(&io_bytes_written, (unsigned long long)total_bytes_send);
return true; return true;
} }