Skip to content

Commit

Permalink
MONGOCRYPT-783 address miscellaneous warnings (#975)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
eramongodb authored Feb 28, 2025
1 parent 7d799f5 commit fd8eef3
Show file tree
Hide file tree
Showing 68 changed files with 259 additions and 217 deletions.
5 changes: 5 additions & 0 deletions kms-message/src/hexlify.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

#include "hexlify.h"

//

#include "kms_message_private.h"

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion kms-message/src/kms_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
10 changes: 2 additions & 8 deletions kms-message/src/kms_request_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <stdlib.h>
#include <limits.h> /* 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)
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion kms-message/src/kms_response_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion kms-message/src/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@
* https://github.com/freebsd/freebsd/blob/e7c6cef9514d3bb1f14a30a5ee871231523e43db/lib/libc/stdlib/merge.c
*/

#include "sort.h"

//

#include <stddef.h>

/*
* This is to avoid out-of-bounds addresses in sorting the
* last 4 elements.
*/

typedef int (*cmp_t) (const void *, const void *);
#define CMP(x, y) cmp (x, y)
#define swap(a, b) \
{ \
Expand Down
2 changes: 2 additions & 0 deletions kms-message/src/sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

#include <stddef.h>

typedef int (*cmp_t) (const void *, const void *);

void
Expand Down
9 changes: 8 additions & 1 deletion kms-message/test/test_kmip_reader_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions kms-message/test/test_kms_kmip_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions kms-message/test/test_kms_kmip_response.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions kms-message/test/test_kms_kmip_response_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
Loading

0 comments on commit fd8eef3

Please sign in to comment.