Skip to content

Commit

Permalink
Use align_len in all alloc helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ckolivas committed Mar 4, 2015
1 parent b7842d5 commit 8d75ac9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
1 change: 0 additions & 1 deletion cgminer.c
Expand Up @@ -2188,7 +2188,6 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
pool->n2size = 8;
pool->coinbase_len = cbt_len + pool->n2size;
cal_len = pool->coinbase_len + 1;
align_len(&cal_len);
free(pool->coinbase);
pool->coinbase = cgcalloc(cal_len, 1);
hex2bin(pool->coinbase, pool->coinbasetxn, 42);
Expand Down
27 changes: 15 additions & 12 deletions util.c
Expand Up @@ -253,30 +253,36 @@ int Inet_Pton(int af, const char *src, void *dst)
}
#endif

void *_cgmalloc(const int size, const char *file, const char *func, const int line)
void *_cgmalloc(size_t size, const char *file, const char *func, const int line)
{
void *ret = malloc(size);
void *ret;

align_len(&size);
ret = malloc(size);
if (unlikely(!ret))
quit(1, "Failed to malloc size %d from %s %s:%d", size, file, func, line);
quit(1, "Failed to malloc size %d from %s %s:%d", (int)size, file, func, line);
return ret;
}

void *_cgcalloc(const int memb, const int size, const char *file, const char *func, const int line)
void *_cgcalloc(const size_t memb, size_t size, const char *file, const char *func, const int line)
{
void *ret = calloc(memb, size);
void *ret;

align_len(&size);
ret = calloc(memb, size);
if (unlikely(!ret))
quit(1, "Failed to calloc memb %d size %d from %s %s:%d", memb, size, file, func, line);
quit(1, "Failed to calloc memb %d size %d from %s %s:%d", (int)memb, (int)size, file, func, line);
return ret;
}

void *_cgrealloc(void *ptr, const int size, const char *file, const char *func, const int line)
void *_cgrealloc(void *ptr, size_t size, const char *file, const char *func, const int line)
{
void *ret = realloc(ptr, size);
void *ret;

align_len(&size);
ret = realloc(ptr, size);
if (unlikely(!ret))
quit(1, "Failed to realloc size %d from %s %s:%d", size, file, func, line);
quit(1, "Failed to realloc size %d from %s %s:%d", (int)size, file, func, line);
return ret;
}

Expand Down Expand Up @@ -2056,7 +2062,6 @@ static bool parse_notify(struct pool *pool, json_t *val)
goto out_unlock;
}
free(pool->coinbase);
align_len(&alloc_len);
pool->coinbase = cgcalloc(alloc_len, 1);
memcpy(pool->coinbase, cb1, cb1_len);
memcpy(pool->coinbase + cb1_len, pool->nonce1bin, pool->n1_len);
Expand Down Expand Up @@ -2993,8 +2998,6 @@ void *realloc_strcat(char *ptr, char *s)
old = strlen(ptr);

len += old + 1;
align_len(&len);

ret = cgmalloc(len);

if (ptr) {
Expand Down
6 changes: 3 additions & 3 deletions util.h
Expand Up @@ -104,9 +104,9 @@ typedef struct timespec cgtimer_t;

int no_yield(void);
int (*selective_yield)(void);
void *_cgmalloc(const int size, const char *file, const char *func, const int line);
void *_cgcalloc(const int memb, const int size, const char *file, const char *func, const int line);
void *_cgrealloc(void *ptr, const int size, const char *file, const char *func, const int line);
void *_cgmalloc(size_t size, const char *file, const char *func, const int line);
void *_cgcalloc(const size_t memb, size_t size, const char *file, const char *func, const int line);
void *_cgrealloc(void *ptr, size_t size, const char *file, const char *func, const int line);
#define cgmalloc(_size) _cgmalloc(_size, __FILE__, __func__, __LINE__)
#define cgcalloc(_memb, _size) _cgcalloc(_memb, _size, __FILE__, __func__, __LINE__)
#define cgrealloc(_ptr, _size) _cgrealloc(_ptr, _size, __FILE__, __func__, __LINE__)
Expand Down

0 comments on commit 8d75ac9

Please sign in to comment.