Skip to content

Commit

Permalink
Fix clang 15 -Wstrict-prototype warnings
Browse files Browse the repository at this point in the history
Clang 15 has become more strict about prototypes of functions without arguments in C, showing many warnings similar to:

    src/cbor/maps.h:49:49: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
    CBOR_EXPORT cbor_item_t *cbor_new_indefinite_map();
                                                    ^
                                                     void

This is because in C, functions declared or defined with () are considered old-style functions with variadic arguments. (Although these will likely be finally removed in C23.)

Fix the warnings by using `(void)` for each of the declarations and definitions. This also fixes two incorrect invocations of `cbor_new_indefinite_map(void)` in the tests.
  • Loading branch information
DimitryAndric authored and PJK committed Dec 26, 2022
1 parent 7c35186 commit 32da8e0
Show file tree
Hide file tree
Showing 30 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion examples/bazel/src/hello.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include <cstdint>

uint8_t cbor_version();
uint8_t cbor_version(void);

#endif // HELLO_H_
2 changes: 1 addition & 1 deletion examples/cjson2cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void cjson_cbor_stream_decode(cJSON *source,
}
}

void usage() {
void usage(void) {
printf("Usage: cjson [input JSON file]\n");
exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/create_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdio.h>
#include "cbor.h"

int main() {
int main(void) {
/* Preallocate the map structure */
cbor_item_t* root = cbor_new_definite_map(2);
/* Add the content */
Expand Down
2 changes: 1 addition & 1 deletion examples/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdio.h>
#include "cbor.h"

int main() {
int main(void) {
printf("Hello from libcbor %s\n", CBOR_VERSION);
printf("Custom allocation support: %s\n", CBOR_CUSTOM_ALLOC ? "yes" : "no");
printf("Pretty-printer support: %s\n", CBOR_PRETTY_PRINTER ? "yes" : "no");
Expand Down
2 changes: 1 addition & 1 deletion examples/readfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdio.h>
#include "cbor.h"

void usage() {
void usage(void) {
printf("Usage: readfile [input file]\n");
exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int compareUint(const void *a, const void *b) {
return 1;
}

int main() {
int main(void) {
cbor_item_t *array = cbor_new_definite_array(4);
cbor_array_push(array, cbor_move(cbor_build_uint8(4)));
cbor_array_push(array, cbor_move(cbor_build_uint8(3)));
Expand Down
2 changes: 1 addition & 1 deletion examples/streaming_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdlib.h>
#include "cbor.h"

void usage() {
void usage(void) {
printf("Usage: streaming_array <N>\n");
printf("Prints out serialized array [0, ..., N-1]\n");
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion examples/streaming_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define UNUSED(x) x
#endif

void usage() {
void usage(void) {
printf("Usage: streaming_parser [input file]\n");
exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cbor/arrays.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ cbor_item_t *cbor_new_definite_array(size_t size) {
return item;
}

cbor_item_t *cbor_new_indefinite_array() {
cbor_item_t *cbor_new_indefinite_array(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);

Expand Down
2 changes: 1 addition & 1 deletion src/cbor/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ CBOR_EXPORT cbor_item_t* cbor_new_definite_array(size_t size);
*
* @return **new** array or `NULL` upon malloc failure
*/
CBOR_EXPORT cbor_item_t* cbor_new_indefinite_array();
CBOR_EXPORT cbor_item_t* cbor_new_indefinite_array(void);

/** Append to the end
*
Expand Down
4 changes: 2 additions & 2 deletions src/cbor/bytestrings.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool cbor_bytestring_is_indefinite(const cbor_item_t *item) {
return !cbor_bytestring_is_definite(item);
}

cbor_item_t *cbor_new_definite_bytestring() {
cbor_item_t *cbor_new_definite_bytestring(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
Expand All @@ -39,7 +39,7 @@ cbor_item_t *cbor_new_definite_bytestring() {
return item;
}

cbor_item_t *cbor_new_indefinite_bytestring() {
cbor_item_t *cbor_new_indefinite_bytestring(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
Expand Down
4 changes: 2 additions & 2 deletions src/cbor/bytestrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ CBOR_EXPORT bool cbor_bytestring_add_chunk(cbor_item_t *item,
*
* @return **new** definite bytestring. `NULL` on malloc failure.
*/
CBOR_EXPORT cbor_item_t *cbor_new_definite_bytestring();
CBOR_EXPORT cbor_item_t *cbor_new_definite_bytestring(void);

/** Creates a new indefinite byte string
*
* The chunks array is initialized to `NULL` and chunk count to 0
*
* @return **new** indefinite bytestring. `NULL` on malloc failure.
*/
CBOR_EXPORT cbor_item_t *cbor_new_indefinite_bytestring();
CBOR_EXPORT cbor_item_t *cbor_new_indefinite_bytestring(void);

/** Creates a new byte string and initializes it
*
Expand Down
12 changes: 6 additions & 6 deletions src/cbor/floats_ctrls.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void cbor_set_bool(cbor_item_t *item, bool value) {
value ? CBOR_CTRL_TRUE : CBOR_CTRL_FALSE;
}

cbor_item_t *cbor_new_ctrl() {
cbor_item_t *cbor_new_ctrl(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);

Expand All @@ -106,7 +106,7 @@ cbor_item_t *cbor_new_ctrl() {
return item;
}

cbor_item_t *cbor_new_float2() {
cbor_item_t *cbor_new_float2(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t) + 4);
_CBOR_NOTNULL(item);

Expand All @@ -118,7 +118,7 @@ cbor_item_t *cbor_new_float2() {
return item;
}

cbor_item_t *cbor_new_float4() {
cbor_item_t *cbor_new_float4(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t) + 4);
_CBOR_NOTNULL(item);

Expand All @@ -130,7 +130,7 @@ cbor_item_t *cbor_new_float4() {
return item;
}

cbor_item_t *cbor_new_float8() {
cbor_item_t *cbor_new_float8(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t) + 8);
_CBOR_NOTNULL(item);

Expand All @@ -142,14 +142,14 @@ cbor_item_t *cbor_new_float8() {
return item;
}

cbor_item_t *cbor_new_null() {
cbor_item_t *cbor_new_null(void) {
cbor_item_t *item = cbor_new_ctrl();
_CBOR_NOTNULL(item);
cbor_set_ctrl(item, CBOR_CTRL_NULL);
return item;
}

cbor_item_t *cbor_new_undef() {
cbor_item_t *cbor_new_undef(void) {
cbor_item_t *item = cbor_new_ctrl();
_CBOR_NOTNULL(item);
cbor_set_ctrl(item, CBOR_CTRL_UNDEF);
Expand Down
12 changes: 6 additions & 6 deletions src/cbor/floats_ctrls.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,43 +84,43 @@ CBOR_EXPORT bool cbor_get_bool(const cbor_item_t *item);
*
* @return **new** 1B ctrl or `NULL` upon memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_new_ctrl();
CBOR_EXPORT cbor_item_t *cbor_new_ctrl(void);

/** Constructs a new float item
*
* The width cannot be changed once the item is created
*
* @return **new** 2B float or `NULL` upon memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_new_float2();
CBOR_EXPORT cbor_item_t *cbor_new_float2(void);

/** Constructs a new float item
*
* The width cannot be changed once the item is created
*
* @return **new** 4B float or `NULL` upon memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_new_float4();
CBOR_EXPORT cbor_item_t *cbor_new_float4(void);

/** Constructs a new float item
*
* The width cannot be changed once the item is created
*
* @return **new** 8B float or `NULL` upon memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_new_float8();
CBOR_EXPORT cbor_item_t *cbor_new_float8(void);

/** Constructs new null ctrl item
*
* @return **new** null ctrl item or `NULL` upon memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_new_null();
CBOR_EXPORT cbor_item_t *cbor_new_null(void);

/** Constructs new undef ctrl item
*
* @return **new** undef ctrl item or `NULL` upon memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_new_undef();
CBOR_EXPORT cbor_item_t *cbor_new_undef(void);

/** Constructs new boolean ctrl item
*
Expand Down
2 changes: 1 addition & 1 deletion src/cbor/internal/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "stack.h"

struct _cbor_stack _cbor_stack_init() {
struct _cbor_stack _cbor_stack_init(void) {
return (struct _cbor_stack){.top = NULL, .size = 0};
}

Expand Down
2 changes: 1 addition & 1 deletion src/cbor/internal/stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct _cbor_stack {
size_t size;
};

struct _cbor_stack _cbor_stack_init();
struct _cbor_stack _cbor_stack_init(void);

void _cbor_stack_pop(struct _cbor_stack *);

Expand Down
8 changes: 4 additions & 4 deletions src/cbor/ints.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void cbor_mark_negint(cbor_item_t *item) {
item->type = CBOR_TYPE_NEGINT;
}

cbor_item_t *cbor_new_int8() {
cbor_item_t *cbor_new_int8(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t) + 1);
_CBOR_NOTNULL(item);
*item = (cbor_item_t){.data = (unsigned char *)item + sizeof(cbor_item_t),
Expand All @@ -96,7 +96,7 @@ cbor_item_t *cbor_new_int8() {
return item;
}

cbor_item_t *cbor_new_int16() {
cbor_item_t *cbor_new_int16(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t) + 2);
_CBOR_NOTNULL(item);
*item = (cbor_item_t){.data = (unsigned char *)item + sizeof(cbor_item_t),
Expand All @@ -106,7 +106,7 @@ cbor_item_t *cbor_new_int16() {
return item;
}

cbor_item_t *cbor_new_int32() {
cbor_item_t *cbor_new_int32(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t) + 4);
_CBOR_NOTNULL(item);
*item = (cbor_item_t){.data = (unsigned char *)item + sizeof(cbor_item_t),
Expand All @@ -116,7 +116,7 @@ cbor_item_t *cbor_new_int32() {
return item;
}

cbor_item_t *cbor_new_int64() {
cbor_item_t *cbor_new_int64(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t) + 8);
_CBOR_NOTNULL(item);
*item = (cbor_item_t){.data = (unsigned char *)item + sizeof(cbor_item_t),
Expand Down
8 changes: 4 additions & 4 deletions src/cbor/ints.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ CBOR_EXPORT void cbor_mark_negint(cbor_item_t *item);
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
CBOR_EXPORT cbor_item_t *cbor_new_int8();
CBOR_EXPORT cbor_item_t *cbor_new_int8(void);

/** Allocates new integer with 2B width
*
Expand All @@ -127,7 +127,7 @@ CBOR_EXPORT cbor_item_t *cbor_new_int8();
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
CBOR_EXPORT cbor_item_t *cbor_new_int16();
CBOR_EXPORT cbor_item_t *cbor_new_int16(void);

/** Allocates new integer with 4B width
*
Expand All @@ -136,7 +136,7 @@ CBOR_EXPORT cbor_item_t *cbor_new_int16();
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
CBOR_EXPORT cbor_item_t *cbor_new_int32();
CBOR_EXPORT cbor_item_t *cbor_new_int32(void);

/** Allocates new integer with 8B width
*
Expand All @@ -145,7 +145,7 @@ CBOR_EXPORT cbor_item_t *cbor_new_int32();
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
CBOR_EXPORT cbor_item_t *cbor_new_int64();
CBOR_EXPORT cbor_item_t *cbor_new_int64(void);

/** Constructs a new positive integer
*
Expand Down
2 changes: 1 addition & 1 deletion src/cbor/maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cbor_item_t *cbor_new_definite_map(size_t size) {
return item;
}

cbor_item_t *cbor_new_indefinite_map() {
cbor_item_t *cbor_new_indefinite_map(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);

Expand Down
2 changes: 1 addition & 1 deletion src/cbor/maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CBOR_EXPORT cbor_item_t *cbor_new_definite_map(size_t size);
*
* @return **new** indefinite map. `NULL` on malloc failure.
*/
CBOR_EXPORT cbor_item_t *cbor_new_indefinite_map();
CBOR_EXPORT cbor_item_t *cbor_new_indefinite_map(void);

/** Add a pair to the map
*
Expand Down
4 changes: 2 additions & 2 deletions src/cbor/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <string.h>
#include "internal/memory_utils.h"

cbor_item_t *cbor_new_definite_string() {
cbor_item_t *cbor_new_definite_string(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
Expand All @@ -19,7 +19,7 @@ cbor_item_t *cbor_new_definite_string() {
return item;
}

cbor_item_t *cbor_new_indefinite_string() {
cbor_item_t *cbor_new_indefinite_string(void) {
cbor_item_t *item = _CBOR_MALLOC(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
Expand Down
4 changes: 2 additions & 2 deletions src/cbor/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ CBOR_EXPORT bool cbor_string_add_chunk(cbor_item_t *item, cbor_item_t *chunk);
*
* @return **new** definite string. `NULL` on malloc failure.
*/
CBOR_EXPORT cbor_item_t *cbor_new_definite_string();
CBOR_EXPORT cbor_item_t *cbor_new_definite_string(void);

/** Creates a new indefinite string
*
* The chunks array is initialized to `NULL` and chunkcount to 0
*
* @return **new** indefinite string. `NULL` on malloc failure.
*/
CBOR_EXPORT cbor_item_t *cbor_new_indefinite_string();
CBOR_EXPORT cbor_item_t *cbor_new_indefinite_string(void);

/** Creates a new string and initializes it
*
Expand Down
2 changes: 1 addition & 1 deletion test/cbor_serialize_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static void test_serialize_definite_map(void **_CBOR_UNUSED(_state)) {
}

static void test_serialize_indefinite_map(void **_CBOR_UNUSED(_state)) {
cbor_item_t *item = cbor_new_indefinite_map(2);
cbor_item_t *item = cbor_new_indefinite_map();
cbor_item_t *one = cbor_build_uint8(1);
cbor_item_t *two = cbor_build_uint8(2);

Expand Down
2 changes: 1 addition & 1 deletion test/copy_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void test_def_map(void **_CBOR_UNUSED(_state)) {
}

static void test_indef_map(void **_CBOR_UNUSED(_state)) {
item = cbor_new_indefinite_map(1);
item = cbor_new_indefinite_map();
cbor_map_add(item, (struct cbor_pair){
.key = cbor_move(cbor_build_uint8(42)),
.value = cbor_move(cbor_build_uint8(43)),
Expand Down
2 changes: 1 addition & 1 deletion test/float_ctrl_encoders_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void test_break(void **_CBOR_UNUSED(_state)) {

/* Check that encode(decode(buffer)) = buffer for a valid half-float in the
* buffer.*/
static void assert_half_float_codec_identity() {
static void assert_half_float_codec_identity(void) {
unsigned char secondary_buffer[3];
struct cbor_load_result res;
// Load and check data in buffer
Expand Down

0 comments on commit 32da8e0

Please sign in to comment.