bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new macro xnmalloca


From: Bruno Haible
Subject: new macro xnmalloca
Date: Mon, 31 Dec 2007 11:58:52 +0100
User-agent: KMail/1.5.4

Since there was need for a macro 'nmalloca', there will also be need for
'xnmalloca'.

This also fixes a bug: On platforms without working alloca(), xmalloc()
could be used without being declared.


2007-12-30  Bruno Haible  <address@hidden>

        * lib/xmalloca.h: Include xalloc.h.
        (xnmalloca): New macro.

*** lib/xmalloca.h.orig 2007-12-30 16:44:24.000000000 +0100
--- lib/xmalloca.h      2007-12-30 16:30:56.000000000 +0100
***************
*** 19,24 ****
--- 19,25 ----
  #define _XMALLOCA_H
  
  #include "malloca.h"
+ #include "xalloc.h"
  
  
  #ifdef __cplusplus
***************
*** 40,48 ****
    xmalloc (N)
  #endif
  
! /* Maybe we should also define a variant
!     xnmalloca (size_t n, size_t s) - behaves like xmalloca (n * s)
!    If this would be useful in your application. please speak up.  */
  
  
  #ifdef __cplusplus
--- 41,59 ----
    xmalloc (N)
  #endif
  
! /* xnmalloca(N,S) is an overflow-safe variant of xmalloca (N * S).
!    It allocates an array of N objects, each with S bytes of memory,
!    on the stack.  S must be positive and N must be nonnegative.
!    The array must be freed using freea() before the function returns.
!    Upon failure, it exits with an error message.  */
! #if HAVE_ALLOCA
! /* Rely on xmalloca (SIZE_MAX) calling xalloc_die ().  */
! # define xnmalloca(n, s) \
!     xmalloca (xalloc_oversized ((n), (s)) ? (size_t) (-1) : (n) * (s))
! #else
! # define xnmalloca(n, s) \
!     xnmalloc ((n), (s))
! #endif
  
  
  #ifdef __cplusplus





reply via email to

[Prev in Thread] Current Thread [Next in Thread]