Skip to content

Reduce Warnings - Miscellaneous GCC and Clang Warnings (CDRIVER-5305) #1543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/common-md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ bson_md5_process (bson_md5_t *md5, const uint8_t *data)
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
if (!((data - (const uint8_t *) 0) & 3)) {
if (!(((uintptr_t) data) & 3u)) {
/* data are properly aligned */
#ifdef __clang__
#pragma clang diagnostic push
Expand Down
3 changes: 2 additions & 1 deletion src/libbson/examples/bson-streaming-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
int
bson_streaming_remote_open (const char *hostname, const char *port)
{
int error, sock;
int error = 0;
int sock = 0;
struct addrinfo hints, *ptr, *server_list;

/*
Expand Down
2 changes: 1 addition & 1 deletion src/libbson/examples/creating.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <bson/bson.h>

int
main (int argc, const char **argv)
main (void)
{
{
// bson_append_document_begin example ... begin
Expand Down
16 changes: 10 additions & 6 deletions src/libbson/src/bson/bson-decimal128.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
#define BSON_DECIMAL128_MAX_DIGITS 34

#define BSON_DECIMAL128_SET_NAN(dec) \
do { \
if (1) { \
(dec).high = 0x7c00000000000000ull; \
(dec).low = 0; \
} while (0);
} else \
(void) 0
#define BSON_DECIMAL128_SET_INF(dec, isneg) \
do { \
if (1) { \
(dec).high = 0x7800000000000000ull + 0x8000000000000000ull * (isneg); \
(dec).low = 0; \
} while (0);
} else \
(void) 0

/**
* _bson_uint128_t:
Expand Down Expand Up @@ -163,8 +165,10 @@ bson_decimal128_to_string (const bson_decimal128_t *dec, /* IN */
*(str_out++) = '-';
}

low = (uint32_t) dec->low, midl = (uint32_t) (dec->low >> 32),
midh = (uint32_t) dec->high, high = (uint32_t) (dec->high >> 32);
low = (uint32_t) dec->low;
midl = (uint32_t) (dec->low >> 32);
midh = (uint32_t) dec->high;
high = (uint32_t) (dec->high >> 32);

/* Decode combination field and exponent */
combination = (high >> 26) & COMBINATION_MASK;
Expand Down
8 changes: 5 additions & 3 deletions src/libbson/src/bson/bson-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,16 @@ _noop (void)
do { \
STACK_POP_DOC (_noop ()); \
bson->code_data.in_scope = false; \
} while (0);
} while (0)
#define STACK_POP_DBPOINTER STACK_POP_DOC (_noop ())
#define BASIC_CB_PREAMBLE \
const char *key; \
size_t len; \
bson_json_reader_bson_t *bson = &reader->bson; \
_bson_json_read_fixup_key (bson); \
key = bson->key; \
len = bson->key_buf.len;
len = bson->key_buf.len; \
(void) 0
#define BASIC_CB_BAIL_IF_NOT_NORMAL(_type) \
if (bson->read_state != BSON_JSON_REGULAR) { \
_bson_json_read_set_error (reader, \
Expand All @@ -369,7 +370,8 @@ _noop (void)
(_type), \
read_state_names[bson->read_state]); \
return; \
}
} else \
(void) 0
#define HANDLE_OPTION(_selection_statement, _key, _type, _state) \
_selection_statement (len == strlen (_key) && \
strncmp ((const char *) val, (_key), len) == 0) \
Expand Down
4 changes: 2 additions & 2 deletions src/libbson/tests/test-bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ test_bson_append_array (void)
static void
test_bson_append_binary (void)
{
const static uint8_t binary[] = {'1', '2', '3', '4'};
static const uint8_t binary[] = {'1', '2', '3', '4'};
bson_t *b;
bson_t *b2;

Expand All @@ -307,7 +307,7 @@ test_bson_append_binary (void)
static void
test_bson_append_binary_deprecated (void)
{
const static uint8_t binary[] = {'1', '2', '3', '4'};
static const uint8_t binary[] = {'1', '2', '3', '4'};
bson_t *b;
bson_t *b2;

Expand Down
2 changes: 1 addition & 1 deletion src/libbson/tests/test-decimal128.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
do { \
(dec).high = (h); \
(dec).low = (l); \
} while (0);
} while (0)


static void
Expand Down
8 changes: 4 additions & 4 deletions src/libbson/tests/test-iso8601.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "bson/bson-iso8601-private.h"
#include "TestSuite.h"

#define IS_TIME_T_SMALL (sizeof (time_t) == sizeof (int32_t))
static const bool is_time_t_small = (sizeof (time_t) == sizeof (int32_t));

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

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

if (!IS_TIME_T_SMALL) {
if (!is_time_t_small) {
test_date_io ("2058-02-20T13:29:11.100-0500",
"2058-02-20T18:29:11.100Z",
2781455351100ULL);
Expand Down Expand Up @@ -291,7 +291,7 @@ test_bson_iso8601_leap_year (void)
test_date_rt ("2032-02-29T00:00:00Z", 1961625600000ULL);
test_date_rt ("2036-02-29T00:00:00Z", 2087856000000ULL);

if (!IS_TIME_T_SMALL) {
if (!is_time_t_small) {
test_date_rt ("2040-02-29T00:00:00Z", 2214086400000ULL);
test_date_rt ("2044-02-29T00:00:00Z", 2340316800000ULL);
test_date_rt ("2048-02-29T00:00:00Z", 2466547200000ULL);
Expand Down
2 changes: 1 addition & 1 deletion src/libbson/tests/test-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -2951,7 +2951,7 @@ _test_json_produces_multiple (const char *json_in, int err_expected, ...)
}

#define TEST_JSON_PRODUCES_MULTIPLE(_json, _has_err, ...) \
_test_json_produces_multiple (_json, _has_err, __VA_ARGS__, NULL);
_test_json_produces_multiple (_json, _has_err, __VA_ARGS__, NULL)

static void
test_bson_as_json_multi_object (void)
Expand Down
25 changes: 12 additions & 13 deletions src/libmongoc/examples/basic_aggregation/map-reduce-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ bool
map_reduce_basic (mongoc_database_t *database)
{
bson_t reply;
bson_t *command;
bool res;
bool res = false;
bson_error_t error;
mongoc_cursor_t *cursor;
const bson_t *doc;
mongoc_cursor_t *cursor = NULL;

bool query_done = false;

const char *out_collection_name = "outCollection";
mongoc_collection_t *out_collection;
mongoc_collection_t *out_collection = NULL;

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

/* Other arguments can also be specified here, like "query" or
"limit" and so on */
command = BCON_NEW ("mapReduce",
BCON_UTF8 (COLLECTION_NAME),
"map",
BCON_CODE (MAPPER),
"reduce",
BCON_CODE (REDUCER),
"out",
BCON_UTF8 (out_collection_name));
bson_t *const command = BCON_NEW ("mapReduce",
BCON_UTF8 (COLLECTION_NAME),
"map",
BCON_CODE (MAPPER),
"reduce",
BCON_CODE (REDUCER),
"out",
BCON_UTF8 (out_collection_name));
res =
mongoc_database_command_simple (database, command, NULL, &reply, &error);

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

/* Do something with the results */
const bson_t *doc = NULL;
while (mongoc_cursor_next (cursor, &doc)) {
print_res (doc);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/examples/example-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ main (int argc, char *argv[])
if (!mongoc_client_session_append (client_session, find_opts, &error)) {
fprintf (stderr, "Could not add session to opts: %s\n", error.message);
goto done;
};
}

/* read from secondary. since we're in a causally consistent session, the
* data is guaranteed to reflect the update we did on the primary. the query
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/examples/tutorial/appending.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <bson/bson.h>

int
main (int argc, char *argv[])
main (void)
{
struct tm born = {0};
struct tm died = {0};
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/examples/tutorial/executing.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdio.h>

int
main (int argc, char *argv[])
main (void)
{
mongoc_client_t *client;
bson_error_t error;
Expand Down
13 changes: 9 additions & 4 deletions src/libmongoc/src/mongoc/mongoc-aggregate.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ _make_agg_cmd (const char *ns,
then (cstr (dot + 1)),
// Otherwise just an integer 1:
else (int32 (1)))));
if ((error_hint = "append-aggregate", error = bsonBuildError)) {
if ((error = bsonBuildError)) {
error_hint = "append-aggregate";
goto fail;
}

Expand All @@ -124,7 +125,8 @@ _make_agg_cmd (const char *ns,
else ( // We did not find a "pipeline" array. copy the pipeline as
// an array into the command
append (*command, kv ("pipeline", array (insert (*pipeline, true))))));
if ((error_hint = "append-pipeline", error = bsonParseError)) {
if ((error = bsonParseError)) {
error_hint = "append-pipeline";
goto fail;
}

Expand All @@ -141,7 +143,9 @@ _make_agg_cmd (const char *ns,
// writing aggregate command.
parse (find (key ("$out", "$merge"),
do (has_write_key = true)))))));
if ((error_hint = "parse-pipeline", error = bsonParseError)) {

if ((error = bsonParseError)) {
error_hint = "parse-pipeline";
goto fail;
}

Expand All @@ -154,7 +158,8 @@ _make_agg_cmd (const char *ns,
doc (if (opts->batchSize_is_set &&
!(has_write_key && opts->batchSize == 0),
then (kv ("batchSize", int32 (opts->batchSize)))))));
if ((error_hint = "build-cursor", error = bsonBuildError)) {
if ((error = bsonBuildError)) {
error_hint = "build-cursor";
goto fail;
}

Expand Down
22 changes: 11 additions & 11 deletions src/libmongoc/src/mongoc/mongoc-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ mongoc_async_run (mongoc_async_t *async)

DL_FOREACH_SAFE (async->cmds, acmd, tmp)
{
bool remove_cmd = false;
mongoc_async_cmd_result_t result;

/* check if an initiated cmd has passed the connection timeout. */
if (acmd->state != MONGOC_ASYNC_CMD_INITIATE &&
now > acmd->connect_started + acmd->timeout_msec * 1000) {
Expand All @@ -182,15 +179,18 @@ mongoc_async_run (mongoc_async_t *async)
? "connection timeout"
: "socket timeout");

remove_cmd = true;
result = MONGOC_ASYNC_CMD_TIMEOUT;
} else if (acmd->state == MONGOC_ASYNC_CMD_CANCELED_STATE) {
remove_cmd = true;
result = MONGOC_ASYNC_CMD_ERROR;
}
acmd->cb (acmd,
MONGOC_ASYNC_CMD_TIMEOUT,
NULL,
(now - acmd->connect_started) / 1000);

if (remove_cmd) {
acmd->cb (acmd, result, NULL, (now - acmd->connect_started) / 1000);
/* Remove acmd from the async->cmds doubly-linked list */
mongoc_async_cmd_destroy (acmd);
} else if (acmd->state == MONGOC_ASYNC_CMD_CANCELED_STATE) {
acmd->cb (acmd,
MONGOC_ASYNC_CMD_ERROR,
NULL,
(now - acmd->connect_started) / 1000);

/* Remove acmd from the async->cmds doubly-linked list */
mongoc_async_cmd_destroy (acmd);
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/src/mongoc/mongoc-change-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
bson_set_error (&stream->err, \
MONGOC_ERROR_CURSOR, \
MONGOC_ERROR_BSON, \
"Could not set " _str);
"Could not set " _str)

/* the caller knows either a client or server error has occurred.
* `reply` contains the server reply or an empty document. */
Expand Down
1 change: 0 additions & 1 deletion src/libmongoc/src/mongoc/mongoc-client-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,6 @@ mongoc_client_session_get_transaction_state (
MONGOC_ERROR ("invalid state %d when getting transaction state",
(int) session->txn.state);
abort ();
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/src/mongoc/mongoc-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ _mongoc_client_command_with_stream (mongoc_client_t *client,
if (!mongoc_cmd_parts_assemble (parts, server_stream, error)) {
_mongoc_bson_init_if_set (reply);
return false;
};
}

if (parts->is_retryable_write) {
RETURN (_mongoc_client_retryable_write_command_with_stream (
Expand Down
7 changes: 0 additions & 7 deletions src/libmongoc/src/mongoc/mongoc-compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,20 @@ mongoc_compressor_max_compressed_length (int32_t compressor_id, size_t len)
#ifdef MONGOC_ENABLE_COMPRESSION_SNAPPY
case MONGOC_COMPRESSOR_SNAPPY_ID:
return snappy_max_compressed_length (len);
break;
#endif

#ifdef MONGOC_ENABLE_COMPRESSION_ZLIB
case MONGOC_COMPRESSOR_ZLIB_ID:
BSON_ASSERT (bson_in_range_unsigned (unsigned_long, len));
return compressBound ((unsigned long) len);
break;
#endif

#ifdef MONGOC_ENABLE_COMPRESSION_ZSTD
case MONGOC_COMPRESSOR_ZSTD_ID:
return ZSTD_compressBound (len);
break;
#endif
case MONGOC_COMPRESSOR_NOOP_ID:
return len;
break;
default:
return 0;
}
Expand Down Expand Up @@ -169,7 +165,6 @@ mongoc_uncompress (int32_t compressor_id,
"compression is not compiled in");
return false;
#endif
break;
}

case MONGOC_COMPRESSOR_ZLIB_ID: {
Expand All @@ -186,7 +181,6 @@ mongoc_uncompress (int32_t compressor_id,
"compression is not compiled in");
return false;
#endif
break;
}

case MONGOC_COMPRESSOR_ZSTD_ID: {
Expand All @@ -208,7 +202,6 @@ mongoc_uncompress (int32_t compressor_id,
"compression is not compiled in");
return false;
#endif
break;
}
case MONGOC_COMPRESSOR_NOOP_ID:
memcpy (uncompressed, compressed, compressed_len);
Expand Down
Loading