include/r_types: fix R_NEWS0 calloc usage and use it in libr/util

This commit is contained in:
Riccardo Schirone 2015-06-12 12:00:18 +02:00 committed by pancake
parent e9b870d588
commit 177ee3ac56
5 changed files with 9 additions and 8 deletions

View file

@ -176,7 +176,7 @@ typedef void (*PrintfCallback)(const char *str, ...);
#define BITS2BYTES(x) (((x)/8)+(((x)%8)?1:0))
#define ZERO_FILL(x) memset (&x, 0, sizeof (x))
#define R_NEWS0(x,y) (x*)calloc(sizeof(x),y)
#define R_NEWS0(x,y) (x*)calloc(y,sizeof(x))
#define R_NEWS(x,y) (x*)malloc(sizeof(x)*y)
#define R_NEW0(x) (x*)calloc(1,sizeof(x))
#define R_NEW(x) (x*)malloc(sizeof(x))

View file

@ -297,6 +297,7 @@ R_API void r_graph_add_edge (RGraph *g, RGraphNode *from, RGraphNode *to);
R_API RList *r_graph_get_neighbours (RGraph *g, RGraphNode *n);
R_API int r_graph_adjacent (RGraph *g, RGraphNode *from, RGraphNode *to);
R_API int r_file_is_abspath(const char *file);
R_API boolt r_file_truncate (const char *filename, ut64 newsize);
R_API ut64 r_file_size(const char *str);
R_API char *r_file_root(const char *root, const char *path);

View file

@ -27,8 +27,8 @@ static void r_graph_node_free (RGraphNode *n) {
R_API RGraph *r_graph_new () {
RGraph *t = R_NEW0 (RGraph);
t->capacity = INITIAL_CAPACITY;
t->nodes = calloc (t->capacity, sizeof(RGraphNode *));
t->adjacency = calloc (t->capacity, sizeof(RList *));
t->nodes = R_NEWS0 (RGraphNode *, t->capacity);
t->adjacency = R_NEWS0 (RList *, t->capacity);
t->n_nodes = 0;
t->last_index = -1;
return t;
@ -64,8 +64,8 @@ R_API void r_graph_reset (RGraph *t) {
}
free (t->nodes);
t->capacity = INITIAL_CAPACITY;
t->nodes = calloc (t->capacity, sizeof(RGraphNode *));
t->adjacency = calloc (t->capacity, sizeof(RList *));
t->nodes = R_NEWS0 (RGraphNode *, t->capacity);
t->adjacency = R_NEWS0 (RList *, t->capacity);
t->n_nodes = 0;
}

View file

@ -4,7 +4,7 @@
R_API RQueue *r_queue_new (int n) {
RQueue *q = R_NEW0 (RQueue);
q->elems = calloc (n, sizeof(void *));
q->elems = R_NEWS0 (void *, n);
if (!q->elems)
return NULL;
@ -29,7 +29,7 @@ static int increase_capacity (RQueue *q) {
void **newelems;
int i, tmp_front;
newelems = calloc (new_capacity, sizeof(void *));
newelems = R_NEWS0(void *, new_capacity);
if (!newelems)
return R_FALSE;

View file

@ -4,7 +4,7 @@
R_API RStack *r_stack_new (unsigned int n) {
RStack *s = R_NEW0 (RStack);
s->elems = calloc(n, sizeof(void *));
s->elems = R_NEWS0 (void *, n);
if (!s->elems)
return NULL;