Skip to content

Commit a35d672

Browse files
authored
Reducing Warnings - Unused Parameters (#1065)
* Format source files * Add BSON_UNUSED macro * Address -Wunused-parameter warnings * Use BSON_UNUSED instead of asserting with -Wtype-limits warning
1 parent 3ed55ed commit a35d672

File tree

117 files changed

+1332
-255
lines changed

Some content is hidden

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

117 files changed

+1332
-255
lines changed

src/libbson/examples/bcon-col-view.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ col_view_create (const char *stub, ...)
7777
}
7878

7979
int
80-
main (int argc, char *argv[])
80+
main (void)
8181
{
8282
bson_t *bson;
8383
char *json;

src/libbson/examples/bson-check-depth.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ _check_depth_document (const bson_iter_t *iter,
5454
check_depth_t *state = (check_depth_t *) data;
5555
bson_iter_t child;
5656

57+
BSON_UNUSED (iter);
58+
BSON_UNUSED (key);
59+
5760
if (!bson_iter_init (&child, v_document)) {
5861
fprintf (stderr, "corrupt\n");
5962
return true; /* cancel */

src/libbson/examples/bson-metrics.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ bson_metrics_visit_utf8 (const bson_iter_t *iter,
107107
void *data)
108108
{
109109
bson_metrics_state_t *s = data;
110+
111+
BSON_UNUSED (iter);
112+
BSON_UNUSED (key);
113+
BSON_UNUSED (v_utf8);
114+
110115
s->utf8_size_tally += v_utf8_len;
111116

112117
return false;
@@ -160,6 +165,9 @@ bson_metrics_visit_document (const bson_iter_t *iter,
160165
bson_metrics_state_t *s = data;
161166
bson_iter_t child;
162167

168+
BSON_UNUSED (iter);
169+
BSON_UNUSED (key);
170+
163171
if (s->depth >= MAX_RECURSION) {
164172
fprintf (stderr, "Invalid document, max recursion reached.\n");
165173
return true;
@@ -183,6 +191,9 @@ bson_metrics_visit_array (const bson_iter_t *iter,
183191
bson_metrics_state_t *s = data;
184192
bson_iter_t child;
185193

194+
BSON_UNUSED (iter);
195+
BSON_UNUSED (key);
196+
186197
if (s->depth >= MAX_RECURSION) {
187198
fprintf (stderr, "Invalid document, max recursion reached.\n");
188199
return true;
@@ -202,6 +213,9 @@ bson_metrics (const bson_t *bson, size_t *length, void *data)
202213
{
203214
bson_iter_t iter;
204215
bson_metrics_state_t *s = data;
216+
217+
BSON_UNUSED (length);
218+
205219
++s->doc_count;
206220

207221
if (bson_iter_init (&iter, bson)) {

src/libbson/src/bson/bson-atomic.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ _bson_emul_atomic_int64_fetch_add (volatile int64_t *p,
9191
enum bson_memory_order _unused)
9292
{
9393
int64_t ret;
94+
95+
BSON_UNUSED (_unused);
96+
9497
_lock_emul_atomic ();
9598
ret = *p;
9699
*p += n;
@@ -104,6 +107,9 @@ _bson_emul_atomic_int64_exchange (volatile int64_t *p,
104107
enum bson_memory_order _unused)
105108
{
106109
int64_t ret;
110+
111+
BSON_UNUSED (_unused);
112+
107113
_lock_emul_atomic ();
108114
ret = *p;
109115
*p = n;
@@ -118,6 +124,9 @@ _bson_emul_atomic_int64_compare_exchange_strong (volatile int64_t *p,
118124
enum bson_memory_order _unused)
119125
{
120126
int64_t ret;
127+
128+
BSON_UNUSED (_unused);
129+
121130
_lock_emul_atomic ();
122131
ret = *p;
123132
if (ret == expect_value) {
@@ -145,6 +154,9 @@ _bson_emul_atomic_int32_fetch_add (volatile int32_t *p,
145154
enum bson_memory_order _unused)
146155
{
147156
int32_t ret;
157+
158+
BSON_UNUSED (_unused);
159+
148160
_lock_emul_atomic ();
149161
ret = *p;
150162
*p += n;
@@ -158,6 +170,9 @@ _bson_emul_atomic_int32_exchange (volatile int32_t *p,
158170
enum bson_memory_order _unused)
159171
{
160172
int32_t ret;
173+
174+
BSON_UNUSED (_unused);
175+
161176
_lock_emul_atomic ();
162177
ret = *p;
163178
*p = n;
@@ -172,6 +187,9 @@ _bson_emul_atomic_int32_compare_exchange_strong (volatile int32_t *p,
172187
enum bson_memory_order _unused)
173188
{
174189
int32_t ret;
190+
191+
BSON_UNUSED (_unused);
192+
175193
_lock_emul_atomic ();
176194
ret = *p;
177195
if (ret == expect_value) {
@@ -199,6 +217,9 @@ _bson_emul_atomic_int_fetch_add (volatile int *p,
199217
enum bson_memory_order _unused)
200218
{
201219
int ret;
220+
221+
BSON_UNUSED (_unused);
222+
202223
_lock_emul_atomic ();
203224
ret = *p;
204225
*p += n;
@@ -212,6 +233,9 @@ _bson_emul_atomic_int_exchange (volatile int *p,
212233
enum bson_memory_order _unused)
213234
{
214235
int ret;
236+
237+
BSON_UNUSED (_unused);
238+
215239
_lock_emul_atomic ();
216240
ret = *p;
217241
*p = n;
@@ -226,6 +250,9 @@ _bson_emul_atomic_int_compare_exchange_strong (volatile int *p,
226250
enum bson_memory_order _unused)
227251
{
228252
int ret;
253+
254+
BSON_UNUSED (_unused);
255+
229256
_lock_emul_atomic ();
230257
ret = *p;
231258
if (ret == expect_value) {
@@ -252,6 +279,9 @@ _bson_emul_atomic_ptr_exchange (void *volatile *p,
252279
enum bson_memory_order _unused)
253280
{
254281
void *ret;
282+
283+
BSON_UNUSED (_unused);
284+
255285
_lock_emul_atomic ();
256286
ret = *p;
257287
*p = n;

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ _noop (void)
387387
}
388388

389389

390-
391390
bson_json_opts_t *
392391
bson_json_opts_new (bson_json_mode_t mode, int32_t max_len)
393392
{
@@ -1369,6 +1368,7 @@ _bson_json_read_map_key (bson_json_reader_t *reader, /* IN */
13691368
_bson_json_save_map_key (bson, val, len);
13701369
}
13711370

1371+
/* clang-format off */
13721372
if (bson->read_state == BSON_JSON_IN_BSON_TYPE) {
13731373
if
13741374
HANDLE_OPTION ("$regex", BSON_TYPE_REGEX, BSON_JSON_LF_REGEX)
@@ -1459,6 +1459,7 @@ _bson_json_read_map_key (bson_json_reader_t *reader, /* IN */
14591459
} else {
14601460
_bson_json_save_map_key (bson, val, len);
14611461
}
1462+
/* clang-format on */
14621463
}
14631464

14641465

@@ -2012,6 +2013,9 @@ _push_callback (jsonsl_t json,
20122013
{
20132014
bson_json_reader_t *reader = (bson_json_reader_t *) json->data;
20142015

2016+
BSON_UNUSED (action);
2017+
BSON_UNUSED (buf);
2018+
20152019
switch (state->type) {
20162020
case JSONSL_T_STRING:
20172021
case JSONSL_T_HKEY:
@@ -2043,6 +2047,8 @@ _pop_callback (jsonsl_t json,
20432047
double d;
20442048
const char *obj_text;
20452049

2050+
BSON_UNUSED (action);
2051+
20462052
reader = (bson_json_reader_t *) json->data;
20472053
reader_bson = &reader->bson;
20482054

@@ -2110,6 +2116,8 @@ _error_callback (jsonsl_t json,
21102116
{
21112117
bson_json_reader_t *reader = (bson_json_reader_t *) json->data;
21122118

2119+
BSON_UNUSED (state);
2120+
21132121
if (err == JSONSL_ERROR_CANT_INSERT && *errat == '{') {
21142122
/* start the next document */
21152123
reader->should_reset = true;
@@ -2260,6 +2268,8 @@ bson_json_reader_new (void *data, /* IN */
22602268
bson_json_reader_t *r;
22612269
bson_json_reader_producer_t *p;
22622270

2271+
BSON_UNUSED (allow_multiple);
2272+
22632273
r = bson_malloc0 (sizeof *r);
22642274
r->json = jsonsl_new (STACK_MAX);
22652275
r->json->error_callback = _error_callback;

src/libbson/src/bson/bson-macros.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,15 @@
370370
abort (); \
371371
} while (0)
372372

373+
/**
374+
* @brief Silence warnings for deliberately unused variables or parameters.
375+
*
376+
* @param expr An unused variable or parameter.
377+
*
378+
*/
379+
#define BSON_UNUSED(expr) \
380+
do { \
381+
(void) (expr); \
382+
} while (0)
383+
373384
#endif /* BSON_MACROS_H */

src/libbson/src/bson/bson-memory.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ bson_malloc (size_t num_bytes) /* IN */
6464

6565
if (BSON_LIKELY (num_bytes)) {
6666
if (BSON_UNLIKELY (!(mem = gMemVtable.malloc (num_bytes)))) {
67-
fprintf (stderr, "Failure to allocate memory in bson_malloc(). errno: %d.\n", errno);
67+
fprintf (stderr,
68+
"Failure to allocate memory in bson_malloc(). errno: %d.\n",
69+
errno);
6870
abort ();
6971
}
7072
}
@@ -102,7 +104,9 @@ bson_malloc0 (size_t num_bytes) /* IN */
102104

103105
if (BSON_LIKELY (num_bytes)) {
104106
if (BSON_UNLIKELY (!(mem = gMemVtable.calloc (1, num_bytes)))) {
105-
fprintf (stderr, "Failure to allocate memory in bson_malloc0(). errno: %d.\n", errno);
107+
fprintf (stderr,
108+
"Failure to allocate memory in bson_malloc0(). errno: %d.\n",
109+
errno);
106110
abort ();
107111
}
108112
}
@@ -150,7 +154,9 @@ bson_realloc (void *mem, /* IN */
150154
mem = gMemVtable.realloc (mem, num_bytes);
151155

152156
if (BSON_UNLIKELY (!mem)) {
153-
fprintf (stderr, "Failure to re-allocate memory in bson_realloc(). errno: %d.\n", errno);
157+
fprintf (stderr,
158+
"Failure to re-allocate memory in bson_realloc(). errno: %d.\n",
159+
errno);
154160
abort ();
155161
}
156162

@@ -187,6 +193,8 @@ bson_realloc_ctx (void *mem, /* IN */
187193
size_t num_bytes, /* IN */
188194
void *ctx) /* IN */
189195
{
196+
BSON_UNUSED (ctx);
197+
190198
return bson_realloc (mem, num_bytes);
191199
}
192200

0 commit comments

Comments
 (0)