just assume realloc(NULL, n) is ANSI C89 (for n>0) but provide a
define to do otherwise; shrinks the code and optimises for speed
This commit is contained in:
parent
9f37ccb368
commit
edf126c810
13
lalloc.c
13
lalloc.c
|
@ -1,6 +1,6 @@
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.6 2009/03/24 14:07:41 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.7 2009/03/24 18:34:39 tg Exp $");
|
||||||
|
|
||||||
#ifndef SIZE_MAX
|
#ifndef SIZE_MAX
|
||||||
#ifdef SIZE_T_MAX
|
#ifdef SIZE_T_MAX
|
||||||
|
@ -10,6 +10,13 @@ __RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.6 2009/03/24 14:07:41 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */
|
||||||
|
#if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0)
|
||||||
|
#define remalloc(p,n) ((p) == NULL ? malloc(n) : realloc((p), (n)))
|
||||||
|
#else
|
||||||
|
#define remalloc(p,n) realloc((p), (n))
|
||||||
|
#endif
|
||||||
|
|
||||||
static struct lalloc *findptr(struct lalloc **, char *, Area *);
|
static struct lalloc *findptr(struct lalloc **, char *, Area *);
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -41,9 +48,7 @@ aresize(void *ptr, size_t numb, Area *ap)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((numb >= SIZE_MAX - sizeof (struct lalloc)) ||
|
if ((numb >= SIZE_MAX - sizeof (struct lalloc)) ||
|
||||||
/* here I wish all realloc(3)s would take NULL */
|
(lp = remalloc(lp, numb + sizeof (struct lalloc))) == NULL)
|
||||||
(lp = ptr ? realloc(lp, numb + sizeof (struct lalloc)) :
|
|
||||||
malloc(numb + sizeof (struct lalloc))) == NULL)
|
|
||||||
internal_errorf("cannot allocate %lu data bytes",
|
internal_errorf("cannot allocate %lu data bytes",
|
||||||
(unsigned long)numb);
|
(unsigned long)numb);
|
||||||
lp->next = ap->next;
|
lp->next = ap->next;
|
||||||
|
|
Loading…
Reference in New Issue