From: mquinson Date: Mon, 18 May 2009 13:06:17 +0000 (+0000) Subject: Do not allow malloc(0) since that's not portable X-Git-Tag: SVN~1347 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/827122d635564b67542189fd3e013307458b3550 Do not allow malloc(0) since that's not portable git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6290 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/ChangeLog b/ChangeLog index 3ab6e6a509..b43bef0818 100644 --- a/ChangeLog +++ b/ChangeLog @@ -37,7 +37,8 @@ SimGrid (3.4-svn) unstable; urgency=high * Also include strbuff from xbt.h public header * xbt_ex_display(): do not free the exception after displaying This allows to do more with the given exception afterward. - Users should call xbt_ex_free() themselves. + Users should call xbt_ex_free() themselves. + * Do not allow malloc(0) since that's not portable -- Da SimGrid team diff --git a/include/xbt/sysdep.h b/include/xbt/sysdep.h index 0d515ca07d..8b264539dc 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -56,11 +56,17 @@ static XBT_INLINE char *xbt_strdup(const char *s) { } return res; } +extern void xbt_backtrace_display_current(void); + /** @brief Like malloc, but xbt_die() on error @hideinitializer */ static XBT_INLINE void *xbt_malloc(unsigned int n){ void *res; -/* if (n==0) xbt_die("malloc(0) is not portable"); */ + if (n==0) { + xbt_backtrace_display_current(); + xbt_die("malloc(0) is not portable"); + } + res=malloc(n); if (!res) xbt_die(bprintf("Memory allocation of %d bytes failed",n)); @@ -71,7 +77,7 @@ static XBT_INLINE void *xbt_malloc(unsigned int n){ @hideinitializer */ static XBT_INLINE void *xbt_malloc0(unsigned int n) { void *res; -/* if (n==0) xbt_die("calloc(0) is not portable"); */ + if (n==0) xbt_die("calloc(0) is not portable"); res=calloc(n,1); if (!res) xbt_die(bprintf("Memory callocation of %d bytes failed",n)); @@ -82,7 +88,7 @@ static XBT_INLINE void *xbt_malloc0(unsigned int n) { @hideinitializer */ static XBT_INLINE void *xbt_realloc(void*p,unsigned int s){ void *res=res; -/* if (s==0) xbt_die("realloc(0) is not portable"); */ + if (s==0) xbt_die("realloc(0) is not portable"); if (s) { if (p) { res=realloc(p,s); diff --git a/teshsuite/gras/datadesc/datadesc_usage.c b/teshsuite/gras/datadesc/datadesc_usage.c index 51df175fbf..eab24a28d7 100644 --- a/teshsuite/gras/datadesc/datadesc_usage.c +++ b/teshsuite/gras/datadesc/datadesc_usage.c @@ -554,7 +554,7 @@ static void test_clause_empty(gras_socket_t sock, int direction) { i=xbt_new(Clause,1); i->num_lits = 0; - i->literals = xbt_new(int, 0); + i->literals = NULL; DEBUG3("created data=%p (within %p @%p)",&(i->num_lits),i,&i); DEBUG1("created count=%d",i->num_lits);