From fd8eef3e78a40de035bb4fab3629dda73bdd7b59 Mon Sep 17 00:00:00 2001 From: Ezra Chung <88335979+eramongodb@users.noreply.github.com> Date: Fri, 28 Feb 2025 13:59:17 -0600 Subject: [PATCH] MONGOCRYPT-783 address miscellaneous warnings (#975) * Silence -Wold-style-cast for C++ compatibility code * Address -Wmissing-prototype and -Wmissing-variable-declarations warnings * Address -Wundef warnings * Address -Wvla warnings * Address -Wunreachable-code-break warnings * Address -Wassign-enum warnings * Address -Wunused-macros warnings --- kms-message/src/hexlify.c | 5 ++ kms-message/src/kms_request.c | 2 +- kms-message/src/kms_request_str.c | 10 +-- kms-message/src/kms_response_parser.c | 1 - kms-message/src/sort.c | 5 +- kms-message/src/sort.h | 2 + kms-message/test/test_kmip_reader_writer.c | 9 ++- kms-message/test/test_kms_kmip_request.c | 4 ++ kms-message/test/test_kms_kmip_response.c | 3 + .../test/test_kms_kmip_response_parser.c | 4 ++ kms-message/test/test_kms_request.c | 72 +++++++++---------- src/crypto/libcrypto.c | 2 + src/mc-dec128.h | 4 +- src/mc-dec128.test.cpp | 2 +- src/mc-fle2-payload-iev-v2.c | 4 +- src/mc-fle2-payload-iev.c | 2 +- src/mc-fle2-rfds.c | 7 +- src/mc-optional-private.h | 2 +- src/mc-range-edge-generation-private.h | 2 +- src/mc-range-edge-generation.c | 2 +- src/mc-range-encoding-private.h | 2 +- src/mc-range-encoding.c | 8 +-- src/mc-range-mincover-generator.template.h | 2 +- src/mc-range-mincover-private.h | 2 +- src/mc-range-mincover.c | 4 +- src/mc-rangeopts.c | 22 +++--- src/mc-str-encode-string-sets.c | 4 +- src/mc-tokens.c | 2 +- src/mlib/int128.h | 11 +++ src/mlib/int128.test.cpp | 5 ++ src/mlib/path.h | 2 +- src/mlib/path.test.c | 5 +- src/mlib/str.h | 11 +++ src/mlib/str.test.c | 2 +- src/mlib/thread.h | 2 +- src/mongocrypt-cache-collinfo.c | 4 ++ src/mongocrypt-crypto-private.h | 8 +-- src/mongocrypt-crypto.c | 4 +- src/mongocrypt-dll-private.h | 4 +- src/mongocrypt-key-broker.c | 18 ++--- src/mongocrypt-marking.c | 4 +- src/mongocrypt.c | 4 +- src/os_posix/os_dll.c | 2 + src/os_win/os_dll.c | 2 + test/crypt_shared-stub.cpp | 14 ---- test/example-state-machine.c | 7 +- test/test-dll.cpp | 16 +++-- test/test-mc-range-edge-generation.c | 4 +- test/test-mc-range-encoding.c | 4 +- test/test-mc-range-mincover.c | 14 ++-- test/test-mc-rangeopts.c | 2 +- test/test-mc-text-search-str-encode.c | 34 ++++----- test/test-mongocrypt-assert-match-bson.c | 7 +- test/test-mongocrypt-buffer.c | 2 +- test/test-mongocrypt-cache.c | 2 +- test/test-mongocrypt-ciphertext.c | 4 +- test/test-mongocrypt-crypto-hooks.c | 36 +++++----- test/test-mongocrypt-crypto-std-hooks.c | 4 ++ test/test-mongocrypt-crypto.c | 2 +- test/test-mongocrypt-ctx-decrypt.c | 2 +- test/test-mongocrypt-ctx-encrypt.c | 10 +-- test/test-mongocrypt-endpoint.c | 2 +- test/test-mongocrypt-kek.c | 2 +- test/test-mongocrypt-key-cache.c | 8 +-- test/test-mongocrypt-log.c | 4 +- test/test-unicode-fold.c | 8 ++- test/util/csfle.c | 2 +- test/util/util.c | 8 +-- 68 files changed, 259 insertions(+), 217 deletions(-) diff --git a/kms-message/src/hexlify.c b/kms-message/src/hexlify.c index 2d7092714..2ef7d1bf2 100644 --- a/kms-message/src/hexlify.c +++ b/kms-message/src/hexlify.c @@ -14,7 +14,12 @@ * limitations under the License. */ +#include "hexlify.h" + +// + #include "kms_message_private.h" + #include #include #include diff --git a/kms-message/src/kms_request.c b/kms-message/src/kms_request.c index b95c451b0..a00ff9036 100644 --- a/kms-message/src/kms_request.c +++ b/kms-message/src/kms_request.c @@ -744,7 +744,7 @@ kms_request_get_signature (kms_request_t *request) return kms_request_str_detach (sig); } -void +static void kms_request_validate (kms_request_t *request) { if (!check_and_prohibit_kmip (request)) { diff --git a/kms-message/src/kms_request_str.c b/kms-message/src/kms_request_str.c index 57b2e4f9d..f830f9595 100644 --- a/kms-message/src/kms_request_str.c +++ b/kms-message/src/kms_request_str.c @@ -27,8 +27,8 @@ #include #include /* CHAR_BIT */ -bool rfc_3986_tab[256] = {0}; -bool kms_initialized = false; +static bool rfc_3986_tab[256] = {0}; +static bool kms_initialized = false; static void tables_init (void) @@ -126,12 +126,6 @@ kms_request_str_detach (kms_request_str_t *str) return r; } -const char * -kms_request_str_get (kms_request_str_t *str) -{ - return str->str; -} - bool kms_request_str_reserve (kms_request_str_t *str, size_t size) { diff --git a/kms-message/src/kms_response_parser.c b/kms-message/src/kms_response_parser.c index 67336d702..0f51f1a28 100644 --- a/kms-message/src/kms_response_parser.c +++ b/kms-message/src/kms_response_parser.c @@ -81,7 +81,6 @@ kms_response_parser_wants_bytes (kms_response_parser_t *parser, int32_t max) default: KMS_ASSERT (false && "Invalid kms_response_parser HTTP state"); } - return -1; } static bool diff --git a/kms-message/src/sort.c b/kms-message/src/sort.c index 91aa3f359..3545d6d0a 100644 --- a/kms-message/src/sort.c +++ b/kms-message/src/sort.c @@ -37,6 +37,10 @@ * https://github.com/freebsd/freebsd/blob/e7c6cef9514d3bb1f14a30a5ee871231523e43db/lib/libc/stdlib/merge.c */ +#include "sort.h" + +// + #include /* @@ -44,7 +48,6 @@ * last 4 elements. */ -typedef int (*cmp_t) (const void *, const void *); #define CMP(x, y) cmp (x, y) #define swap(a, b) \ { \ diff --git a/kms-message/src/sort.h b/kms-message/src/sort.h index 42c1b21c7..31558bfae 100644 --- a/kms-message/src/sort.h +++ b/kms-message/src/sort.h @@ -15,6 +15,8 @@ * limitations under the License. */ +#include + typedef int (*cmp_t) (const void *, const void *); void diff --git a/kms-message/test/test_kmip_reader_writer.c b/kms-message/test/test_kmip_reader_writer.c index 1e266bba7..fa164a3b9 100644 --- a/kms-message/test/test_kmip_reader_writer.c +++ b/kms-message/test/test_kmip_reader_writer.c @@ -6,7 +6,7 @@ * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 - * + * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -54,6 +54,7 @@ kms_kmip_writer_test_evaluate (kmip_writer_t *writer, free (expected_hex); } +void kms_kmip_writer_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_writer_test (void) { @@ -140,6 +141,7 @@ kms_kmip_writer_test (void) kmip_writer_destroy (writer); } +void kms_kmip_reader_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_reader_test (void) { @@ -312,6 +314,7 @@ kms_kmip_reader_test (void) free (data); } +void kms_kmip_reader_negative_int_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_reader_negative_int_test (void) { @@ -356,6 +359,7 @@ kms_kmip_reader_negative_int_test (void) free (data); } +void kms_kmip_reader_find_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_reader_find_test (void) { @@ -404,6 +408,7 @@ kms_kmip_reader_find_test (void) free (data); } +void kms_kmip_reader_find_and_recurse_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_reader_find_and_recurse_test (void) { @@ -438,6 +443,7 @@ kms_kmip_reader_find_and_recurse_test (void) free (data); } +void kms_kmip_reader_find_and_read_enum_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_reader_find_and_read_enum_test (void) { @@ -470,6 +476,7 @@ kms_kmip_reader_find_and_read_enum_test (void) free (data); } +void kms_kmip_reader_find_and_read_bytes_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_reader_find_and_read_bytes_test (void) { diff --git a/kms-message/test/test_kms_kmip_request.c b/kms-message/test/test_kms_kmip_request.c index 05b1fdbe3..198c94082 100644 --- a/kms-message/test/test_kms_kmip_request.c +++ b/kms-message/test/test_kms_kmip_request.c @@ -76,6 +76,7 @@ value="ffa8cc79e8c3763b0121fcd06bb3488c8bf42c0774604640279b16b264194030eeb083962 0x36, 0xa9, 0x06, 0x6b, 0x4e, 0x10, 0xae, 0xb5, 0x6a, 0x5c, 0xcf, 0x6a, \ 0xa4, 0x69, 0x01, 0xe6, 0x25, 0xe3, 0x40, 0x0c, 0x78, 0x11, 0xd2, 0xec +void kms_kmip_request_register_secretdata_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_request_register_secretdata_test (void) { @@ -98,6 +99,7 @@ kms_kmip_request_register_secretdata_test (void) kms_request_destroy (req); } +void kms_kmip_request_register_secretdata_invalid_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_request_register_secretdata_invalid_test (void) { @@ -144,6 +146,7 @@ value="7FJYvnV6XkaUCWuY96bCSc6AuhvkPpqI"/> 0x58, 0x6b, 0x61, 0x55, 0x43, 0x57, 0x75, 0x59, 0x39, 0x36, 0x62, 0x43, \ 0x53, 0x63, 0x36, 0x41, 0x75, 0x68, 0x76, 0x6b, 0x50, 0x70, 0x71, 0x49 +void kms_kmip_request_get_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_request_get_test (void) { @@ -200,6 +203,7 @@ value="7FJYvnV6XkaUCWuY96bCSc6AuhvkPpqI"/> 0x58, 0x6b, 0x61, 0x55, 0x43, 0x57, 0x75, 0x59, 0x39, 0x36, 0x62, 0x43, \ 0x53, 0x63, 0x36, 0x41, 0x75, 0x68, 0x76, 0x6b, 0x50, 0x70, 0x71, 0x49 +void kms_kmip_request_activate_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_request_activate_test (void) { diff --git a/kms-message/test/test_kms_kmip_response.c b/kms-message/test/test_kms_kmip_response.c index f25fa304c..97c7b81cd 100644 --- a/kms-message/test/test_kms_kmip_response.c +++ b/kms-message/test/test_kms_kmip_response.c @@ -56,6 +56,7 @@ static const uint8_t SUCCESS_REGISTER_RESPONSE[] = { static const char *const SUCCESS_REGISTER_RESPONSE_UNIQUE_IDENTIFIER = "39"; +void kms_kmip_response_get_unique_identifier_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_response_get_unique_identifier_test (void) { @@ -141,6 +142,7 @@ static const uint8_t SUCCESS_GET_RESPONSE_SECRETDATA[] = { 0x36, 0xa9, 0x06, 0x6b, 0x4e, 0x10, 0xae, 0xb5, 0x6a, 0x5c, 0xcf, 0x6a, 0xa4, 0x69, 0x01, 0xe6, 0x25, 0xe3, 0x40, 0x0c, 0x78, 0x11, 0xd2, 0xec}; +void kms_kmip_response_get_secretdata_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_response_get_secretdata_test (void) { @@ -197,6 +199,7 @@ static const uint8_t ERROR_GET_RESPOSE_NOTFOUND[] = { 0x6c, 0x74, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x49, 0x74, 0x65, 0x6d, 0x4e, 0x6f, 0x74, 0x46, 0x6f, 0x75, 0x6e, 0x64}; +void kms_kmip_response_get_secretdata_notfound_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_response_get_secretdata_notfound_test (void) { diff --git a/kms-message/test/test_kms_kmip_response_parser.c b/kms-message/test/test_kms_kmip_response_parser.c index 0d1c773b7..91bf114d8 100644 --- a/kms-message/test/test_kms_kmip_response_parser.c +++ b/kms-message/test/test_kms_kmip_response_parser.c @@ -36,6 +36,7 @@ static const int SAMPLE_KMIP_FIRST_LENGTH = 32; /* SAMPLE_KMIP_LARGE_LENGTH is a byte size larger than the message. */ static const int SAMPLE_KMIP_LARGE_LENGTH = 1024; +void kms_kmip_response_parser_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_response_parser_test (void) { @@ -118,6 +119,7 @@ feed_full_response (kms_response_parser_t *parser, uint8_t *data) } } +void kms_kmip_response_parser_reuse_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_response_parser_reuse_test (void) { @@ -150,6 +152,7 @@ kms_kmip_response_parser_reuse_test (void) free (data); } +void kms_kmip_response_parser_excess_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_response_parser_excess_test (void) { @@ -171,6 +174,7 @@ kms_kmip_response_parser_excess_test (void) free (data); } +void kms_kmip_response_parser_notenough_test (void); // -Wmissing-prototypes: for testing only. void kms_kmip_response_parser_notenough_test (void) { diff --git a/kms-message/test/test_kms_request.c b/kms-message/test/test_kms_request.c index 4c19fd86d..9e944e115 100644 --- a/kms-message/test/test_kms_request.c +++ b/kms-message/test/test_kms_request.c @@ -41,15 +41,15 @@ #include "test_kms_assert.h" -const char *aws_test_suite_dir = "aws-sig-v4-test-suite"; +static const char *aws_test_suite_dir = "aws-sig-v4-test-suite"; -const char *skipped_aws_tests[] = { +static const char *skipped_aws_tests[] = { /* we don't yet support temporary security credentials provided by the AWS * Security Token Service (AWS STS). see post-sts-token/readme.txt */ "post-sts-token", }; -bool +static bool skip_aws_test (const char *test_name) { size_t i; @@ -63,7 +63,7 @@ skip_aws_test (const char *test_name) return false; } -bool +static bool ends_with (const char *str, const char *suffix) { size_t str_len = strlen (str); @@ -77,7 +77,7 @@ ends_with (const char *str, const char *suffix) } -char * +static char * last_segment (const char *str) { const char *p = str + strlen (str); @@ -91,7 +91,7 @@ last_segment (const char *str) return strdup (str); } -char * +static char * test_file_path (const char *path, const char *suffix) { char *r; @@ -103,7 +103,7 @@ test_file_path (const char *path, const char *suffix) return r; } -void +static void realloc_buffer (char **buffer, size_t *n, size_t len) { if (*buffer == NULL) { @@ -117,7 +117,7 @@ realloc_buffer (char **buffer, size_t *n, size_t len) *n = len; } -ssize_t +static ssize_t test_getline (char **lineptr, size_t *n, FILE *stream) { if (*lineptr == NULL && *n == 0) { @@ -162,7 +162,7 @@ test_getline (char **lineptr, size_t *n, FILE *stream) } } -char * +static char * read_test (const char *path, const char *suffix) { char *file_path = test_file_path (path, suffix); @@ -208,7 +208,7 @@ read_test (const char *path, const char *suffix) return str; } -void +static void set_test_date (kms_request_t *request) { struct tm tm; @@ -228,7 +228,7 @@ set_test_date (kms_request_t *request) KMS_ASSERT (kms_request_set_date (request, &tm)); } -kms_request_t * +static kms_request_t * read_req (const char *path) { kms_request_t *request; @@ -303,7 +303,7 @@ read_req (const char *path) return request; } -void +static void test_compare (kms_request_t *request, char *(*func) (kms_request_t *), const char *dir_path, @@ -328,31 +328,31 @@ test_compare (kms_request_t *request, free (test_name); } -void +static void test_compare_creq (kms_request_t *request, const char *dir_path) { test_compare (request, kms_request_get_canonical, dir_path, "creq"); } -void +static void test_compare_sts (kms_request_t *request, const char *dir_path) { test_compare (request, kms_request_get_string_to_sign, dir_path, "sts"); } -void +static void test_compare_authz (kms_request_t *request, const char *dir_path) { test_compare (request, kms_request_get_signature, dir_path, "authz"); } -void +static void test_compare_sreq (kms_request_t *request, const char *dir_path) { test_compare (request, kms_request_get_signed, dir_path, "sreq"); } -void +static void aws_sig_v4_test (const char *dir_path) { kms_request_t *request; @@ -365,7 +365,7 @@ aws_sig_v4_test (const char *dir_path) kms_request_destroy (request); } -bool +static bool all_aws_sig_v4_tests (const char *path, const char *selected) { /* Amazon supplies tests, one per directory, 5 files per test, see @@ -420,7 +420,7 @@ all_aws_sig_v4_tests (const char *path, const char *selected) } /* docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html */ -void +static void example_signature_test (void) { const char *expect = @@ -444,7 +444,7 @@ example_signature_test (void) kms_request_destroy (request); } -void +static void path_normalization_test (void) { const char *tests[][2] = { @@ -499,7 +499,7 @@ path_normalization_test (void) } } -kms_request_t * +static kms_request_t * make_test_request (void) { kms_request_t *request = kms_request_new ("POST", "/", NULL); @@ -513,7 +513,7 @@ make_test_request (void) return request; } -void +static void host_test (void) { kms_request_t *request = make_test_request (); @@ -521,7 +521,7 @@ host_test (void) kms_request_destroy (request); } -void +static void content_length_test (void) { const char *payload = "foo-payload"; @@ -531,7 +531,7 @@ content_length_test (void) kms_request_destroy (request); } -void +static void bad_query_test (void) { kms_request_t *request = kms_request_new ("GET", "/?asdf", NULL); @@ -539,7 +539,7 @@ bad_query_test (void) kms_request_destroy (request); } -void +static void append_header_field_value_test (void) { kms_request_t *request = kms_request_new ("GET", "/", NULL); @@ -550,7 +550,7 @@ append_header_field_value_test (void) kms_request_destroy (request); } -void +static void set_date_test (void) { // Windows CRT asserts on this negative test because it is a negative test @@ -566,7 +566,7 @@ set_date_test (void) #endif } -void +static void multibyte_test (void) { /* euro currency symbol */ @@ -595,7 +595,7 @@ multibyte_test (void) #undef EU } -void +static void connection_close_test (void) { kms_request_opt_t *opt; @@ -617,7 +617,7 @@ connection_close_test (void) } /* the ciphertext blob from a response to an "Encrypt" API call */ -const char ciphertext_blob[] = +static const char ciphertext_blob[] = "\x01\x02\x02\x00\x78\xf3\x8e\xd8\xd4\xc6\xba\xfb\xa1\xcf\xc1\x1e\x68\xf2" "\xa1\x91\x9e\x36\x4d\x74\xa2\xc4\x9e\x30\x67\x08\x53\x33\x0d\xcd\xe0\xc9" "\x1b\x01\x60\x30\xd4\x73\x9e\x90\x1f\xa7\x43\x55\x84\x26\xf9\xd5\xf0\xb1" @@ -628,7 +628,7 @@ const char ciphertext_blob[] = "\x03\xcd\xcb\xe2\xac\x36\x4f\x73\xdb\x1b\x73\x2e\x33\xda\x45\x51\xf4\xcd" "\xc0\xff\xd2\xe1\xb9\xc4\xc2\x0e\xbf\x53\x90\x46\x18\x42"; -void +static void decrypt_request_test (void) { kms_request_t *request = kms_decrypt_request_new ( @@ -647,7 +647,7 @@ decrypt_request_test (void) kms_request_destroy (request); } -void +static void encrypt_request_test (void) { char *plaintext = "foobar"; @@ -667,7 +667,7 @@ encrypt_request_test (void) kms_request_destroy (request); } -void +static void kv_list_del_test (void) { kms_kv_list_t *lst = kms_kv_list_new (); @@ -694,7 +694,7 @@ kv_list_del_test (void) kms_kv_list_destroy (lst); } -void +static void b64_test (void) { uint8_t *expected = (uint8_t *) "\x01\x02\x03\x04"; @@ -710,7 +710,7 @@ b64_test (void) KMS_ASSERT (0 == memcmp (expected, data, 4)); } -void +static void b64_b64url_test (void) { char base64_data[64]; @@ -742,7 +742,7 @@ b64_b64url_test (void) ASSERT_CMPSTR (base64_data, "PDw_Pz8-Pg=="); } -void +static void kms_response_parser_test (void) { kms_response_parser_t *parser = kms_response_parser_new (); @@ -956,7 +956,7 @@ kms_response_parser_files (void) _field = kms_request_str_new (); \ } while (0) -void +static void kms_request_validate_test (void) { kms_request_t *request = NULL; diff --git a/src/crypto/libcrypto.c b/src/crypto/libcrypto.c index 2fee38475..9cdc24930 100644 --- a/src/crypto/libcrypto.c +++ b/src/crypto/libcrypto.c @@ -173,6 +173,8 @@ bool _native_crypto_aes_256_cbc_decrypt(aes_256_args_t args) { return _decrypt_with_cipher(EVP_aes_256_cbc(), args); } +bool _native_crypto_aes_256_ecb_encrypt(aes_256_args_t args); // -Wmissing-prototypes: for testing only. + bool _native_crypto_aes_256_ecb_encrypt(aes_256_args_t args) { return _encrypt_with_cipher(EVP_aes_256_ecb(), args); } diff --git a/src/mc-dec128.h b/src/mc-dec128.h index fd994874f..0a6e7a29f 100644 --- a/src/mc-dec128.h +++ b/src/mc-dec128.h @@ -11,11 +11,11 @@ // the ImportDFP.cmake script: #ifndef MONGOCRYPT_INTELDFP // Notify includers that Decimal128 is not available: -#define MONGOCRYPT_HAVE_DECIMAL128_SUPPORT 0 +#define MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() false #else // With IntelDFP: // Tell includers that Decimal128 is okay: -#define MONGOCRYPT_HAVE_DECIMAL128_SUPPORT 1 +#define MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() true // Include the header that declares the DFP functions, which may be macros that // expand to renamed symbols: diff --git a/src/mc-dec128.test.cpp b/src/mc-dec128.test.cpp index 9f7ac749f..ab21aba54 100644 --- a/src/mc-dec128.test.cpp +++ b/src/mc-dec128.test.cpp @@ -2,7 +2,7 @@ #include -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() #include diff --git a/src/mc-fle2-payload-iev-v2.c b/src/mc-fle2-payload-iev-v2.c index 4a9ec9b96..358028ba2 100644 --- a/src/mc-fle2-payload-iev-v2.c +++ b/src/mc-fle2-payload-iev-v2.c @@ -17,6 +17,7 @@ #include "mongocrypt-buffer-private.h" #include "mongocrypt-private.h" +#include "mc-dec128.h" #include "mc-fle-blob-subtype-private.h" #include "mc-fle2-payload-iev-private-v2.h" #include "mc-fle2-tag-and-encrypted-metadata-block-private.h" @@ -27,7 +28,6 @@ #include #define kMinServerEncryptedValueLen 17U // IV(16) + EncryptCTR(1byte) -#define kMinSEVAndMetadataLen (kMinServerEncryptedValueLen + kMetadataLen) #define CHECK_AND_RETURN(x) \ if (!(x)) { \ @@ -721,7 +721,7 @@ static bool is_fle2_range_indexed_supported_type(int bson_type) { case BSON_TYPE_INT64: case BSON_TYPE_DATE_TIME: case BSON_TYPE_DOUBLE: -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() case BSON_TYPE_DECIMAL128: #endif return true; diff --git a/src/mc-fle2-payload-iev.c b/src/mc-fle2-payload-iev.c index 15e421ff8..83a4b0674 100644 --- a/src/mc-fle2-payload-iev.c +++ b/src/mc-fle2-payload-iev.c @@ -78,7 +78,7 @@ static bool mc_fle2IndexedEncryptedValue_encrypt(_mongocrypt_crypto_t *crypto, _mongocrypt_buffer_t *out, mongocrypt_status_t *status); -bool safe_uint32_t_sum(const uint32_t a, const uint32_t b, uint32_t *out, mongocrypt_status_t *status) { +static bool safe_uint32_t_sum(const uint32_t a, const uint32_t b, uint32_t *out, mongocrypt_status_t *status) { if (a > UINT32_MAX - b) { CLIENT_ERR("safe_uint32_t_sum overflow, %" PRIu32 ", %" PRIu32, a, b); return false; diff --git a/src/mc-fle2-rfds.c b/src/mc-fle2-rfds.c index 0622bfd9d..c13b1b204 100644 --- a/src/mc-fle2-rfds.c +++ b/src/mc-fle2-rfds.c @@ -302,10 +302,7 @@ bool mc_FLE2RangeFindDriverSpec_parse(mc_FLE2RangeFindDriverSpec_t *spec, spec->upper.included = op.op_type == FLE2RangeOperator_kLte; break; case FLE2RangeOperator_kNone: - default: - ERR_WITH_BSON(in, "unsupported operator type %s", op.op_type_str); - goto fail; - break; + default: ERR_WITH_BSON(in, "unsupported operator type %s", op.op_type_str); goto fail; } if (spec->field && 0 != strcmp(spec->field, op.field)) { @@ -579,6 +576,8 @@ static void payloadId_init_mutex(void) { _mongocrypt_mutex_init(&payloadId_mutex); } +void mc_reset_payloadId_for_testing(void); // -Wmissing-prototypes: for testing only. + void mc_reset_payloadId_for_testing(void) { mlib_call_once(&payloadId_init_flag, payloadId_init_mutex); MONGOCRYPT_WITH_MUTEX(payloadId_mutex) { diff --git a/src/mc-optional-private.h b/src/mc-optional-private.h index 42a92eb39..5d7f411b7 100644 --- a/src/mc-optional-private.h +++ b/src/mc-optional-private.h @@ -89,7 +89,7 @@ typedef struct { #define OPT_DOUBLE_C(val) \ { .set = true, .value = val } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() typedef struct { bool set; mc_dec128 value; diff --git a/src/mc-range-edge-generation-private.h b/src/mc-range-edge-generation-private.h index 268eef335..2d6eda43f 100644 --- a/src/mc-range-edge-generation-private.h +++ b/src/mc-range-edge-generation-private.h @@ -80,7 +80,7 @@ typedef struct { // SERVER-67751 for double. mc_edges_t *mc_getEdgesDouble(mc_getEdgesDouble_args_t args, mongocrypt_status_t *status, bool use_range_v2); -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() typedef struct { mc_dec128 value; size_t sparsity; diff --git a/src/mc-range-edge-generation.c b/src/mc-range-edge-generation.c index b9852e0dc..8f3dd9b96 100644 --- a/src/mc-range-edge-generation.c +++ b/src/mc-range-edge-generation.c @@ -227,7 +227,7 @@ mc_edges_t *mc_getEdgesDouble(mc_getEdgesDouble_args_t args, mongocrypt_status_t return ret; } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() mc_edges_t *mc_getEdgesDecimal128(mc_getEdgesDecimal128_args_t args, mongocrypt_status_t *status, bool use_range_v2) { mc_OSTType_Decimal128 got; if (!mc_getTypeInfoDecimal128( diff --git a/src/mc-range-encoding-private.h b/src/mc-range-encoding-private.h index 2250b1fb4..45022f62e 100644 --- a/src/mc-range-encoding-private.h +++ b/src/mc-range-encoding-private.h @@ -100,7 +100,7 @@ bool mc_getTypeInfoDouble(mc_getTypeInfoDouble_args_t args, mongocrypt_status_t *status, bool use_range_v2) MONGOCRYPT_WARN_UNUSED_RESULT; -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() /** * @brief OST-encoding of a Decimal128 */ diff --git a/src/mc-range-encoding.c b/src/mc-range-encoding.c index e7d423b4b..b513ef5f9 100644 --- a/src/mc-range-encoding.c +++ b/src/mc-range-encoding.c @@ -165,7 +165,7 @@ bool mc_getTypeInfo64(mc_getTypeInfo64_args_t args, mc_OSTType_Int64 *out, mongo #define exp10Double(x) pow(10, x) #define SCALED_DOUBLE_BOUNDS 9007199254740992.0 // 2^53 -uint64_t subtract_int64_t(int64_t max, int64_t min) { +static uint64_t subtract_int64_t(int64_t max, int64_t min) { BSON_ASSERT(max > min); // If the values have the same sign, then simple subtraction // will work because we know max > min. @@ -180,7 +180,7 @@ uint64_t subtract_int64_t(int64_t max, int64_t min) { return u_return; } -bool ceil_log2_double(uint64_t i, uint32_t *maxBitsOut, mongocrypt_status_t *status) { +static bool ceil_log2_double(uint64_t i, uint32_t *maxBitsOut, mongocrypt_status_t *status) { if (i == 0) { CLIENT_ERR("Invalid input to ceil_log2_double function. Input cannot be 0."); return false; @@ -421,7 +421,7 @@ bool mc_getTypeInfoDouble(mc_getTypeInfoDouble_args_t args, return true; } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() /** * @brief There is no shipped algorithm for creating a full 128-bit integer from * a Decimal128, but it's easy enough to write one of our own. @@ -852,7 +852,7 @@ bool mc_getTypeInfoDecimal128(mc_getTypeInfoDecimal128_args_t args, #endif // defined MONGOCRYPT_HAVE_DECIMAL128_SUPPORT const int64_t mc_FLERangeSparsityDefault = 2; -const int32_t mc_FLERangeTrimFactorDefault = 6; +static const int32_t mc_FLERangeTrimFactorDefault = 6; int32_t trimFactorDefault(size_t maxlen, mc_optional_int32_t trimFactor, bool use_range_v2) { if (trimFactor.set) { diff --git a/src/mc-range-mincover-generator.template.h b/src/mc-range-mincover-generator.template.h index af54aa038..81a915fab 100644 --- a/src/mc-range-mincover-generator.template.h +++ b/src/mc-range-mincover-generator.template.h @@ -174,7 +174,7 @@ static inline bool DECORATE_NAME(MinCoverGenerator_isLevelStored)(DECORATE_NAME( return 0 == maskedBits || (level >= trimFactor_sz && 0 == (level % mcg->_sparsity)); } -char * +static char * DECORATE_NAME(MinCoverGenerator_toString)(DECORATE_NAME(MinCoverGenerator) * mcg, UINT_T start, size_t maskedBits) { BSON_ASSERT_PARAM(mcg); BSON_ASSERT(maskedBits <= mcg->_maxlen); diff --git a/src/mc-range-mincover-private.h b/src/mc-range-mincover-private.h index 2129dff08..4ca291400 100644 --- a/src/mc-range-mincover-private.h +++ b/src/mc-range-mincover-private.h @@ -91,7 +91,7 @@ mc_mincover_t *mc_getMincoverDouble(mc_getMincoverDouble_args_t args, mongocrypt_status_t *status, bool use_range_v2) MONGOCRYPT_WARN_UNUSED_RESULT; -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() typedef struct { mc_dec128 lowerBound; bool includeLowerBound; diff --git a/src/mc-range-mincover.c b/src/mc-range-mincover.c index 3e8d8d471..b0e90e2e7 100644 --- a/src/mc-range-mincover.c +++ b/src/mc-range-mincover.c @@ -80,7 +80,7 @@ void mc_mincover_destroy(mc_mincover_t *mincover) { // The 128-bit version is only required for Decimal128, otherwise generates // unused-fn warnings -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() #define UINT_T mlib_int128 #define UINT_C MLIB_INT128 #define UINT_FMT_S "s" @@ -243,7 +243,7 @@ mc_mincover_t *mc_getMincoverDouble(mc_getMincoverDouble_args_t args, mongocrypt return mc; } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() mc_mincover_t * mc_getMincoverDecimal128(mc_getMincoverDecimal128_args_t args, mongocrypt_status_t *status, bool use_range_v2) { BSON_ASSERT_PARAM(status); diff --git a/src/mc-rangeopts.c b/src/mc-rangeopts.c index 78a8812d1..d263b9ae7 100644 --- a/src/mc-rangeopts.c +++ b/src/mc-rangeopts.c @@ -41,12 +41,6 @@ continue; \ } -#define CHECK_HAS(Name) \ - if (!has_##Name) { \ - CLIENT_ERR_PREFIXED("Missing field '" #Name "'"); \ - return false; \ - } - #define ERROR_PREFIX "Error parsing RangeOpts" bool mc_RangeOpts_parse(mc_RangeOpts_t *ro, const bson_t *in, bool use_range_v2, mongocrypt_status_t *status) { @@ -301,7 +295,7 @@ bool mc_RangeOpts_appendMin(const mc_RangeOpts_t *ro, return false; } } else if (valueType == BSON_TYPE_DECIMAL128) { -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() const bson_decimal128_t min = mc_dec128_to_bson_decimal128(MC_DEC128_LARGEST_NEGATIVE); if (!BSON_APPEND_DECIMAL128(out, fieldName, &min)) { CLIENT_ERR_PREFIXED("failed to append BSON"); @@ -356,7 +350,7 @@ bool mc_RangeOpts_appendMax(const mc_RangeOpts_t *ro, return false; } } else if (valueType == BSON_TYPE_DECIMAL128) { -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() const bson_decimal128_t max = mc_dec128_to_bson_decimal128(MC_DEC128_LARGEST_POSITIVE); if (!BSON_APPEND_DECIMAL128(out, fieldName, &max)) { CLIENT_ERR_PREFIXED("failed to append BSON"); @@ -379,11 +373,11 @@ bool mc_RangeOpts_appendMax(const mc_RangeOpts_t *ro, // Used to calculate max trim factor. Returns the number of bits required to represent any number in // the domain. -bool mc_getNumberOfBits(const mc_RangeOpts_t *ro, - bson_type_t valueType, - uint32_t *bitsOut, - mongocrypt_status_t *status, - bool use_range_v2) { +static bool mc_getNumberOfBits(const mc_RangeOpts_t *ro, + bson_type_t valueType, + uint32_t *bitsOut, + mongocrypt_status_t *status, + bool use_range_v2) { BSON_ASSERT_PARAM(ro); BSON_ASSERT_PARAM(bitsOut); @@ -456,7 +450,7 @@ bool mc_getNumberOfBits(const mc_RangeOpts_t *ro, *bitsOut = 64 - (uint32_t)mc_count_leading_zeros_u64(out.max); return true; } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() else if (valueType == BSON_TYPE_DECIMAL128) { mc_dec128 value = MC_DEC128_ZERO; mc_optional_dec128_t rmin = {false, MC_DEC128_ZERO}, rmax = {false, MC_DEC128_ZERO}; diff --git a/src/mc-str-encode-string-sets.c b/src/mc-str-encode-string-sets.c index 2d6caaca0..135c2cbd4 100644 --- a/src/mc-str-encode-string-sets.c +++ b/src/mc-str-encode-string-sets.c @@ -166,8 +166,8 @@ static void mc_substring_set_node_destroy(mc_substring_set_node_t *node) { } // FNV-1a hash function -const uint32_t FNV1APRIME = 16777619; -const uint32_t FNV1ABASIS = 2166136261; +static const uint32_t FNV1APRIME = 16777619; +static const uint32_t FNV1ABASIS = 2166136261; static uint32_t fnv1a(const uint8_t *data, uint32_t len) { BSON_ASSERT_PARAM(data); diff --git a/src/mc-tokens.c b/src/mc-tokens.c index 95234b16b..af520a948 100644 --- a/src/mc-tokens.c +++ b/src/mc-tokens.c @@ -168,7 +168,7 @@ IMPL_TOKEN_NEW_CONST(mc_ServerZerosEncryptionToken, mc_ServerDerivedFromDataToke // d = 17 bytes of 0, AnchorPaddingTokenRoot = HMAC(ESCToken, d) #define ANCHOR_PADDING_TOKEN_D_LENGTH 17 -const uint8_t mc_AnchorPaddingTokenDValue[ANCHOR_PADDING_TOKEN_D_LENGTH] = +static const uint8_t mc_AnchorPaddingTokenDValue[ANCHOR_PADDING_TOKEN_D_LENGTH] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; DEF_TOKEN_TYPE(mc_AnchorPaddingTokenRoot, const mc_ESCToken_t *ESCToken) { diff --git a/src/mlib/int128.h b/src/mlib/int128.h index d43338392..e397e029c 100644 --- a/src/mlib/int128.h +++ b/src/mlib/int128.h @@ -9,6 +9,12 @@ #include #include +// Deliberately using old-style casts for C and C++ compatibility. +#if defined(__cplusplus) && defined(__clang__) +_Pragma("clang diagnostic push"); +_Pragma("clang diagnostic ignored \"-Wold-style-cast\""); +#endif + MLIB_C_LINKAGE_BEGIN /** @@ -644,4 +650,9 @@ static mlib_constexpr_fn mlib_int128_charbuf mlib_int128_format(mlib_int128 i) { MLIB_C_LINKAGE_END +// Deliberately using old-style casts for C and C++ compatibility. +#if defined(__cplusplus) && defined(__clang__) +_Pragma("clang diagnostic pop"); +#endif + #endif // MLIB_INT128_H_INCLUDED diff --git a/src/mlib/int128.test.cpp b/src/mlib/int128.test.cpp index 3a0854a3b..388ac334c 100644 --- a/src/mlib/int128.test.cpp +++ b/src/mlib/int128.test.cpp @@ -10,6 +10,11 @@ #include #include +// Deliberately using old-style casts for C and C++ compatibility. +#if defined(__clang__) +_Pragma("clang diagnostic ignored \"-Wold-style-cast\""); +#endif + #if (defined(__GNUC__) && __GNUC__ < 7 && !defined(__clang__)) || (defined(_MSC_VER) && _MSC_VER < 1920) // Old GCC and old MSVC have partially-broken constexpr that prevents us from // properly using static_assert with from_string() diff --git a/src/mlib/path.h b/src/mlib/path.h index 262014d9d..0a259e95b 100644 --- a/src/mlib/path.h +++ b/src/mlib/path.h @@ -60,7 +60,7 @@ static inline char mpath_preferred_sep(mpath_format f) { * @return mstr A new string which must be freed with mstr_free() */ static inline mstr mpath_current_path(void) { -#if _WIN32 +#if defined(_WIN32) while (1) { DWORD len = GetCurrentDirectoryW(0, NULL); wchar_t *wstr = calloc(sizeof(wchar_t), len); diff --git a/src/mlib/path.test.c b/src/mlib/path.test.c index a661d5f02..d87408517 100644 --- a/src/mlib/path.test.c +++ b/src/mlib/path.test.c @@ -1,8 +1,5 @@ #include "./path.h" -#define CHECK(Expr) \ - ((Expr) ? 0 : ((fprintf(stderr, "%s:%d: Check '%s' failed\n", __FILE__, __LINE__, #Expr), abort()), 0)) - #define TEST_DECOMP(Part, Given, Expect) \ MSTR_ASSERT_EQ(mpath_##Part(mstrv_view_cstr(Given), MPATH_NATIVE), mstrv_view_cstr(Expect)) @@ -12,7 +9,7 @@ static void test_make_absolute(mpath_format f, const char *part, const char *bas mstr_free(result); } -int main() { +int main(void) { mstr s = mstr_copy_cstr("/foo/bar/baz.txt"); MSTR_ASSERT_EQ(mpath_parent(s.view, MPATH_NATIVE), mstrv_lit("/foo/bar")); MSTR_ASSERT_EQ(mpath_parent(mpath_parent(s.view, MPATH_NATIVE), MPATH_NATIVE), mstrv_lit("/foo")); diff --git a/src/mlib/str.h b/src/mlib/str.h index 1477b52c4..55509a07c 100644 --- a/src/mlib/str.h +++ b/src/mlib/str.h @@ -17,6 +17,12 @@ #include /* For strncasecmp. */ #endif +// Deliberately using old-style casts for C and C++ compatibility. +#if defined(__cplusplus) && defined(__clang__) +_Pragma("clang diagnostic push"); +_Pragma("clang diagnostic ignored \"-Wold-style-cast\""); +#endif + MLIB_C_LINKAGE_BEGIN /** @@ -906,4 +912,9 @@ static mlib_constexpr_fn size_t mlib_strnmcopy(char *dst, size_t dst_bufsize, co MLIB_C_LINKAGE_END +// Deliberately using old-style casts for C and C++ compatibility. +#if defined(__cplusplus) && defined(__clang__) +_Pragma("clang diagnostic pop"); +#endif + #endif // MONGOCRYPT_STR_PRIVATE_H diff --git a/src/mlib/str.test.c b/src/mlib/str.test.c index f0529129f..c881db982 100644 --- a/src/mlib/str.test.c +++ b/src/mlib/str.test.c @@ -5,7 +5,7 @@ #define test_predicate(Bool, Left, Pred, Right) MSTR_ASSERT(Bool, mstrv_lit(Left), Pred, mstrv_lit(Right)) -int main() { +int main(void) { // Test the null-initializers: mstr str = MSTR_NULL; mstr_view null_view = MSTRV_NULL; diff --git a/src/mlib/thread.h b/src/mlib/thread.h index 8cb26c56d..574603147 100644 --- a/src/mlib/thread.h +++ b/src/mlib/thread.h @@ -40,7 +40,7 @@ typedef struct mlib_once_flag { */ typedef void (*mlib_init_once_fn_t)(void); -#if _WIN32 +#if defined(_WIN32) /** * An indirection layer for mlib_once on Windows platforms. Do not use directly. */ diff --git a/src/mongocrypt-cache-collinfo.c b/src/mongocrypt-cache-collinfo.c index a25a5ae24..b9a55a0ff 100644 --- a/src/mongocrypt-cache-collinfo.c +++ b/src/mongocrypt-cache-collinfo.c @@ -14,6 +14,10 @@ * limitations under the License. */ +#include "mongocrypt-cache-collinfo-private.h" + +// + #include "mongocrypt-cache-private.h" /* The collinfo cache. diff --git a/src/mongocrypt-crypto-private.h b/src/mongocrypt-crypto-private.h index e06ab892f..99e191918 100644 --- a/src/mongocrypt-crypto-private.h +++ b/src/mongocrypt-crypto-private.h @@ -77,18 +77,18 @@ typedef struct { // FLE1 algorithm: AES-256-CBC HMAC/SHA-512-256 (SHA-512 truncated to 256 bits) // Algorithm is documented in [FLE and // AEAD](https://docs.google.com/document/d/1D8xTXWo1B1dunO0bDZhPdolKTMbbD5fUIgsERubWRmY) -const _mongocrypt_value_encryption_algorithm_t *_mcFLE1Algorithm(); +const _mongocrypt_value_encryption_algorithm_t *_mcFLE1Algorithm(void); // FLE2 general algorithm: AES-256-CTR HMAC/SHA-256 // Algorithm is documented in [AEAD with // CTR](https://docs.google.com/document/d/1eCU7R8Kjr-mdyz6eKvhNIDVmhyYQcAaLtTfHeK7a_vE/). -const _mongocrypt_value_encryption_algorithm_t *_mcFLE2AEADAlgorithm(); +const _mongocrypt_value_encryption_algorithm_t *_mcFLE2AEADAlgorithm(void); // FLE2 used with FLE2IndexedEncryptedValue: AES-256-CTR no HMAC -const _mongocrypt_value_encryption_algorithm_t *_mcFLE2Algorithm(); +const _mongocrypt_value_encryption_algorithm_t *_mcFLE2Algorithm(void); // FLE2AEAD general algorithm: AES-256-CBC HMAC/SHA-256 -const _mongocrypt_value_encryption_algorithm_t *_mcFLE2v2AEADAlgorithm(); +const _mongocrypt_value_encryption_algorithm_t *_mcFLE2v2AEADAlgorithm(void); bool _mongocrypt_random(_mongocrypt_crypto_t *crypto, _mongocrypt_buffer_t *out, diff --git a/src/mongocrypt-crypto.c b/src/mongocrypt-crypto.c index 4d3a5a53a..4ba284c1a 100644 --- a/src/mongocrypt-crypto.c +++ b/src/mongocrypt-crypto.c @@ -1142,7 +1142,9 @@ static bool _mongocrypt_do_decryption(_mongocrypt_crypto_t *crypto, _mc_##name##_do_encryption, \ _mc_##name##_do_decryption, \ }; \ - const _mongocrypt_value_encryption_algorithm_t *_mc##name##Algorithm() { return &_mc##name##Algorithm_definition; } + const _mongocrypt_value_encryption_algorithm_t *_mc##name##Algorithm(void) { \ + return &_mc##name##Algorithm_definition; \ + } // FLE1 algorithm: AES-256-CBC HMAC/SHA-512-256 (SHA-512 truncated to 256 bits) DECLARE_ALGORITHM(FLE1, CBC, SHA_512_256) diff --git a/src/mongocrypt-dll-private.h b/src/mongocrypt-dll-private.h index 3debb7314..3340730bc 100644 --- a/src/mongocrypt-dll-private.h +++ b/src/mongocrypt-dll-private.h @@ -6,9 +6,9 @@ #include -#if _WIN32 +#if defined(_WIN32) #define MCR_DLL_SUFFIX ".dll" -#elif __APPLE__ +#elif defined(__APPLE__) #define MCR_DLL_SUFFIX ".dylib" #else #define MCR_DLL_SUFFIX ".so" diff --git a/src/mongocrypt-key-broker.c b/src/mongocrypt-key-broker.c index 7af66c4e5..5bf7ae234 100644 --- a/src/mongocrypt-key-broker.c +++ b/src/mongocrypt-key-broker.c @@ -24,11 +24,11 @@ typedef struct _auth_request_t { char *kmsid; } auth_request_t; -auth_request_t *auth_request_new() { +static auth_request_t *auth_request_new(void) { return bson_malloc0(sizeof(auth_request_t)); } -void auth_request_destroy(auth_request_t *ar) { +static void auth_request_destroy(auth_request_t *ar) { if (!ar) { return; } @@ -41,13 +41,13 @@ struct _mc_mapof_kmsid_to_authrequest_t { mc_array_t entries; }; -mc_mapof_kmsid_to_authrequest_t *mc_mapof_kmsid_to_authrequest_new(void) { +static mc_mapof_kmsid_to_authrequest_t *mc_mapof_kmsid_to_authrequest_new(void) { mc_mapof_kmsid_to_authrequest_t *k2a = bson_malloc0(sizeof(mc_mapof_kmsid_to_authrequest_t)); _mc_array_init(&k2a->entries, sizeof(auth_request_t *)); return k2a; } -void mc_mapof_kmsid_to_authrequest_destroy(mc_mapof_kmsid_to_authrequest_t *k2a) { +static void mc_mapof_kmsid_to_authrequest_destroy(mc_mapof_kmsid_to_authrequest_t *k2a) { if (!k2a) { return; } @@ -59,7 +59,7 @@ void mc_mapof_kmsid_to_authrequest_destroy(mc_mapof_kmsid_to_authrequest_t *k2a) bson_free(k2a); } -bool mc_mapof_kmsid_to_authrequest_has(const mc_mapof_kmsid_to_authrequest_t *k2a, const char *kmsid) { +static bool mc_mapof_kmsid_to_authrequest_has(const mc_mapof_kmsid_to_authrequest_t *k2a, const char *kmsid) { BSON_ASSERT_PARAM(k2a); BSON_ASSERT_PARAM(kmsid); for (size_t i = 0; i < k2a->entries.len; i++) { @@ -71,25 +71,25 @@ bool mc_mapof_kmsid_to_authrequest_has(const mc_mapof_kmsid_to_authrequest_t *k2 return false; } -size_t mc_mapof_kmsid_to_authrequest_len(const mc_mapof_kmsid_to_authrequest_t *k2a) { +static size_t mc_mapof_kmsid_to_authrequest_len(const mc_mapof_kmsid_to_authrequest_t *k2a) { BSON_ASSERT_PARAM(k2a); return k2a->entries.len; } -bool mc_mapof_kmsid_to_authrequest_empty(const mc_mapof_kmsid_to_authrequest_t *k2a) { +static bool mc_mapof_kmsid_to_authrequest_empty(const mc_mapof_kmsid_to_authrequest_t *k2a) { BSON_ASSERT_PARAM(k2a); return k2a->entries.len == 0; } // `mc_mapof_kmsid_to_authrequest_put` moves `to_put` into the map and takes ownership of `to_put`. // No checking is done to prohibit duplicate entries. -void mc_mapof_kmsid_to_authrequest_put(mc_mapof_kmsid_to_authrequest_t *k2a, auth_request_t *to_put) { +static void mc_mapof_kmsid_to_authrequest_put(mc_mapof_kmsid_to_authrequest_t *k2a, auth_request_t *to_put) { BSON_ASSERT_PARAM(k2a); _mc_array_append_val(&k2a->entries, to_put); } -auth_request_t *mc_mapof_kmsid_to_authrequest_at(mc_mapof_kmsid_to_authrequest_t *k2a, size_t i) { +static auth_request_t *mc_mapof_kmsid_to_authrequest_at(mc_mapof_kmsid_to_authrequest_t *k2a, size_t i) { BSON_ASSERT_PARAM(k2a); return _mc_array_index(&k2a->entries, auth_request_t *, i); diff --git a/src/mongocrypt-marking.c b/src/mongocrypt-marking.c index 49b2cbbf5..d0ed58308 100644 --- a/src/mongocrypt-marking.c +++ b/src/mongocrypt-marking.c @@ -890,7 +890,7 @@ get_edges(mc_FLE2RangeInsertSpec_t *insertSpec, size_t sparsity, mongocrypt_stat } else if (value_type == BSON_TYPE_DECIMAL128) { -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() const mc_dec128 value = mc_dec128_from_bson_iter(&insertSpec->v); mc_getEdgesDecimal128_args_t args = { .value = value, @@ -1648,7 +1648,7 @@ mc_mincover_t *mc_get_mincover_from_FLE2RangeFindSpec(mc_FLE2RangeFindSpec_t *fi return mc_getMincoverDouble(args, status, use_range_v2); } case BSON_TYPE_DECIMAL128: { -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() BSON_ASSERT(bson_iter_type(&lowerBound) == BSON_TYPE_DECIMAL128); BSON_ASSERT(bson_iter_type(&upperBound) == BSON_TYPE_DECIMAL128); BSON_ASSERT(bson_iter_type(&findSpec->edgesInfo.value.indexMin) == BSON_TYPE_DECIMAL128); diff --git a/src/mongocrypt.c b/src/mongocrypt.c index 6e3ae05d7..b40f3e9d2 100644 --- a/src/mongocrypt.c +++ b/src/mongocrypt.c @@ -548,13 +548,13 @@ typedef struct csfle_global_lib_state { mongo_crypt_v1_lib *csfle_lib; } csfle_global_lib_state; -csfle_global_lib_state g_csfle_state; +static csfle_global_lib_state g_csfle_state; static void init_csfle_state(void) { _mongocrypt_mutex_init(&g_csfle_state.mtx); } -mlib_once_flag g_csfle_init_flag = MLIB_ONCE_INITIALIZER; +static mlib_once_flag g_csfle_init_flag = MLIB_ONCE_INITIALIZER; /** * @brief Verify that `found` refers to the same library that is globally loaded diff --git a/src/os_posix/os_dll.c b/src/os_posix/os_dll.c index 21149e6eb..abec59573 100644 --- a/src/os_posix/os_dll.c +++ b/src/os_posix/os_dll.c @@ -41,6 +41,8 @@ mcr_dll mcr_dll_open(const char *filepath) { } } +void mcr_dll_close_handle(mcr_dll); // -Wmissing-prototypes: not for external use despite external linkage. + void mcr_dll_close_handle(mcr_dll dll) { if (dll._native_handle) { dlclose(dll._native_handle); diff --git a/src/os_win/os_dll.c b/src/os_win/os_dll.c index e6e4f1b5a..fb73e5e8a 100644 --- a/src/os_win/os_dll.c +++ b/src/os_win/os_dll.c @@ -36,6 +36,8 @@ mcr_dll mcr_dll_open(const char *filepath_) { return (mcr_dll){.error_string = NULL, ._native_handle = lib}; } +void mcr_dll_close_handle(mcr_dll); // -Wmissing-prototypes: not for external use despite external linkage. + void mcr_dll_close_handle(mcr_dll dll) { if (dll._native_handle) { FreeLibrary(dll._native_handle); diff --git a/test/crypt_shared-stub.cpp b/test/crypt_shared-stub.cpp index 037d75f59..59175b3b3 100644 --- a/test/crypt_shared-stub.cpp +++ b/test/crypt_shared-stub.cpp @@ -7,12 +7,6 @@ * libmongocrypt. */ -#ifdef _WIN32 -#define EXPORT_API __declspec(dllexport) -#else -#define EXPORT_API __attribute__((visibility("default"))) -#endif - #define MONGO_CRYPT_SUPPORT_COMPILING #include @@ -22,14 +16,6 @@ #include #include -#ifdef _WIN32 -#define MONGO_API_CALL __cdecl -#define MONGO_API_EXPORT __declspec(dllexport) -#else -#define MONGO_API_CALL [[]] -#define MONGO_API_EXPORT __attribute__((used, visibility("default"))) -#endif - struct mongo_crypt_v1_status {}; typedef mongo_crypt_v1_status status_t; diff --git a/test/example-state-machine.c b/test/example-state-machine.c index 6ede0d80e..3ff7456ba 100644 --- a/test/example-state-machine.c +++ b/test/example-state-machine.c @@ -135,7 +135,7 @@ static void _print_binary_as_text(mongocrypt_binary_t *binary) { continue; \ } -void _run_state_machine(mongocrypt_ctx_t *ctx, bson_t *result) { +static void _run_state_machine(mongocrypt_ctx_t *ctx, bson_t *result) { mongocrypt_binary_t *input, *output = NULL; bson_t tmp; mongocrypt_kms_ctx_t *kms; @@ -227,11 +227,10 @@ void _run_state_machine(mongocrypt_ctx_t *ctx, bson_t *result) { mongocrypt_ctx_status(ctx, status); printf("\ngot error: %s\n", mongocrypt_status_message(status, NULL)); abort(); - break; case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS: // We don't handle KMS credentials // fallthrough - default: BSON_ASSERT(0); break; + default: BSON_ASSERT(0); } } @@ -247,7 +246,7 @@ static mongocrypt_binary_t *_iter_to_binary(bson_iter_t *iter) { return mongocrypt_binary_new_from_data(data, len); } -int main() { +int main(void) { bson_iter_t iter; bson_t result; bson_t key_doc; diff --git a/test/test-dll.cpp b/test/test-dll.cpp index 9ad69f503..d748a5390 100644 --- a/test/test-dll.cpp +++ b/test/test-dll.cpp @@ -8,14 +8,20 @@ static std::string global_str; -extern "C" -#if _MSC_VER - __declspec(dllexport) +#if defined(_MSC_VER) +#define SAY_HELLO_EXPORT __declspec(dllexport) #else -__attribute__ ((visibility ("default"))) +#define SAY_HELLO_EXPORT __attribute__((visibility("default"))) #endif - int say_hello() { + +extern "C" { + +SAY_HELLO_EXPORT int say_hello(); // -Wmissing-prototypes: for testing only. + +int say_hello() { global_str = "Hello, DLL!"; std::cout << global_str << "\n"; return 42; } + +} // extern "C" diff --git a/test/test-mc-range-edge-generation.c b/test/test-mc-range-edge-generation.c index e7e5b08fe..3a97abd23 100644 --- a/test/test-mc-range-edge-generation.c +++ b/test/test-mc-range-edge-generation.c @@ -308,7 +308,7 @@ static void _test_getEdgesDouble(_mongocrypt_tester_t *tester) { } } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() #define MAX_DEC128_EDGES 129 typedef struct { @@ -492,7 +492,7 @@ void _mongocrypt_tester_install_range_edge_generation(_mongocrypt_tester_t *test INSTALL_TEST(_test_getEdgesInt32); INSTALL_TEST(_test_getEdgesInt64); INSTALL_TEST(_test_getEdgesDouble); -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() INSTALL_TEST(_test_getEdgesDecimal128); #endif INSTALL_TEST(_test_count_leading_zeros); diff --git a/test/test-mc-range-encoding.c b/test/test-mc-range-encoding.c index 4dff6e3d6..3f28db128 100644 --- a/test/test-mc-range-encoding.c +++ b/test/test-mc-range-encoding.c @@ -589,7 +589,7 @@ static void _test_RangeTest_Encode_Double(_mongocrypt_tester_t *tester) { } } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() typedef struct { mc_dec128 value; mc_optional_dec128_t min; @@ -1033,7 +1033,7 @@ void _mongocrypt_tester_install_range_encoding(_mongocrypt_tester_t *tester) { INSTALL_TEST(_test_RangeTest_Encode_Int64); INSTALL_TEST(_test_canUsePrecisionModeDouble); INSTALL_TEST(_test_RangeTest_Encode_Double); -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() INSTALL_TEST(_test_canUsePrecisionModeDecimal); INSTALL_TEST(_test_RangeTest_Encode_Decimal128); #endif diff --git a/test/test-mc-range-mincover.c b/test/test-mc-range-mincover.c index e21fd3eae..afe890bd2 100644 --- a/test/test-mc-range-mincover.c +++ b/test/test-mc-range-mincover.c @@ -68,7 +68,7 @@ typedef struct { const char *expectError; } DoubleTest; -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() typedef struct { mc_dec128 lowerBound; bool includeLowerBound; @@ -148,7 +148,7 @@ static mc_mincover_t *_test_getMincoverDouble_helper(void *tests, size_t idx, mo use_range_v2); } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() static mc_mincover_t *_test_getMincoverDecimal128_helper(void *tests, size_t idx, mongocrypt_status_t *status) { BSON_ASSERT_PARAM(tests); @@ -202,7 +202,7 @@ static const char *_test_expectErrorDouble(void *tests, size_t idx, mongocrypt_s return test->expectError; } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() static const char *_test_expectErrorDecimal128(void *tests, size_t idx, mongocrypt_status_t *status) { BSON_ASSERT_PARAM(tests); BSON_ASSERT_PARAM(status); @@ -238,7 +238,7 @@ static const char *const *_test_expectMincoverDouble(void *tests, size_t idx) { return ((DoubleTest *)tests + idx)->expectMincoverStrings; } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() static const char *const *_test_expectMincoverDecimal128(void *tests, size_t idx) { BSON_ASSERT_PARAM(tests); return ((Decimal128Test *)tests + idx)->expectMincoverStrings; @@ -329,7 +329,7 @@ static void _test_dump_Double(void *tests, size_t idx, mc_mincover_t *got) { TEST_STDERR_PRINTF("mincover got ... end\n"); } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() static void _test_dump_Decimal128(void *tests, size_t idx, mc_mincover_t *got) { BSON_ASSERT_PARAM(tests); Decimal128Test *const test = (Decimal128Test *)tests + idx; @@ -594,7 +594,7 @@ static void _test_getMincoverDouble(_mongocrypt_tester_t *tester) { .dump = _test_dump_Double}); } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() static void _test_getMincoverDecimal128(_mongocrypt_tester_t *tester) { Decimal128Test tests[] = { #include "./data/range-min-cover/mincover_decimal128.cstruct" @@ -614,7 +614,7 @@ void _mongocrypt_tester_install_range_mincover(_mongocrypt_tester_t *tester) { INSTALL_TEST(_test_getMincoverInt32); INSTALL_TEST(_test_getMincoverInt64); INSTALL_TEST(_test_getMincoverDouble); -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() INSTALL_TEST(_test_getMincoverDecimal128); #endif } diff --git a/test/test-mc-rangeopts.c b/test/test-mc-rangeopts.c index db09ad06f..63e2bda70 100644 --- a/test/test-mc-rangeopts.c +++ b/test/test-mc-rangeopts.c @@ -260,7 +260,7 @@ static void test_mc_RangeOpts_to_FLE2RangeInsertSpec(_mongocrypt_tester_t *teste .expectError = "Trim factor (64) must be less than the total number of bits (64) used to represent any " "element in the domain."}, -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() {.desc = "tf bound check passes correctly for decimal with min, max, precision set (tf = 9, 2^9 < domain size " "< 2^10)", .in = RAW_STRING({ diff --git a/test/test-mc-text-search-str-encode.c b/test/test-mc-text-search-str-encode.c index df625e882..b1be1c01b 100644 --- a/test/test-mc-text-search-str-encode.c +++ b/test/test-mc-text-search-str-encode.c @@ -360,21 +360,21 @@ static void test_nofold_substring_case_multiple_mlen(_mongocrypt_tester_t *teste test_nofold_substring_case(tester, str, lb, ub, byte_len + 64, casef, diacf, foldable_codepoints); } -const char *normal_ascii_strings[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", - "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", - "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", - "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; -const char *ascii_diacritics[] = {"^", "`"}; -const char *normal_unicode_strings[] = {"ぁ", "あ", "ぃ", "い", "ぅ", "う", "ぇ", "え", "ぉ", "お", "か", "が", - "き", "ぎ", "く", "け", "Ѐ", "Ё", "Ђ", "Ѓ", "Є", "Ѕ", "І", "Ї", - "Ј", "Љ", "Њ", "Ћ", "Ќ", "Ѝ", "Ў", "Џ", "𓀀", "𓀁", "𓀂", "𓀃", - "𓀄", "𓀅", "𓀆", "𓀇", "𓀈", "𓀉", "𓀊", "𓀋", "𓀌", "𓀍", "𓀎", "𓀏"}; -const char *unicode_diacritics[] = {"̀", "́", "̂", "̃", "̄", "̅", "̆", "̇", "̈", "̉", "̊", "̋", "̌", "̍", "̎", - "̏", "᷄", "᷅", "᷆", "᷇", "᷈", "᷉", "᷊", "᷋", "᷌", "᷍", "᷎", "᷏", "︠", "︡", - "︢", "︣", "︤", "︥", "︦", "︧", "︨", "︩", "︪", "︫", "︬", "︭", "︮", "︯"}; +static const char *normal_ascii_strings[] = { + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", + "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", + "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; +static const char *ascii_diacritics[] = {"^", "`"}; +static const char *normal_unicode_strings[] = {"ぁ", "あ", "ぃ", "い", "ぅ", "う", "ぇ", "え", "ぉ", "お", "か", "が", + "き", "ぎ", "く", "け", "Ѐ", "Ё", "Ђ", "Ѓ", "Є", "Ѕ", "І", "Ї", + "Ј", "Љ", "Њ", "Ћ", "Ќ", "Ѝ", "Ў", "Џ", "𓀀", "𓀁", "𓀂", "𓀃", + "𓀄", "𓀅", "𓀆", "𓀇", "𓀈", "𓀉", "𓀊", "𓀋", "𓀌", "𓀍", "𓀎", "𓀏"}; +static const char *unicode_diacritics[] = {"̀", "́", "̂", "̃", "̄", "̅", "̆", "̇", "̈", "̉", "̊", "̋", "̌", "̍", "̎", + "̏", "᷄", "᷅", "᷆", "᷇", "᷈", "᷉", "᷊", "᷋", "᷌", "᷍", "᷎", "᷏", "︠", "︡", + "︢", "︣", "︤", "︥", "︦", "︧", "︨", "︩", "︪", "︫", "︬", "︭", "︮", "︯"}; // Build a random string which has unfolded_len codepoints, but folds to folded_len codepoints after diacritic folding. -char *build_random_string_to_fold(uint32_t folded_len, uint32_t unfolded_len) { +static char *build_random_string_to_fold(uint32_t folded_len, uint32_t unfolded_len) { // 1/3 to generate all unicode, 1/3 to be half and half, 1/3 to be all ascii. int ascii_ratio = rand() % 3; ASSERT_CMPUINT32(unfolded_len, >=, folded_len); @@ -526,11 +526,11 @@ static void suffix_prefix_run_folding_case(_mongocrypt_tester_t *tester, test_nofold_suffix_prefix_case(tester, long_s, 32, 49, casef, diacf, foldable_codepoints); } -const uint32_t UNFOLDED_CASES[] = {0, 1, 3, 16}; +static const uint32_t UNFOLDED_CASES[] = {0, 1, 3, 16}; // Predefined lengths to test a variety of cases -const uint32_t SHORT_LEN = 9; -const uint32_t MEDIUM_LEN = 16; -const uint32_t LONG_LEN = 27; +static const uint32_t SHORT_LEN = 9; +static const uint32_t MEDIUM_LEN = 16; +static const uint32_t LONG_LEN = 27; static void _test_text_search_str_encode_suffix_prefix(_mongocrypt_tester_t *tester) { unsigned int seed = (unsigned int)time(0); diff --git a/test/test-mongocrypt-assert-match-bson.c b/test/test-mongocrypt-assert-match-bson.c index a20c6ee32..c4b342064 100644 --- a/test/test-mongocrypt-assert-match-bson.c +++ b/test/test-mongocrypt-assert-match-bson.c @@ -78,11 +78,6 @@ bool match_json(const bson_t *doc, const char *json_pattern, ...); -#define ASSERT_MATCH(doc, ...) \ - do { \ - BSON_ASSERT(match_json(doc, false, __FILE__, __LINE__, BSON_FUNC, __VA_ARGS__)); \ - } while (0) - const char *_mongoc_bson_type_to_str(bson_type_t t); static bool get_exists_operator(const bson_value_t *value, bool *exists); @@ -225,7 +220,7 @@ bool match_bson(const bson_t *doc, const bson_t *pattern, bool is_command) { MLIB_ANNOTATE_PRINTF(2, 3) -void match_err(match_ctx_t *ctx, const char *fmt, ...) { +static void match_err(match_ctx_t *ctx, const char *fmt, ...) { va_list args; char *formatted; diff --git a/test/test-mongocrypt-buffer.c b/test/test-mongocrypt-buffer.c index 1945be85d..ad64c7b93 100644 --- a/test/test-mongocrypt-buffer.c +++ b/test/test-mongocrypt-buffer.c @@ -35,7 +35,7 @@ static void _get_bytes(const void *in, char *out, int len) { dest[-1] = '\0'; } -bool assert_excess_bytes_removed(char *key, char *wrapped, char *unwrapped, uint32_t type, bson_value_t *out) { +static bool assert_excess_bytes_removed(char *key, char *wrapped, char *unwrapped, uint32_t type, bson_value_t *out) { _mongocrypt_buffer_t plaintext = {0}; _mongocrypt_marking_t marking = {0}; bson_iter_t iter; diff --git a/test/test-mongocrypt-cache.c b/test/test-mongocrypt-cache.c index db566a1dd..3b7ddcaf9 100644 --- a/test/test-mongocrypt-cache.c +++ b/test/test-mongocrypt-cache.c @@ -18,7 +18,7 @@ #include "mongocrypt-crypto-private.h" #include "test-mongocrypt.h" -void _test_cache(_mongocrypt_tester_t *tester) { +static void _test_cache(_mongocrypt_tester_t *tester) { _mongocrypt_cache_t cache; mongocrypt_status_t *status; bson_t *entry = BCON_NEW("a", "b"), *entry2 = BCON_NEW("c", "d"); diff --git a/test/test-mongocrypt-ciphertext.c b/test/test-mongocrypt-ciphertext.c index 03bed1757..94eb2ccd9 100644 --- a/test/test-mongocrypt-ciphertext.c +++ b/test/test-mongocrypt-ciphertext.c @@ -91,7 +91,7 @@ static void _test_malformed_ciphertext(_mongocrypt_tester_t *tester) { mongocrypt_status_destroy(status); } -void _test_ciphertext_algorithm(_mongocrypt_tester_t *tester) { +static void _test_ciphertext_algorithm(_mongocrypt_tester_t *tester) { mongocrypt_t *crypt; mongocrypt_ctx_t *ctx; mongocrypt_status_t *status; @@ -184,7 +184,7 @@ void _test_ciphertext_algorithm(_mongocrypt_tester_t *tester) { mongocrypt_status_destroy(status); } -void _test_ciphertext_serialize_associated_data(_mongocrypt_tester_t *tester) { +static void _test_ciphertext_serialize_associated_data(_mongocrypt_tester_t *tester) { _mongocrypt_ciphertext_t ciphertext; _mongocrypt_buffer_t serialized; /* Expected associated data is: diff --git a/test/test-mongocrypt-crypto-hooks.c b/test/test-mongocrypt-crypto-hooks.c index a2fdb8f79..b723e1404 100644 --- a/test/test-mongocrypt-crypto-hooks.c +++ b/test/test-mongocrypt-crypto-hooks.c @@ -117,11 +117,11 @@ static bool _mock_aes_256_xxx_decrypt(void *ctx, return true; } -bool _hmac_sha_512(void *ctx, - mongocrypt_binary_t *key, - mongocrypt_binary_t *in, - mongocrypt_binary_t *out, - mongocrypt_status_t *status) { +static bool _hmac_sha_512(void *ctx, + mongocrypt_binary_t *key, + mongocrypt_binary_t *in, + mongocrypt_binary_t *out, + mongocrypt_status_t *status) { _mongocrypt_buffer_t tmp; BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:"))); @@ -141,11 +141,11 @@ bool _hmac_sha_512(void *ctx, return true; } -bool _hmac_sha_256(void *ctx, - mongocrypt_binary_t *key, - mongocrypt_binary_t *in, - mongocrypt_binary_t *out, - mongocrypt_status_t *status) { +static bool _hmac_sha_256(void *ctx, + mongocrypt_binary_t *key, + mongocrypt_binary_t *in, + mongocrypt_binary_t *out, + mongocrypt_status_t *status) { _mongocrypt_buffer_t tmp; BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:"))); @@ -165,7 +165,7 @@ bool _hmac_sha_256(void *ctx, return true; } -bool _sha_256(void *ctx, mongocrypt_binary_t *in, mongocrypt_binary_t *out, mongocrypt_status_t *status) { +static bool _sha_256(void *ctx, mongocrypt_binary_t *in, mongocrypt_binary_t *out, mongocrypt_status_t *status) { _mongocrypt_buffer_t tmp; BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:"))); @@ -184,7 +184,7 @@ bool _sha_256(void *ctx, mongocrypt_binary_t *in, mongocrypt_binary_t *out, mong return true; } -bool _random(void *ctx, mongocrypt_binary_t *out, uint32_t count, mongocrypt_status_t *status) { +static bool _random(void *ctx, mongocrypt_binary_t *out, uint32_t count, mongocrypt_status_t *status) { /* only have 32 bytes of random test data. */ BSON_ASSERT(count <= 96); @@ -204,11 +204,11 @@ bool _random(void *ctx, mongocrypt_binary_t *out, uint32_t count, mongocrypt_sta return true; } -bool _sign_rsaes_pkcs1_v1_5(void *ctx, - mongocrypt_binary_t *key, - mongocrypt_binary_t *in, - mongocrypt_binary_t *out, - mongocrypt_status_t *status) { +static bool _sign_rsaes_pkcs1_v1_5(void *ctx, + mongocrypt_binary_t *key, + mongocrypt_binary_t *in, + mongocrypt_binary_t *out, + mongocrypt_status_t *status) { _mongocrypt_buffer_t tmp; BSON_ASSERT(0 == strncmp("error_on:", (char *)ctx, strlen("error_on:"))); @@ -696,7 +696,7 @@ static bool _aes_256_ecb_encrypt(void *ctx, return _native_crypto_aes_256_ecb_encrypt(args); } -void _test_fle2_crypto_via_ecb_hook(_mongocrypt_tester_t *tester) { +static void _test_fle2_crypto_via_ecb_hook(_mongocrypt_tester_t *tester) { const _mongocrypt_value_encryption_algorithm_t *fle2alg = _mcFLE2Algorithm(); bool ret; _mongocrypt_buffer_t key; diff --git a/test/test-mongocrypt-crypto-std-hooks.c b/test/test-mongocrypt-crypto-std-hooks.c index 85c569c04..f336d67d1 100644 --- a/test/test-mongocrypt-crypto-std-hooks.c +++ b/test/test-mongocrypt-crypto-std-hooks.c @@ -14,6 +14,10 @@ * limitations under the License. */ +#include "test-mongocrypt-crypto-std-hooks.h" + +// + #include #include "test-mongocrypt.h" diff --git a/test/test-mongocrypt-crypto.c b/test/test-mongocrypt-crypto.c index 782715ae8..705fc17c1 100644 --- a/test/test-mongocrypt-crypto.c +++ b/test/test-mongocrypt-crypto.c @@ -283,7 +283,7 @@ typedef struct { const char *expect; } hmac_sha_256_test_t; -void _test_native_crypto_hmac_sha_256(_mongocrypt_tester_t *tester) { +static void _test_native_crypto_hmac_sha_256(_mongocrypt_tester_t *tester) { /* Test data generated with OpenSSL CLI: $ echo -n "test" | openssl dgst -mac hmac -macopt \ hexkey:6bb2664e8d444377d3cd9566c005593b7ed8a35ab8eac9eb5ffa6e426854e5cc \ diff --git a/test/test-mongocrypt-ctx-decrypt.c b/test/test-mongocrypt-ctx-decrypt.c index d3ea3c3f9..10ef09f72 100644 --- a/test/test-mongocrypt-ctx-decrypt.c +++ b/test/test-mongocrypt-ctx-decrypt.c @@ -123,7 +123,7 @@ static void _test_decrypt_ready(_mongocrypt_tester_t *tester) { } /* Test with empty AWS credentials. */ -void _test_decrypt_empty_aws(_mongocrypt_tester_t *tester) { +static void _test_decrypt_empty_aws(_mongocrypt_tester_t *tester) { mongocrypt_t *crypt; mongocrypt_ctx_t *ctx; diff --git a/test/test-mongocrypt-ctx-encrypt.c b/test/test-mongocrypt-ctx-encrypt.c index 7ab8d201f..f4f3a78dd 100644 --- a/test/test-mongocrypt-ctx-encrypt.c +++ b/test/test-mongocrypt-ctx-encrypt.c @@ -1087,7 +1087,7 @@ static void _test_explicit_encryption(_mongocrypt_tester_t *tester) { } /* Test with empty AWS credentials. */ -void _test_encrypt_empty_aws(_mongocrypt_tester_t *tester) { +static void _test_encrypt_empty_aws(_mongocrypt_tester_t *tester) { mongocrypt_t *crypt; mongocrypt_ctx_t *ctx; @@ -1810,7 +1810,7 @@ static void _test_encrypt_fle2_insert_range_payload_double_precision(_mongocrypt #undef RNG_DATA -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() #include "./data/fle2-insert-range/decimal128/RNG_DATA.h" static void _test_encrypt_fle2_insert_range_payload_decimal128(_mongocrypt_tester_t *tester) { @@ -1862,7 +1862,7 @@ static void _test_encrypt_fle2_find_range_payload_double_precision(_mongocrypt_t TEST_ENCRYPT_FLE2_ENCRYPTION_PLACEHOLDER(tester, "fle2-find-range/double-precision-v2", &source, NULL) } -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() // FLE2FindRangePayload only uses deterministic token generation. static void _test_encrypt_fle2_find_range_payload_decimal128(_mongocrypt_tester_t *tester) { _test_rng_data_source source = {{0}}; @@ -5866,7 +5866,7 @@ void _mongocrypt_tester_install_ctx_encrypt(_mongocrypt_tester_t *tester) { INSTALL_TEST(_test_encrypt_fle2_insert_range_payload_date); INSTALL_TEST(_test_encrypt_fle2_insert_range_payload_double); INSTALL_TEST(_test_encrypt_fle2_insert_range_payload_double_precision); -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() INSTALL_TEST(_test_encrypt_fle2_insert_range_payload_decimal128); INSTALL_TEST(_test_encrypt_fle2_insert_range_payload_decimal128_precision); #endif @@ -5875,7 +5875,7 @@ void _mongocrypt_tester_install_ctx_encrypt(_mongocrypt_tester_t *tester) { INSTALL_TEST(_test_encrypt_fle2_find_range_payload_date); INSTALL_TEST(_test_encrypt_fle2_find_range_payload_double); INSTALL_TEST(_test_encrypt_fle2_find_range_payload_double_precision); -#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT +#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT() INSTALL_TEST(_test_encrypt_fle2_find_range_payload_decimal128); INSTALL_TEST(_test_encrypt_fle2_find_range_payload_decimal128_precision); #endif diff --git a/test/test-mongocrypt-endpoint.c b/test/test-mongocrypt-endpoint.c index d03f72268..474a1ec83 100644 --- a/test/test-mongocrypt-endpoint.c +++ b/test/test-mongocrypt-endpoint.c @@ -18,7 +18,7 @@ #include "test-mongocrypt.h" -void _test_mongocrypt_endpoint(_mongocrypt_tester_t *tester) { +static void _test_mongocrypt_endpoint(_mongocrypt_tester_t *tester) { _mongocrypt_endpoint_t *endpoint; mongocrypt_status_t *status; _mongocrypt_endpoint_parse_opts_t opts; diff --git a/test/test-mongocrypt-kek.c b/test/test-mongocrypt-kek.c index b0a4fdebe..f4da6bb25 100644 --- a/test/test-mongocrypt-kek.c +++ b/test/test-mongocrypt-kek.c @@ -81,7 +81,7 @@ static void _run_one_test(_mongocrypt_tester_t *tester, bson_t *test) { mongocrypt_status_destroy(status); } -void test_mongocrypt_kek_parsing(_mongocrypt_tester_t *tester) { +static void test_mongocrypt_kek_parsing(_mongocrypt_tester_t *tester) { bson_t test_file; bson_iter_t iter; diff --git a/test/test-mongocrypt-key-cache.c b/test/test-mongocrypt-key-cache.c index a92ac9597..fa14a5361 100644 --- a/test/test-mongocrypt-key-cache.c +++ b/test/test-mongocrypt-key-cache.c @@ -30,7 +30,7 @@ typedef struct { /* The JSON spec tests refer to key ids by a shorthand integer. * This function maps that integer to a UUID buffer. */ -void lookup_key_id(uint32_t index, _mongocrypt_buffer_t *buf) { +static void lookup_key_id(uint32_t index, _mongocrypt_buffer_t *buf) { const char *key_ids[] = {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"}; @@ -44,10 +44,8 @@ void lookup_key_id(uint32_t index, _mongocrypt_buffer_t *buf) { /* Generate a realistic key document given a @key_description, which contains an * _id * and possible keyAltNames. key_out and key_doc_out are NULLable outputs. */ -void gen_key(_mongocrypt_tester_t *tester, - bson_t *key_description, - bson_t *key_out, - _mongocrypt_key_doc_t *key_doc_out) { +static void +gen_key(_mongocrypt_tester_t *tester, bson_t *key_description, bson_t *key_out, _mongocrypt_key_doc_t *key_doc_out) { bson_iter_t iter; _mongocrypt_buffer_t key_material; _mongocrypt_buffer_t key_id; diff --git a/test/test-mongocrypt-log.c b/test/test-mongocrypt-log.c index bef2be5be..78b54d80d 100644 --- a/test/test-mongocrypt-log.c +++ b/test/test-mongocrypt-log.c @@ -88,10 +88,10 @@ static void _test_trace_log(_mongocrypt_tester_t *tester) { #if defined(__GLIBC__) || defined(__APPLE__) static void _test_no_log(_mongocrypt_tester_t *tester) { - const int buffer_size = BUFSIZ; mongocrypt_t *crypt; mongocrypt_status_t *status; - char captured_logs[buffer_size]; + char captured_logs[BUFSIZ]; + const int buffer_size = sizeof(captured_logs); int saved_stdout = dup(1); /* Redirect stdout to /dev/null and capture output in a buffer diff --git a/test/test-unicode-fold.c b/test/test-unicode-fold.c index d0f78d172..4f137b123 100644 --- a/test/test-unicode-fold.c +++ b/test/test-unicode-fold.c @@ -49,7 +49,7 @@ _both_len, \ input, \ _input_len, \ - kUnicodeFoldToLower | kUnicodeFoldRemoveDiacritics); \ + (unicode_fold_options_t)(kUnicodeFoldToLower | kUnicodeFoldRemoveDiacritics)); \ } while (0) static void test_unicode_fold(_mongocrypt_tester_t *tester) { @@ -85,7 +85,11 @@ static void test_unicode_fold(_mongocrypt_tester_t *tester) { TEST_UNICODE_FOLD_ALL_CASES("Cafe\xcc\x81", "cafe\xcc\x81", "Cafe", "cafe"); TEST_UNICODE_FOLD_ALL_CASES("CafE\xcc\x81", "cafe\xcc\x81", "CafE", "cafe"); // Test string with null bytes - TEST_UNICODE_FOLD("fo\0bar", 6, "fo\0bar", 6, kUnicodeFoldToLower | kUnicodeFoldRemoveDiacritics); + TEST_UNICODE_FOLD("fo\0bar", + 6, + "fo\0bar", + 6, + (unicode_fold_options_t)(kUnicodeFoldToLower | kUnicodeFoldRemoveDiacritics)); // Test strings with folded representations longer in bytes than the input TEST_UNICODE_FOLD("\xe2\xb1\xa6", 3, "\xc8\xbe", 2, kUnicodeFoldToLower); TEST_UNICODE_FOLD("\xf0\xa4\x8b\xae", 4, "\xef\xa9\xac", 3, kUnicodeFoldRemoveDiacritics); diff --git a/test/util/csfle.c b/test/util/csfle.c index bf12c899b..08fd52298 100644 --- a/test/util/csfle.c +++ b/test/util/csfle.c @@ -23,7 +23,7 @@ #include "util.h" -const char *help_text = "" +static const char *help_text = "" #include "HELP.autogen" ; diff --git a/test/util/util.c b/test/util/util.c index 899383042..e94df3280 100644 --- a/test/util/util.c +++ b/test/util/util.c @@ -111,7 +111,7 @@ static void _status_to_error(mongocrypt_status_t *status, bson_error_t *error) { * Returns true if ok, and does not modify @error. * Returns false if error, and sets @error. */ -bool _test_ctx_check_error(mongocrypt_ctx_t *ctx, bson_error_t *error, bool error_expected) { +static bool _test_ctx_check_error(mongocrypt_ctx_t *ctx, bson_error_t *error, bool error_expected) { mongocrypt_status_t *status; status = mongocrypt_status_new(); @@ -131,7 +131,7 @@ bool _test_ctx_check_error(mongocrypt_ctx_t *ctx, bson_error_t *error, bool erro return true; } -bool _test_kms_ctx_check_error(mongocrypt_kms_ctx_t *kms_ctx, bson_error_t *error, bool error_expected) { +static bool _test_kms_ctx_check_error(mongocrypt_kms_ctx_t *kms_ctx, bson_error_t *error, bool error_expected) { mongocrypt_status_t *status; status = mongocrypt_status_new(); @@ -659,7 +659,7 @@ static bool _state_ready(_state_machine_t *state_machine, bson_t *result, bson_e return ret; } -const char *_state_string(mongocrypt_ctx_state_t state) { +static const char *_state_string(mongocrypt_ctx_state_t state) { switch (state) { case MONGOCRYPT_CTX_ERROR: return "MONGOCRYPT_CTX_ERROR"; case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB: return "MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB"; @@ -732,7 +732,7 @@ bool _csfle_state_machine_run(_state_machine_t *state_machine, bson_t *result, b goto fail; } break; - case MONGOCRYPT_CTX_DONE: goto success; break; + case MONGOCRYPT_CTX_DONE: goto success; } }