From 84f744670b2b96bf8e8f1dbc95f2d89e25e6140c Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 13 Feb 2019 15:31:50 +0100 Subject: [PATCH] common: cast all allocations of entangled for c++/objC compilation --- cclient/request/get_transactions_to_approve.c | 2 +- ciri/conf.c | 3 ++- common/curl-p/pearl_diver.c | 6 ++++-- common/storage/sql/sqlite3/storage.c | 2 +- common/storage/sql/sqlite3/tests/test_sqlite3.c | 4 ++-- common/storage/sql/statements.c | 4 ++-- common/trinary/trit_array.c | 2 +- gossip/components/processor.c | 13 ++++++++----- gossip/iota_packet.c | 3 ++- gossip/neighbor.c | 2 +- gossip/transaction_request.c | 3 ++- mam/v1/tests/test_mam.c | 2 +- utils/containers/hash/hash_queue.c.tpl | 2 +- utils/containers/hash/hash_set.c.tpl | 2 +- utils/containers/hash/hash_stack.c.tpl | 2 +- utils/containers/lock_free/lf_queue.c.tpl | 2 +- utils/containers/set.c.tpl | 2 +- utils/signed_files.c | 8 ++++---- 18 files changed, 36 insertions(+), 28 deletions(-) diff --git a/cclient/request/get_transactions_to_approve.c b/cclient/request/get_transactions_to_approve.c index 52bb7e1491..f314645d72 100644 --- a/cclient/request/get_transactions_to_approve.c +++ b/cclient/request/get_transactions_to_approve.c @@ -38,7 +38,7 @@ void get_transactions_to_approve_req_set_reference( get_transactions_to_approve_req_t* const req, flex_trit_t const* const reference) { if (req->reference == NULL) { - req->reference = malloc(FLEX_TRIT_SIZE_243); + req->reference = (flex_trit_t*)malloc(FLEX_TRIT_SIZE_243); } memcpy(req->reference, reference, FLEX_TRIT_SIZE_243); } diff --git a/ciri/conf.c b/ciri/conf.c index 024e9e85d2..36761a9ef7 100644 --- a/ciri/conf.c +++ b/ciri/conf.c @@ -23,7 +23,8 @@ static struct option* build_options() { while (cli_arguments_g[nbr].desc) { nbr++; } - struct option* options = malloc((nbr + 1) * sizeof(struct option)); + struct option* options = + (struct option*)malloc((nbr + 1) * sizeof(struct option)); size_t i; for (i = 0; i < nbr; i++) { options[i].name = cli_arguments_g[i].name; diff --git a/common/curl-p/pearl_diver.c b/common/curl-p/pearl_diver.c index c29a679bd2..16adfdfba7 100644 --- a/common/curl-p/pearl_diver.c +++ b/common/curl-p/pearl_diver.c @@ -55,8 +55,10 @@ PearlDiverStatus pd_search(Curl *const ctx, unsigned short const offset, return PEARL_DIVER_ERROR; } - SearchInstance *inst = calloc(n_procs, sizeof(SearchInstance)); - thread_handle_t *tid = calloc(n_procs, sizeof(thread_handle_t)); + SearchInstance *inst = + (SearchInstance *)calloc(n_procs, sizeof(SearchInstance)); + thread_handle_t *tid = + (thread_handle_t *)calloc(n_procs, sizeof(thread_handle_t)); { PCurl curl; diff --git a/common/storage/sql/sqlite3/storage.c b/common/storage/sql/sqlite3/storage.c index a01e8d3805..a99b38a820 100644 --- a/common/storage/sql/sqlite3/storage.c +++ b/common/storage/sql/sqlite3/storage.c @@ -1175,7 +1175,7 @@ retcode_t iota_stor_state_delta_store( sqlite3_connection->statements.state_delta_store; size = state_delta_serialized_size(delta); - if ((bytes = calloc(size, sizeof(byte_t))) == NULL) { + if ((bytes = (byte_t*)calloc(size, sizeof(byte_t))) == NULL) { ret = RC_STORAGE_OOM; goto done; } diff --git a/common/storage/sql/sqlite3/tests/test_sqlite3.c b/common/storage/sql/sqlite3/tests/test_sqlite3.c index 98fb50d7a3..97a4b7b9e3 100644 --- a/common/storage/sql/sqlite3/tests/test_sqlite3.c +++ b/common/storage/sql/sqlite3/tests/test_sqlite3.c @@ -214,7 +214,7 @@ void test_stored_milestone(void) { .insufficient_capacity = false}; for (int i = 0; i < 5; ++i) { - pack.models[i] = malloc(sizeof(iota_milestone_t)); + pack.models[i] = (iota_milestone_t *)malloc(sizeof(iota_milestone_t)); } TEST_ASSERT(iota_stor_milestone_load(&connection, HASH, &pack) == RC_OK); TEST_ASSERT_EQUAL_INT(1, pack.num_loaded); @@ -232,7 +232,7 @@ void test_stored_load_hashes_by_address(void) { .num_loaded = 0, .insufficient_capacity = false}; for (size_t i = 0; i < 5; ++i) { - hashes[i] = malloc(FLEX_TRIT_SIZE_243); + hashes[i] = (flex_trit_t *)malloc(FLEX_TRIT_SIZE_243); } flex_trit_t tx_test_trits[FLEX_TRIT_SIZE_8019]; diff --git a/common/storage/sql/statements.c b/common/storage/sql/statements.c index eed07be291..dc487e2fc5 100644 --- a/common/storage/sql/statements.c +++ b/common/storage/sql/statements.c @@ -18,7 +18,7 @@ */ char *iota_statement_in_clause_build(size_t const count) { - char *in_clause = calloc(2 * count + 1, 1); + char *in_clause = (char *)calloc(2 * count + 1, 1); size_t offset = 0; if (count != 0) { @@ -177,7 +177,7 @@ char *iota_statement_transaction_find_build(size_t const bundles_count, size_t statement_size = iota_statement_transaction_find_size + 2 * bundles_count + 2 * addresses_count + 2 * tags_count + 4 * approvees_count; - char *statement = malloc(statement_size); + char *statement = (char *)malloc(statement_size); char *bundles_in_clause = iota_statement_in_clause_build(bundles_count); char *addresses_in_clause = iota_statement_in_clause_build(addresses_count); diff --git a/common/trinary/trit_array.c b/common/trinary/trit_array.c index 9147842f49..f219551b89 100644 --- a/common/trinary/trit_array.c +++ b/common/trinary/trit_array.c @@ -127,7 +127,7 @@ trit_array_p trit_array_new(size_t const num_trits) { memset(trit_array, 0, sizeof(struct _trit_array)); trit_array->num_trits = num_trits; trit_array->num_bytes = trit_array_bytes_for_trits(num_trits); - trit_array->trits = malloc(trit_array->num_bytes); + trit_array->trits = (flex_trit_t *)malloc(trit_array->num_bytes); if (!trit_array->trits) { trit_array_free(trit_array); // errno = IOTA_OUT_OF_MEMORY diff --git a/gossip/components/processor.c b/gossip/components/processor.c index 0aeaf3906b..db6f5d7d1f 100644 --- a/gossip/components/processor.c +++ b/gossip/components/processor.c @@ -264,15 +264,18 @@ static void *processor_routine(processor_t *const processor) { const size_t PACKET_MAX = 64; size_t packet_cnt = 0; iota_packet_t *packet_ptr = NULL; - iota_packet_t *packets = calloc(PACKET_MAX, sizeof(iota_packet_t)); + iota_packet_t *packets = + (iota_packet_t *)calloc(PACKET_MAX, sizeof(iota_packet_t)); - trit_t *tx = calloc(NUM_TRITS_SERIALIZED_TRANSACTION, sizeof(trit_t)); - trit_t *hash = calloc(HASH_LENGTH_TRIT, sizeof(trit_t)); + trit_t *tx = + (trit_t *)calloc(NUM_TRITS_SERIALIZED_TRANSACTION, sizeof(trit_t)); + trit_t *hash = (trit_t *)calloc(HASH_LENGTH_TRIT, sizeof(trit_t)); - PCurl *curl = calloc(1, sizeof(PCurl)); + PCurl *curl = (PCurl *)calloc(1, sizeof(PCurl)); curl->type = 81; - ptrit_t *txs_acc = calloc(NUM_TRITS_SERIALIZED_TRANSACTION, sizeof(ptrit_t)); + ptrit_t *txs_acc = + (ptrit_t *)calloc(NUM_TRITS_SERIALIZED_TRANSACTION, sizeof(ptrit_t)); flex_trit_t flex_hash[FLEX_TRIT_SIZE_243]; diff --git a/gossip/iota_packet.c b/gossip/iota_packet.c index 4c68db2ab3..d08cbfd8b0 100644 --- a/gossip/iota_packet.c +++ b/gossip/iota_packet.c @@ -77,7 +77,8 @@ retcode_t iota_packet_queue_push(iota_packet_queue_t *const queue, return RC_NULL_PARAM; } - if ((entry = malloc(sizeof(iota_packet_queue_entry_t))) == NULL) { + if ((entry = (iota_packet_queue_entry_t *)malloc( + sizeof(iota_packet_queue_entry_t))) == NULL) { return RC_OOM; } entry->packet = *packet; diff --git a/gossip/neighbor.c b/gossip/neighbor.c index 2de831cc4b..5f02f44605 100644 --- a/gossip/neighbor.c +++ b/gossip/neighbor.c @@ -141,7 +141,7 @@ retcode_t neighbors_add(neighbor_t **const neighbors, return RC_NEIGHBOR_ALREADY_PAIRED; } - if ((entry = malloc(sizeof(neighbor_t))) == NULL) { + if ((entry = (neighbor_t *)malloc(sizeof(neighbor_t))) == NULL) { return RC_OOM; } diff --git a/gossip/transaction_request.c b/gossip/transaction_request.c index b249bcc1b0..c4c3ebed4c 100644 --- a/gossip/transaction_request.c +++ b/gossip/transaction_request.c @@ -30,7 +30,8 @@ retcode_t transaction_request_queue_push( return RC_NULL_PARAM; } - if ((entry = malloc(sizeof(transaction_request_queue_entry_t))) == NULL) { + if ((entry = (transaction_request_queue_entry_t *)malloc( + sizeof(transaction_request_queue_entry_t))) == NULL) { return RC_OOM; } entry->request.neighbor = neighbor; diff --git a/mam/v1/tests/test_mam.c b/mam/v1/tests/test_mam.c index 5074319d9a..1609dfb9d3 100644 --- a/mam/v1/tests/test_mam.c +++ b/mam/v1/tests/test_mam.c @@ -49,7 +49,7 @@ void test_mam_sec(int security) { trit_t next_root[next_tree_size * HASH_LENGTH_TRIT]; int payload_length = payload_min_length( message_length, tree_size * HASH_LENGTH_TRIT, index, security); - trit_t *payload = malloc(payload_length * sizeof(trit_t)); + trit_t *payload = (trit_t *)malloc(payload_length * sizeof(trit_t)); Curl curl; curl.type = CURL_P_27; diff --git a/utils/containers/hash/hash_queue.c.tpl b/utils/containers/hash/hash_queue.c.tpl index 99efed77e2..fff733f592 100644 --- a/utils/containers/hash/hash_queue.c.tpl +++ b/utils/containers/hash/hash_queue.c.tpl @@ -15,7 +15,7 @@ retcode_t hash{SIZE}_queue_push(hash{SIZE}_queue_t *const queue, flex_trit_t const *const hash) { hash{SIZE}_queue_entry_t *entry = NULL; - if ((entry = malloc(sizeof(hash{SIZE}_queue_entry_t))) == NULL) { + if ((entry = (hash{SIZE}_queue_entry_t *)malloc(sizeof(hash{SIZE}_queue_entry_t))) == NULL) { return RC_UTILS_OOM; } memcpy(entry->hash, hash, FLEX_TRIT_SIZE_{SIZE}); diff --git a/utils/containers/hash/hash_set.c.tpl b/utils/containers/hash/hash_set.c.tpl index 2763d521f5..8f3e69e1ca 100644 --- a/utils/containers/hash/hash_set.c.tpl +++ b/utils/containers/hash/hash_set.c.tpl @@ -17,7 +17,7 @@ retcode_t hash{SIZE}_set_add(hash{SIZE}_set_t *const set, hash{SIZE}_set_entry_t *entry = NULL; if (!hash{SIZE}_set_contains(set, hash)) { - if ((entry = malloc(sizeof(hash{SIZE}_set_entry_t))) == NULL) { + if ((entry = (hash{SIZE}_set_entry_t *)malloc(sizeof(hash{SIZE}_set_entry_t))) == NULL) { return RC_UTILS_OOM; } memcpy(entry->hash, hash, FLEX_TRIT_SIZE_{SIZE}); diff --git a/utils/containers/hash/hash_stack.c.tpl b/utils/containers/hash/hash_stack.c.tpl index 86b81fdb75..abd2398079 100644 --- a/utils/containers/hash/hash_stack.c.tpl +++ b/utils/containers/hash/hash_stack.c.tpl @@ -15,7 +15,7 @@ retcode_t hash{SIZE}_stack_push(hash{SIZE}_stack_t *const stack, flex_trit_t const *const hash) { hash{SIZE}_stack_entry_t *entry = NULL; - if ((entry = malloc(sizeof(hash{SIZE}_stack_entry_t))) == NULL) { + if ((entry = (hash{SIZE}_stack_entry_t *)malloc(sizeof(hash{SIZE}_stack_entry_t))) == NULL) { return RC_UTILS_OOM; } memcpy(entry->hash, hash, FLEX_TRIT_SIZE_{SIZE}); diff --git a/utils/containers/lock_free/lf_queue.c.tpl b/utils/containers/lock_free/lf_queue.c.tpl index f07dc6a343..a853173319 100644 --- a/utils/containers/lock_free/lf_queue.c.tpl +++ b/utils/containers/lock_free/lf_queue.c.tpl @@ -55,7 +55,7 @@ retcode_t iota_lf_umm_queue_{TYPE}_enqueue(iota_lf_umm_queue_{TYPE}_t* const que if (lfds711_freelist_pop(&queue->freelist, &fe, NULL)) { reused_element = true; p = LFDS711_FREELIST_GET_VALUE_FROM_ELEMENT(*fe); - } else if ((p = malloc(sizeof(iota_lf_queue_umm_{TYPE}_t))) == NULL) { + } else if ((p = (iota_lf_queue_umm_{TYPE}_t*)malloc(sizeof(iota_lf_queue_umm_{TYPE}_t))) == NULL) { return RC_OOM; } diff --git a/utils/containers/set.c.tpl b/utils/containers/set.c.tpl index 6e6958786a..8cd6a8a9d1 100644 --- a/utils/containers/set.c.tpl +++ b/utils/containers/set.c.tpl @@ -16,7 +16,7 @@ retcode_t {TYPE}_set_add({TYPE}_set_t *const set, {TYPE}_set_entry_t *entry = NULL; if (!{TYPE}_set_contains(set, value)) { - if ((entry = malloc(sizeof({TYPE}_set_entry_t))) == NULL) { + if ((entry = ({TYPE}_set_entry_t *)malloc(sizeof({TYPE}_set_entry_t))) == NULL) { return RC_UTILS_OOM; } memcpy(&entry->value, value, sizeof({TYPE})); diff --git a/utils/signed_files.c b/utils/signed_files.c index 93bdc8a9fb..60641235e4 100644 --- a/utils/signed_files.c +++ b/utils/signed_files.c @@ -111,16 +111,16 @@ static retcode_t digest_file(char const *const filename, while ((read = getline(&line, &len, fp)) > 0) { line[--read] = '\0'; // 2 trytes by ASCII character - if ((trytes = realloc(trytes, read * 2)) == NULL) { + if ((trytes = (tryte_t *)realloc(trytes, read * 2)) == NULL) { ret = RC_UTILS_OOM; goto done; } ascii_to_trytes(line, trytes); // 3 trits by tryte and size needs to be a multiple of HASH_LENGTH_TRIT // (kerl) - if ((trits = realloc(trits, HASH_LENGTH_TRIT * - (((read * 6) / HASH_LENGTH_TRIT) + 1))) == - NULL) { + if ((trits = (trit_t *)realloc( + trits, HASH_LENGTH_TRIT * + (((read * 6) / HASH_LENGTH_TRIT) + 1))) == NULL) { ret = RC_UTILS_OOM; goto done; }