Skip to content

Commit 9be8568

Browse files
authored
Fix mingw-w64 GCC toolchain compatibility issues (#1054)
* Address -Wincompatible-pointer-types warnings * Define __USE_MINGW_ANSI_STDIO=1 * Fix format string compatibility issues
1 parent 6d8de05 commit 9be8568

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ if (ENABLE_WINDOWS_STATIC_RUNTIME)
1919
set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
2020
endif ()
2121

22+
if (MINGW)
23+
# MSVCRT-based mingw-w64 GCC requires this macro to enable C99 format specifiers. This does not apply to UCRT-based
24+
# mingw-w64 GCC, but apply the workaround anyways until bson-compat.h no longer requires this.
25+
add_compile_definitions ("__USE_MINGW_ANSI_STDIO=1")
26+
endif ()
27+
2228
list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
2329

2430
include (GNUInstallDirs)

kms-message/src/kms_message_private.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ struct _kms_response_parser_t {
124124
} \
125125
} while (0)
126126

127-
#ifdef __GNUC__
128-
__attribute__((format(__printf__, 3, 4)))
127+
#if defined(__clang__)
128+
__attribute__((format(printf, 3, 4)))
129+
#elif defined(__GNUC__)
130+
__attribute__((format(gnu_printf, 3, 4)))
129131
#endif
130132
void
131133
kms_set_error (char *error, size_t size, const char *fmt, ...);

kms-message/src/kms_request_str.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ KMS_MSG_EXPORT (void)
6565
kms_request_str_append_lowercase (kms_request_str_t *str,
6666
kms_request_str_t *appended);
6767

68-
#ifdef __GNUC__
69-
__attribute__((format(__printf__, 2, 3)))
68+
#if defined(__clang__)
69+
__attribute__((format(printf, 2, 3)))
70+
#elif defined(__GNUC__)
71+
__attribute__((format(gnu_printf, 2, 3)))
7072
#endif
7173
KMS_MSG_EXPORT (void)
7274
kms_request_str_appendf (kms_request_str_t *str, const char *format, ...);
7375

74-
#ifdef __GNUC__
75-
__attribute__((format(__printf__, 2, 3)))
76+
#if defined(__clang__)
77+
__attribute__((format(printf, 2, 3)))
78+
#elif defined(__GNUC__)
79+
__attribute__((format(gnu_printf, 2, 3)))
7680
#endif
7781
KMS_MSG_EXPORT (void)
7882
kms_request_strdupf (kms_request_str_t *str, const char *format, ...);

src/crypto/cng.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ bool _native_crypto_aes_256_cbc_encrypt(aes_256_args_t args) {
221221

222222
NTSTATUS nt_status;
223223

224+
ULONG bytes_written = args.bytes_written ? *args.bytes_written : 0u;
224225
nt_status = BCryptEncrypt(state->key_handle,
225226
(PUCHAR)(args.in->data),
226227
args.in->len,
@@ -229,8 +230,9 @@ bool _native_crypto_aes_256_cbc_encrypt(aes_256_args_t args) {
229230
state->iv_len,
230231
args.out->data,
231232
args.out->len,
232-
args.bytes_written,
233+
&bytes_written,
233234
0);
235+
args.bytes_written ? (*args.bytes_written = bytes_written) : (void)0;
234236

235237
if (nt_status != STATUS_SUCCESS) {
236238
CLIENT_ERR("error initializing cipher: 0x%x", (int)nt_status);
@@ -255,6 +257,7 @@ bool _native_crypto_aes_256_cbc_decrypt(aes_256_args_t args) {
255257

256258
NTSTATUS nt_status;
257259

260+
ULONG bytes_written = args.bytes_written ? *args.bytes_written : 0u;
258261
nt_status = BCryptDecrypt(state->key_handle,
259262
(PUCHAR)(args.in->data),
260263
args.in->len,
@@ -263,8 +266,9 @@ bool _native_crypto_aes_256_cbc_decrypt(aes_256_args_t args) {
263266
state->iv_len,
264267
args.out->data,
265268
args.out->len,
266-
args.bytes_written,
269+
&bytes_written,
267270
0);
271+
args.bytes_written ? (*args.bytes_written = bytes_written) : (void)0;
268272

269273
if (nt_status != STATUS_SUCCESS) {
270274
CLIENT_ERR("error initializing cipher: 0x%x", (int)nt_status);
@@ -360,7 +364,7 @@ typedef struct {
360364
static bool _cng_ctr_crypto_generate(cng_ctr_encrypt_state *state, mongocrypt_status_t *status) {
361365
BSON_ASSERT(state);
362366

363-
uint32_t bytesEncrypted = 0;
367+
ULONG bytesEncrypted = 0;
364368
NTSTATUS nt_status = BCryptEncrypt(state->key_handle,
365369
state->input_block,
366370
state->input_block_len,

0 commit comments

Comments
 (0)