Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(win): compile cleanly with MinGW GCC

Oxygen5652e46f3fc4a5
diff --git a/src/daemon/ipc.c b/src/daemon/ipc.c
index 349a7d553..7193d69ad 100644
--- a/src/daemon/ipc.c
+++ b/src/daemon/ipc.c
@@ -3554,13 +3554,13 @@ static void *win_token_user_query(win_security_t *security, HANDLE token, PSID *
return buffer;
}
-#define RESOLVE_ADVAPI_MEMBER(context, member, type, symbol) \
- do { \
- (context)->member = (type)GetProcAddress((context)->advapi, (symbol)); \
- if (!(context)->member) { \
- win_security_destroy((context)); \
- return false; \
- } \
+#define RESOLVE_ADVAPI_MEMBER(context, member, type, symbol) \
+ do { \
+ (context)->member = (type)(void (*)(void))GetProcAddress((context)->advapi, (symbol)); \
+ if (!(context)->member) { \
+ win_security_destroy((context)); \
+ return false; \
+ } \
} while (0)
static bool win_security_init(win_security_t *security) {
@@ -4619,7 +4619,8 @@ static bool win_generation_nonce(uint8_t nonce[CBM_DAEMON_IPC_WINDOWS_NONCE_SIZE
enum { WIN_BCRYPT_USE_SYSTEM_PREFERRED_RNG = 0x00000002 };
HMODULE bcrypt = LoadLibraryW(L"bcrypt.dll");
bcrypt_gen_random_fn generate =
- bcrypt ? (bcrypt_gen_random_fn)GetProcAddress(bcrypt, "BCryptGenRandom") : NULL;
+ bcrypt ? (bcrypt_gen_random_fn)(void (*)(void))GetProcAddress(bcrypt, "BCryptGenRandom")
+ : NULL;
LONG status = generate ? generate(NULL, nonce, CBM_DAEMON_IPC_WINDOWS_NONCE_SIZE,
WIN_BCRYPT_USE_SYSTEM_PREFERRED_RNG)
: (LONG)-1;
@@ -5174,8 +5175,8 @@ static bool win_pipe_client_is_current_user(HANDLE pipe) {
* has completed a read, which accept must not require. */
HMODULE kernel = GetModuleHandleW(L"kernel32.dll");
get_named_pipe_server_process_id_fn get_client_pid =
- kernel ? (get_named_pipe_server_process_id_fn)GetProcAddress(kernel,
- "GetNamedPipeClientProcessId")
+ kernel ? (get_named_pipe_server_process_id_fn)(void (*)(void))GetProcAddress(
+ kernel, "GetNamedPipeClientProcessId")
: NULL;
if (!get_client_pid) {
cbm_log_warn("daemon.accept.client_identity", "step", "pid_fn_missing");
@@ -5319,8 +5320,8 @@ int cbm_daemon_ipc_accept(cbm_daemon_ipc_listener_t *listener, uint32_t timeout_
static bool win_pipe_server_is_current_user(HANDLE pipe) {
HMODULE kernel = GetModuleHandleW(L"kernel32.dll");
get_named_pipe_server_process_id_fn get_server_pid =
- kernel ? (get_named_pipe_server_process_id_fn)GetProcAddress(kernel,
- "GetNamedPipeServerProcessId")
+ kernel ? (get_named_pipe_server_process_id_fn)(void (*)(void))GetProcAddress(
+ kernel, "GetNamedPipeServerProcessId")
: NULL;
ULONG process_id = 0;
if (!get_server_pid) {
@@ -5612,7 +5613,7 @@ uint64_t cbm_daemon_ipc_connection_peer_pid(const cbm_daemon_ipc_connection_t *c
ULONG process_id = 0;
if (connection->role == CBM_DAEMON_IPC_PIPE_ROLE_ACCEPTED_SERVER) {
get_named_pipe_client_process_id_fn get_client_pid =
- kernel ? (get_named_pipe_client_process_id_fn)GetProcAddress(
+ kernel ? (get_named_pipe_client_process_id_fn)(void (*)(void))GetProcAddress(
kernel, "GetNamedPipeClientProcessId")
: NULL;
if (!get_client_pid || !get_client_pid(connection->handle, &process_id)) {
@@ -5620,7 +5621,7 @@ uint64_t cbm_daemon_ipc_connection_peer_pid(const cbm_daemon_ipc_connection_t *c
}
} else if (connection->role == CBM_DAEMON_IPC_PIPE_ROLE_CONNECTED_CLIENT) {
get_named_pipe_server_process_id_fn get_server_pid =
- kernel ? (get_named_pipe_server_process_id_fn)GetProcAddress(
+ kernel ? (get_named_pipe_server_process_id_fn)(void (*)(void))GetProcAddress(
kernel, "GetNamedPipeServerProcessId")
: NULL;
if (!get_server_pid || !get_server_pid(connection->handle, &process_id)) {
diff --git a/src/foundation/compat_fs.c b/src/foundation/compat_fs.c
index 09392097d..fded41a7a 100644
--- a/src/foundation/compat_fs.c
+++ b/src/foundation/compat_fs.c
@@ -883,7 +883,9 @@ int cbm_canonical_path(const char *path, char *out, size_t out_sz) {
}
DWORD needed =
GetFinalPathNameByHandleW(handle, NULL, 0, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
- if (needed == 0 || needed == MAXDWORD || (size_t)needed > SIZE_MAX / sizeof(wchar_t) - 1) {
+ /* MAXDWORD keeps the +1 below safe; calloc rejects an unrepresentable
+ * capacity * sizeof(wchar_t) allocation on narrower size_t targets. */
+ if (needed == 0 || needed == MAXDWORD) {
(void)CloseHandle(handle);
return 0;
}
diff --git a/src/foundation/private_file_lock.c b/src/foundation/private_file_lock.c
index 64f026c1c..80df0d17c 100644
--- a/src/foundation/private_file_lock.c
+++ b/src/foundation/private_file_lock.c
@@ -735,13 +735,13 @@ static void *private_win_token_user_query(private_win_security_t *security, HAND
return buffer;
}
-#define PRIVATE_RESOLVE_ADVAPI(context, member, type, symbol) \
- do { \
- (context)->member = (type)GetProcAddress((context)->advapi, (symbol)); \
- if (!(context)->member) { \
- private_win_security_destroy((context)); \
- return false; \
- } \
+#define PRIVATE_RESOLVE_ADVAPI(context, member, type, symbol) \
+ do { \
+ (context)->member = (type)(void (*)(void))GetProcAddress((context)->advapi, (symbol)); \
+ if (!(context)->member) { \
+ private_win_security_destroy((context)); \
+ return false; \
+ } \
} while (0)
static bool private_win_security_init(private_win_security_t *security) {
diff --git a/tests/test_daemon_ipc.c b/tests/test_daemon_ipc.c
index b9cd6b95f..3ab2203e9 100644
--- a/tests/test_daemon_ipc.c
+++ b/tests/test_daemon_ipc.c
@@ -847,10 +847,12 @@ TEST(daemon_ipc_windows_legacy_bridge_covers_handoff_and_lifetime) {
typedef BOOL(WINAPI * ipc_test_set_dacl_fn)(PSECURITY_DESCRIPTOR, BOOL, PACL, BOOL);
HMODULE advapi = LoadLibraryW(L"advapi32.dll");
ipc_test_initialize_sd_fn initialize_sd =
- advapi ? (ipc_test_initialize_sd_fn)GetProcAddress(advapi, "InitializeSecurityDescriptor")
+ advapi ? (ipc_test_initialize_sd_fn)(void (*)(void))GetProcAddress(
+ advapi, "InitializeSecurityDescriptor")
: NULL;
- ipc_test_set_dacl_fn set_dacl =
- advapi ? (ipc_test_set_dacl_fn)GetProcAddress(advapi, "SetSecurityDescriptorDacl") : NULL;
+ ipc_test_set_dacl_fn set_dacl = advapi ? (ipc_test_set_dacl_fn)(void (*)(void))GetProcAddress(
+ advapi, "SetSecurityDescriptorDacl")
+ : NULL;
SECURITY_DESCRIPTOR unsafe_descriptor;
bool unsafe_descriptor_ok = initialize_sd && set_dacl &&
initialize_sd(&unsafe_descriptor, SECURITY_DESCRIPTOR_REVISION) &&