1
0
forked from bip/bip

Sanitize bip_(m|re)alloc size.

This commit is contained in:
Arnaud Cornet 2008-12-29 15:31:32 +01:00
parent b9f86d544d
commit 0ecb77617c
3 changed files with 14 additions and 10 deletions

View File

@ -36,9 +36,7 @@ list_t *root_list;
struct tuple *tuple_i_new(int type, int i)
{
struct tuple *t;
t = malloc(sizeof(struct tuple));
if (!t)
fatal("malloc");
t = bip_malloc(sizeof(struct tuple));
t->type = type;
t->ndata = i;
t->tuple_type = TUPLE_INT;
@ -48,9 +46,7 @@ struct tuple *tuple_i_new(int type, int i)
struct tuple *tuple_p_new(int type, void *p)
{
struct tuple *t;
t = malloc(sizeof(struct tuple));
if (!t)
fatal("malloc");
t = bip_malloc(sizeof(struct tuple));
t->type = type;
t->pdata = p;
return t;

View File

@ -88,8 +88,7 @@ char *nick_from_ircmask(const char *mask)
char *ret;
size_t len;
if (!mask)
fatal("nick_from_ircmask");
assert(mask);
while (*nick && *nick != '!')
nick++;

View File

@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
@ -41,7 +42,11 @@ void memory_fatal(void)
void *bip_malloc(size_t size)
{
void *r = malloc(size);
void *r;
assert(size < INT_MAX / 4);
r = malloc(size);
if (!r)
memory_fatal();
return r;
@ -57,7 +62,11 @@ void *bip_calloc(size_t nmemb, size_t size)
void *bip_realloc(void *ptr, size_t size)
{
void *r = realloc(ptr, size);
void *r;
assert(size < INT_MAX / 4);
r = realloc(ptr, size);
if (size > 0 && r == NULL)
memory_fatal();
return r;