Skip to content

Commit f0ee150

Browse files
authored
Reduce Warnings - Code Consistency and Quality Improvements (#1543)
CDRIVER-5305 - Address the following warnings: * -Wcast-function-type * -Wcomma * -Wconditional-uninitialized * -Wextra-semi-stmt * -Wnull-pointer-subtraction * -Wold-style-declaration * -Wunreachable-code * -Wunused-parameter
1 parent 08fdb59 commit f0ee150

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+264
-255
lines changed

src/common/common-md5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bson_md5_process (bson_md5_t *md5, const uint8_t *data)
169169
* On little-endian machines, we can process properly aligned
170170
* data without copying it.
171171
*/
172-
if (!((data - (const uint8_t *) 0) & 3)) {
172+
if (!(((uintptr_t) data) & 3u)) {
173173
/* data are properly aligned */
174174
#ifdef __clang__
175175
#pragma clang diagnostic push

src/libbson/examples/bson-streaming-reader.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
int
5353
bson_streaming_remote_open (const char *hostname, const char *port)
5454
{
55-
int error, sock;
55+
int error = 0;
56+
int sock = 0;
5657
struct addrinfo hints, *ptr, *server_list;
5758

5859
/*

src/libbson/examples/creating.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <bson/bson.h>
1818

1919
int
20-
main (int argc, const char **argv)
20+
main (void)
2121
{
2222
{
2323
// bson_append_document_begin example ... begin

src/libbson/src/bson/bson-decimal128.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@
3232
#define BSON_DECIMAL128_MAX_DIGITS 34
3333

3434
#define BSON_DECIMAL128_SET_NAN(dec) \
35-
do { \
35+
if (1) { \
3636
(dec).high = 0x7c00000000000000ull; \
3737
(dec).low = 0; \
38-
} while (0);
38+
} else \
39+
(void) 0
3940
#define BSON_DECIMAL128_SET_INF(dec, isneg) \
40-
do { \
41+
if (1) { \
4142
(dec).high = 0x7800000000000000ull + 0x8000000000000000ull * (isneg); \
4243
(dec).low = 0; \
43-
} while (0);
44+
} else \
45+
(void) 0
4446

4547
/**
4648
* _bson_uint128_t:
@@ -163,8 +165,10 @@ bson_decimal128_to_string (const bson_decimal128_t *dec, /* IN */
163165
*(str_out++) = '-';
164166
}
165167

166-
low = (uint32_t) dec->low, midl = (uint32_t) (dec->low >> 32),
167-
midh = (uint32_t) dec->high, high = (uint32_t) (dec->high >> 32);
168+
low = (uint32_t) dec->low;
169+
midl = (uint32_t) (dec->low >> 32);
170+
midh = (uint32_t) dec->high;
171+
high = (uint32_t) (dec->high >> 32);
168172

169173
/* Decode combination field and exponent */
170174
combination = (high >> 26) & COMBINATION_MASK;

src/libbson/src/bson/bson-json.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,16 @@ _noop (void)
347347
do { \
348348
STACK_POP_DOC (_noop ()); \
349349
bson->code_data.in_scope = false; \
350-
} while (0);
350+
} while (0)
351351
#define STACK_POP_DBPOINTER STACK_POP_DOC (_noop ())
352352
#define BASIC_CB_PREAMBLE \
353353
const char *key; \
354354
size_t len; \
355355
bson_json_reader_bson_t *bson = &reader->bson; \
356356
_bson_json_read_fixup_key (bson); \
357357
key = bson->key; \
358-
len = bson->key_buf.len;
358+
len = bson->key_buf.len; \
359+
(void) 0
359360
#define BASIC_CB_BAIL_IF_NOT_NORMAL(_type) \
360361
if (bson->read_state != BSON_JSON_REGULAR) { \
361362
_bson_json_read_set_error (reader, \
@@ -369,7 +370,8 @@ _noop (void)
369370
(_type), \
370371
read_state_names[bson->read_state]); \
371372
return; \
372-
}
373+
} else \
374+
(void) 0
373375
#define HANDLE_OPTION(_selection_statement, _key, _type, _state) \
374376
_selection_statement (len == strlen (_key) && \
375377
strncmp ((const char *) val, (_key), len) == 0) \

src/libbson/tests/test-bson.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ test_bson_append_array (void)
290290
static void
291291
test_bson_append_binary (void)
292292
{
293-
const static uint8_t binary[] = {'1', '2', '3', '4'};
293+
static const uint8_t binary[] = {'1', '2', '3', '4'};
294294
bson_t *b;
295295
bson_t *b2;
296296

@@ -307,7 +307,7 @@ test_bson_append_binary (void)
307307
static void
308308
test_bson_append_binary_deprecated (void)
309309
{
310-
const static uint8_t binary[] = {'1', '2', '3', '4'};
310+
static const uint8_t binary[] = {'1', '2', '3', '4'};
311311
bson_t *b;
312312
bson_t *b2;
313313

src/libbson/tests/test-decimal128.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
do { \
3838
(dec).high = (h); \
3939
(dec).low = (l); \
40-
} while (0);
40+
} while (0)
4141

4242

4343
static void

src/libbson/tests/test-iso8601.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "bson/bson-iso8601-private.h"
44
#include "TestSuite.h"
55

6-
#define IS_TIME_T_SMALL (sizeof (time_t) == sizeof (int32_t))
6+
static const bool is_time_t_small = (sizeof (time_t) == sizeof (int32_t));
77

88
static void
99
test_date (const char *str, int64_t millis)
@@ -91,7 +91,7 @@ test_bson_iso8601_utc (void)
9191
test_date_rt ("1970-06-30T01:06:40.981Z", 15556000981ULL);
9292
test_date ("1970-01-01T00:00:00.000+0100", -3600LL * 1000);
9393

94-
if (!IS_TIME_T_SMALL) {
94+
if (!is_time_t_small) {
9595
test_date_rt ("2058-02-20T18:29:11.100Z", 2781455351100ULL);
9696
test_date ("3001-01-01T08:00:00.000Z", 32535244800000ULL);
9797
}
@@ -134,7 +134,7 @@ test_bson_iso8601_local (void)
134134
15556000981ULL);
135135
test_date_io ("1969-12-31T16:00:00.000-0800", "1970-01-01T00:00:00Z", 0ULL);
136136

137-
if (!IS_TIME_T_SMALL) {
137+
if (!is_time_t_small) {
138138
test_date_io ("2058-02-20T13:29:11.100-0500",
139139
"2058-02-20T18:29:11.100Z",
140140
2781455351100ULL);
@@ -291,7 +291,7 @@ test_bson_iso8601_leap_year (void)
291291
test_date_rt ("2032-02-29T00:00:00Z", 1961625600000ULL);
292292
test_date_rt ("2036-02-29T00:00:00Z", 2087856000000ULL);
293293

294-
if (!IS_TIME_T_SMALL) {
294+
if (!is_time_t_small) {
295295
test_date_rt ("2040-02-29T00:00:00Z", 2214086400000ULL);
296296
test_date_rt ("2044-02-29T00:00:00Z", 2340316800000ULL);
297297
test_date_rt ("2048-02-29T00:00:00Z", 2466547200000ULL);

src/libbson/tests/test-json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,7 @@ _test_json_produces_multiple (const char *json_in, int err_expected, ...)
29512951
}
29522952

29532953
#define TEST_JSON_PRODUCES_MULTIPLE(_json, _has_err, ...) \
2954-
_test_json_produces_multiple (_json, _has_err, __VA_ARGS__, NULL);
2954+
_test_json_produces_multiple (_json, _has_err, __VA_ARGS__, NULL)
29552955

29562956
static void
29572957
test_bson_as_json_multi_object (void)

src/libmongoc/examples/basic_aggregation/map-reduce-basic.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ bool
22
map_reduce_basic (mongoc_database_t *database)
33
{
44
bson_t reply;
5-
bson_t *command;
6-
bool res;
5+
bool res = false;
76
bson_error_t error;
8-
mongoc_cursor_t *cursor;
9-
const bson_t *doc;
7+
mongoc_cursor_t *cursor = NULL;
108

119
bool query_done = false;
1210

1311
const char *out_collection_name = "outCollection";
14-
mongoc_collection_t *out_collection;
12+
mongoc_collection_t *out_collection = NULL;
1513

1614
/* Empty find query */
1715
bson_t find_query = BSON_INITIALIZER;
@@ -20,14 +18,14 @@ map_reduce_basic (mongoc_database_t *database)
2018

2119
/* Other arguments can also be specified here, like "query" or
2220
"limit" and so on */
23-
command = BCON_NEW ("mapReduce",
24-
BCON_UTF8 (COLLECTION_NAME),
25-
"map",
26-
BCON_CODE (MAPPER),
27-
"reduce",
28-
BCON_CODE (REDUCER),
29-
"out",
30-
BCON_UTF8 (out_collection_name));
21+
bson_t *const command = BCON_NEW ("mapReduce",
22+
BCON_UTF8 (COLLECTION_NAME),
23+
"map",
24+
BCON_CODE (MAPPER),
25+
"reduce",
26+
BCON_CODE (REDUCER),
27+
"out",
28+
BCON_UTF8 (out_collection_name));
3129
res =
3230
mongoc_database_command_simple (database, command, NULL, &reply, &error);
3331

@@ -47,6 +45,7 @@ map_reduce_basic (mongoc_database_t *database)
4745
query_done = true;
4846

4947
/* Do something with the results */
48+
const bson_t *doc = NULL;
5049
while (mongoc_cursor_next (cursor, &doc)) {
5150
print_res (doc);
5251
}

0 commit comments

Comments
 (0)