Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
common: cast all allocations of entangled for c++/objC compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Feb 13, 2019
1 parent df0c5fa commit 84f7446
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cclient/request/get_transactions_to_approve.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion ciri/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions common/curl-p/pearl_diver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion common/storage/sql/sqlite3/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions common/storage/sql/sqlite3/tests/test_sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions common/storage/sql/statements.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion common/trinary/trit_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions gossip/components/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
3 changes: 2 additions & 1 deletion gossip/iota_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gossip/neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion gossip/transaction_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mam/v1/tests/test_mam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion utils/containers/hash/hash_queue.c.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
2 changes: 1 addition & 1 deletion utils/containers/hash/hash_set.c.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
2 changes: 1 addition & 1 deletion utils/containers/hash/hash_stack.c.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
2 changes: 1 addition & 1 deletion utils/containers/lock_free/lf_queue.c.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion utils/containers/set.c.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
Expand Down
8 changes: 4 additions & 4 deletions utils/signed_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 84f7446

Please sign in to comment.