Skip to content

Commit fcd8aa2

Browse files
committed
fixed wrong mallocs preventing proper function
1 parent 952e4b7 commit fcd8aa2

Some content is hidden

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

113 files changed

+58147
-277
lines changed

ODIN_II/SRC/ace.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
2626
#include "cudd.h"
2727
#include "ace.h"
2828
#include "st.h"
29+
#include "allocation_def.h"
2930

3031
#define ACE_P0TO1(P1,PS) ((P1)==0.0)?0.0:(((P1)==1.0)?1.0:0.5*PS/(1.0-(P1)))
3132
#define ACE_P1TO0(P1,PS) ((P1)==0.0)?1.0:(((P1)==0.0)?0.0:0.5*PS/(P1))
@@ -59,7 +60,7 @@ OTHER DEALINGS IN THE SOFTWARE.
5960

6061
typedef unsigned int *pset;
6162

62-
#define ALLOC(type, num) ((type *) malloc(sizeof(type) * (num)))
63+
#define ALLOC(type, num) ALLOCATE_ME(num,type)
6364

6465
#define set_remove(set, e) (set[WHICH_WORD(e)] &= ~ (1 << WHICH_BIT(e)))
6566
#define set_insert(set, e) (set[WHICH_WORD(e)] |= 1 << WHICH_BIT(e))
@@ -465,7 +466,7 @@ ace_cube_t * ace_cube_dup(ace_cube_t * cube) {
465466
int i;
466467
ace_cube_t * cube_copy;
467468

468-
cube_copy = (ace_cube_t * ) malloc(sizeof(ace_cube_t));
469+
cube_copy = (ace_cube_t * ) calloc(1,sizeof(ace_cube_t));
469470
cube_copy->static_prob = cube->static_prob;
470471
cube_copy->num_literals = cube->num_literals;
471472
cube_copy->cube = set_new (2 * cube->num_literals);
@@ -499,7 +500,7 @@ ace_cube_t * ace_cube_new_dc(int num_literals) {
499500
int i;
500501
ace_cube_t * new_cube;
501502

502-
new_cube = (ace_cube_t * ) malloc(sizeof(ace_cube_t));
503+
new_cube = (ace_cube_t * ) calloc(1,sizeof(ace_cube_t));
503504
new_cube->num_literals = num_literals;
504505
new_cube->static_prob = 1.0;
505506
new_cube->cube = set_new (2 * num_literals);
@@ -616,7 +617,7 @@ double calc_cube_switch_prob_recur(DdManager * mgr, DdNode * bdd, ace_cube_t * c
616617

617618
i = Cudd_Regular(bdd)->index;
618619

619-
current_prob = ( double * ) malloc(sizeof(double));
620+
current_prob = ( double * ) calloc(1,sizeof(double));
620621

621622
if (Cudd_IsComplement(bdd)) {
622623
bdd_if1 = Cudd_E(bdd);

ODIN_II/SRC/activity_estimation.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ OTHER DEALINGS IN THE SOFTWARE.
3232
#include "ast_util.h"
3333
#include "activity_estimation.h"
3434
#include "netlist_check.h"
35+
#include "allocation_def.h"
3536

3637
#define DEFAULT_STATIC_PROBABILITY .5
3738
#define DEFAULT_TRANSITION_DENSITY .5
@@ -102,7 +103,7 @@ void calc_transition_density(netlist_t *netlist)
102103
if (current_node->type == BLIF_FUNCTION)
103104
{
104105
/* only one output */
105-
act_data->transition_density = (double*)malloc(sizeof(double)); // only one output
106+
act_data->transition_density = (double*)calloc(1,sizeof(double)); // only one output
106107

107108
if (current_node->num_input_pins == 1)
108109
{
@@ -155,7 +156,7 @@ void calc_transition_density(netlist_t *netlist)
155156
oassert(input_node->unique_node_data_id == ACTIVATION);
156157

157158
/* just store since allocated in the initialization */
158-
act_data->transition_density = (double*)malloc(sizeof(double));
159+
act_data->transition_density = (double*)calloc(1,sizeof(double));
159160
act_data->transition_density[0] = 2 * (input_data->static_probability[input_node_pin] * (1-input_data->static_probability[input_node_pin]));
160161
}
161162
else if (current_node->type == OUTPUT_NODE)
@@ -166,7 +167,7 @@ void calc_transition_density(netlist_t *netlist)
166167
oassert(input_node->unique_node_data_id == ACTIVATION);
167168

168169
/* allocate and stre through */
169-
act_data->transition_density = (double*)malloc(sizeof(double));
170+
act_data->transition_density = (double*)calloc(1,sizeof(double));
170171
act_data->transition_density[0] = input_data->static_probability[input_node_pin];
171172
}
172173
else if ((current_node->type == INPUT_NODE) || (current_node->type == VCC_NODE) || (current_node->type == GND_NODE))
@@ -198,7 +199,7 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
198199
oassert(current_node->unique_node_data_id == RESET);
199200

200201
current_node->unique_node_data_id = ACTIVATION;
201-
act_data = (activation_t*)malloc(sizeof(activation_t));
202+
act_data = (activation_t*)calloc(1,sizeof(activation_t));
202203
current_node->node_data = (void*)act_data;
203204

204205
if (current_node->type == INPUT_NODE)
@@ -218,9 +219,9 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
218219
else
219220
{
220221
/* initialize all the initial probabilities */
221-
act_data->static_probability = (double*)malloc(sizeof(double));
222-
act_data->transition_probability = (double*)malloc(sizeof(double));
223-
act_data->transition_density = (double*)malloc(sizeof(double));
222+
act_data->static_probability = (double*)calloc(1,sizeof(double));
223+
act_data->transition_probability = (double*)calloc(1,sizeof(double));
224+
act_data->transition_density = (double*)calloc(1,sizeof(double));
224225

225226
act_data->static_probability[0] = DEFAULT_STATIC_PROBABILITY;
226227
act_data->transition_probability[0] = -1;
@@ -230,9 +231,9 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
230231
else if (current_node->type == GND_NODE)
231232
{
232233
/* initialize all the initial probabilities */
233-
act_data->static_probability = (double*)malloc(sizeof(double));
234-
act_data->transition_probability = (double*)malloc(sizeof(double));
235-
act_data->transition_density = (double*)malloc(sizeof(double));
234+
act_data->static_probability = (double*)calloc(1,sizeof(double));
235+
act_data->transition_probability = (double*)calloc(1,sizeof(double));
236+
act_data->transition_density = (double*)calloc(1,sizeof(double));
236237

237238
act_data->static_probability[0] = 0.0;
238239
act_data->transition_probability[0] = -1;
@@ -242,9 +243,9 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
242243
else if (current_node->type == VCC_NODE)
243244
{
244245
/* initialize all the initial probabilities */
245-
act_data->static_probability = (double*)malloc(sizeof(double));
246-
act_data->transition_probability = (double*)malloc(sizeof(double));
247-
act_data->transition_density = (double*)malloc(sizeof(double));
246+
act_data->static_probability = (double*)calloc(1,sizeof(double));
247+
act_data->transition_probability = (double*)calloc(1,sizeof(double));
248+
act_data->transition_density = (double*)calloc(1,sizeof(double));
248249

249250
act_data->static_probability[0] = 1.0;
250251
act_data->transition_probability[0] = -1;
@@ -254,9 +255,9 @@ void initialize_probabilities(char *input_file, netlist_t *netlist)
254255
else if (current_node->type == FF_NODE)
255256
{
256257
/* initialize all the initial probabilities */
257-
act_data->static_probability = (double*)malloc(sizeof(double));
258-
act_data->transition_probability = (double*)malloc(sizeof(double));
259-
act_data->transition_density = (double*)malloc(sizeof(double));
258+
act_data->static_probability = (double*)calloc(1,sizeof(double));
259+
act_data->transition_probability = (double*)calloc(1,sizeof(double));
260+
act_data->transition_density = (double*)calloc(1,sizeof(double));
260261

261262
act_data->static_probability[0] = DEFAULT_STATIC_PROBABILITY;
262263
act_data->transition_probability[0] = -1;
@@ -296,7 +297,7 @@ void calc_probabilities_and_init_act_data(netlist_t *netlist)
296297
if (rep == 0)
297298
{
298299
/* only one output */
299-
act_data->static_probability = (double*)malloc(sizeof(double));
300+
act_data->static_probability = (double*)calloc(1,sizeof(double));
300301
}
301302

302303
for (k = 0; k < function_size; k++)
@@ -356,7 +357,7 @@ void calc_probabilities_and_init_act_data(netlist_t *netlist)
356357
if (rep == 0)
357358
{
358359
/* only one output */
359-
act_data->static_probability = (double*)malloc(sizeof(double));
360+
act_data->static_probability = (double*)calloc(1,sizeof(double));
360361
}
361362

362363
act_data->static_probability[0] = input_data->static_probability[input_node_pin];
@@ -374,7 +375,7 @@ void calc_probabilities_and_init_act_data(netlist_t *netlist)
374375
if (rep == 0)
375376
{
376377
/* calculate transition probability */
377-
act_data->transition_probability = (double*)malloc(sizeof(double)*current_node->num_output_pins);
378+
act_data->transition_probability = (double*)calloc(current_node->num_output_pins,sizeof(double));
378379
}
379380

380381
for (k = 0; k < current_node->num_output_pins; k++)
@@ -404,7 +405,7 @@ short *boolean_difference(nnode_t *node, int variable_spot)
404405
/* calculate the size of the boolean difference */
405406
function_size = pow2(node->num_input_pins-1);
406407

407-
return_function = (short*)calloc(sizeof(short), function_size);
408+
return_function = (short*)calloc(function_size,sizeof(short));
408409

409410
for (i = 0; i < function_size; i++)
410411
{
@@ -529,9 +530,9 @@ double calc_density(nnode_t *node, int variable_spot, short *boolean_difference)
529530
*-------------------------------------------------------------------------------------------*/
530531
void output_activation_file_ace_and_function_file(char *output_filename, int lut_size, netlist_t *LUT_netlist, netlist_t *CLUSTER_netlist)
531532
{
532-
char *ace_file_name = (char*)malloc(sizeof(char)*(strlen(output_filename)+4+1));
533-
char *ac2_file_name = (char*)malloc(sizeof(char)*(strlen(output_filename)+4+1));
534-
char *function_file_name = (char*)malloc(sizeof(char)*(strlen(output_filename)+4+1));
533+
char *ace_file_name = (char*)calloc((strlen(output_filename)+4+1),sizeof(char));
534+
char *ac2_file_name = (char*)calloc((strlen(output_filename)+4+1),sizeof(char));
535+
char *function_file_name = (char*)calloc((strlen(output_filename)+4+1),sizeof(char));
535536
int i, j, k, l;
536537
FILE *ace_out;
537538
FILE *ac2_out;
@@ -658,7 +659,7 @@ void output_activation_file_ace_and_function_file(char *output_filename, int lut
658659
for (k = 0; k < internal_subblocks->num_internal_nodes; k++)
659660
{
660661
nnode_t *current_subblock = internal_subblocks->internal_nodes[k];
661-
char *output_search_name = (char*)malloc(sizeof(char)*(strlen(current_subblock->name)+1+4));
662+
char *output_search_name = (char*)calloc((strlen(current_subblock->name)+1+4),sizeof(char));
662663
sprintf(output_search_name, "out:%s", current_subblock->name);
663664

664665
if ((sc_spot = sc_lookup_string(internal_subblocks->nodes_sc, output_search_name)) != -1)

ODIN_II/SRC/adders.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OTHER DEALINGS IN THE SOFTWARE.
3535
#include "errors.h"
3636
#include "subtractions.h"
3737
#include "print_tags.h"
38-
38+
#include "allocation_def.h"
3939
#include "vtr_list.h"
4040

4141
using vtr::t_linked_vptr;
@@ -65,7 +65,7 @@ void init_add_distribution()
6565
int i, j;
6666
oassert(hard_adders != NULL);
6767
j = hard_adders->inputs->size + hard_adders->inputs->next->size;
68-
adder = (int *)malloc(sizeof(int) * (j + 1));
68+
adder = (int *)calloc((j + 1),sizeof(int));
6969
for (i = 0; i <= j; i++)
7070
adder[i] = 0;
7171
return;
@@ -173,7 +173,7 @@ void declare_hard_adder(nnode_t *node)
173173
}
174174

175175
/* Does not exist - must create an instance */
176-
tmp = (t_adder *)malloc(sizeof(t_adder));
176+
tmp = (t_adder *)calloc(1,sizeof(t_adder));
177177
tmp->next = (t_adder *)hard_adders->instances;
178178
hard_adders->instances = tmp;
179179
tmp->size_a = width_a;
@@ -195,26 +195,24 @@ void instantiate_hard_adder(nnode_t *node, short mark, netlist_t * /*netlist*/)
195195
declare_hard_adder(node);
196196

197197
/* Need to give node proper name */
198-
len = strlen(node->name);
199-
len = len + 20; /* 20 chars should hold mul specs */
200-
new_name = (char*)malloc(len);
198+
/* 20 chars should hold mul specs */
199+
new_name = (char*)calloc(strlen(node->name)+20,sizeof(char));
201200

202201
/* wide input first :) */
203202
if (node->input_port_sizes[0] > node->input_port_sizes[1])
204203
sanity = sprintf(new_name, "%s", node->name);
205204
else
206205
sanity = sprintf(new_name, "%s", node->name);
207206

208-
if (len <= sanity) /* buffer not large enough */
207+
if (strlen(node->name)+20 <= sanity) /* buffer not large enough */
209208
oassert(FALSE);
210209

211210
/* Give names to the output pins */
212211
for (i = 0; i < node->num_output_pins; i++)
213212
{
214213
if (node->output_pins[i]->name == NULL)
215214
{
216-
len = strlen(node->name) + 20; /* 6 chars for pin idx */
217-
new_name = (char*)malloc(len);
215+
new_name = (char*)calloc(strlen(node->name) + 20,sizeof(char));
218216
sprintf(new_name, "%s[%d]", node->name, node->output_pins[i]->pin_node_idx);
219217
node->output_pins[i]->name = new_name;
220218
}
@@ -472,12 +470,12 @@ void init_split_adder(nnode_t *node, nnode_t *ptr, int a, int sizea, int b, int
472470

473471
/* Set new port sizes and parameters */
474472
ptr->num_input_port_sizes = 3;
475-
ptr->input_port_sizes = (int *)malloc(3 * sizeof(int));
473+
ptr->input_port_sizes = (int *)calloc(3,sizeof(int));
476474
ptr->input_port_sizes[0] = current_sizea;
477475
ptr->input_port_sizes[1] = current_sizeb;
478476
ptr->input_port_sizes[2] = cin;
479477
ptr->num_output_port_sizes = 2;
480-
ptr->output_port_sizes = (int *)malloc(2 * sizeof(int));
478+
ptr->output_port_sizes = (int *)calloc(2,sizeof(int));
481479
ptr->output_port_sizes[0] = cout;
482480

483481
/* The size of output port sumout equals the maxim size of sizea and sizeb */
@@ -488,7 +486,7 @@ void init_split_adder(nnode_t *node, nnode_t *ptr, int a, int sizea, int b, int
488486

489487
/* Set the number of pins and re-locate previous pin entries */
490488
ptr->num_input_pins = current_sizea + current_sizeb + cin;
491-
ptr->input_pins = (npin_t**)malloc(sizeof(void *) * (current_sizea + current_sizeb + cin));
489+
ptr->input_pins = (npin_t**)calloc((current_sizea + current_sizeb + cin),sizeof(npin_t *));
492490
//if flaga or flagb = 1, the input pins should be empty.
493491
if(flaga == 1)
494492
{
@@ -684,7 +682,7 @@ void init_split_adder(nnode_t *node, nnode_t *ptr, int a, int sizea, int b, int
684682
output = current_sizeb + cout;
685683

686684
ptr->num_output_pins = output;
687-
ptr->output_pins = (npin_t**)malloc(sizeof(void *) * output);
685+
ptr->output_pins = (npin_t**)calloc(output,sizeof(npin_t *));
688686
for (i = 0; i < output; i++)
689687
ptr->output_pins[i] = NULL;
690688

@@ -716,12 +714,12 @@ void split_adder(nnode_t *nodeo, int a, int b, int sizea, int sizeb, int cin, in
716714
oassert(nodeo->input_port_sizes[0] == a);
717715
oassert(nodeo->input_port_sizes[1] == b);
718716

719-
node = (nnode_t**)malloc(sizeof(nnode_t*)*(count));
717+
node = (nnode_t**)calloc((count),sizeof(nnode_t*));
720718

721719
for(i = 0; i < count; i++)
722720
{
723721
node[i] = allocate_nnode();
724-
node[i]->name = (char *)malloc(strlen(nodeo->name) + 20);
722+
node[i]->name = (char *)calloc(strlen(nodeo->name) + 20,sizeof(char));
725723
sprintf(node[i]->name, "%s-%d", nodeo->name, i);
726724
if(i == count - 1)
727725
{

ODIN_II/SRC/allocation_def.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <unistd.h>
4+
#define ALLOCATE_ME(num, type) ((type *) calloc((num),sizeof(type)))

0 commit comments

Comments
 (0)