"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "gl/xmalloc.c" between
gsasl-2.0.1.tar.gz and gsasl-2.2.0.tar.gz

About: GNU SASL is an implementation of the Simple Authentication and Security Layer (SASL).

xmalloc.c  (gsasl-2.0.1):xmalloc.c  (gsasl-2.2.0)
skipping to change at line 25 skipping to change at line 25
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h> #include <config.h>
#define XALLOC_INLINE _GL_EXTERN_INLINE #define XALLOC_INLINE _GL_EXTERN_INLINE
#include "xalloc.h" #include "xalloc.h"
#include "ialloc.h" #include "ialloc.h"
#include "intprops.h"
#include "minmax.h" #include "minmax.h"
#include <stdckdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
static void * _GL_ATTRIBUTE_PURE static void * _GL_ATTRIBUTE_PURE
nonnull (void *p) nonnull (void *p)
{ {
if (!p) if (!p)
xalloc_die (); xalloc_die ();
return p; return p;
} }
skipping to change at line 198 skipping to change at line 198
library malloc. */ library malloc. */
enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 }; enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
n = DEFAULT_MXFAST / s; n = DEFAULT_MXFAST / s;
n += !n; n += !n;
} }
} }
else else
{ {
/* Set N = floor (1.5 * N) + 1 to make progress even if N == 0. */ /* Set N = floor (1.5 * N) + 1 to make progress even if N == 0. */
if (INT_ADD_WRAPV (n, (n >> 1) + 1, &n)) if (ckd_add (&n, n, (n >> 1) + 1))
xalloc_die (); xalloc_die ();
} }
p = xreallocarray (p, n, s); p = xreallocarray (p, n, s);
*pn = n; *pn = n;
return p; return p;
} }
/* Grow PA, which points to an array of *PN items, and return the /* Grow PA, which points to an array of *PN items, and return the
location of the reallocated array, updating *PN to reflect its location of the reallocated array, updating *PN to reflect its
skipping to change at line 239 skipping to change at line 239
requests. This is the largest "small" request for the GNU C requests. This is the largest "small" request for the GNU C
library malloc. */ library malloc. */
enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 }; enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
/* If the array is tiny, grow it to about (but no greater than) /* If the array is tiny, grow it to about (but no greater than)
DEFAULT_MXFAST bytes. Otherwise, grow it by about 50%. DEFAULT_MXFAST bytes. Otherwise, grow it by about 50%.
Adjust the growth according to three constraints: N_INCR_MIN, Adjust the growth according to three constraints: N_INCR_MIN,
N_MAX, and what the C language can represent safely. */ N_MAX, and what the C language can represent safely. */
idx_t n; idx_t n;
if (INT_ADD_WRAPV (n0, n0 >> 1, &n)) if (ckd_add (&n, n0, n0 >> 1))
n = IDX_MAX; n = IDX_MAX;
if (0 <= n_max && n_max < n) if (0 <= n_max && n_max < n)
n = n_max; n = n_max;
/* NBYTES is of a type suitable for holding the count of bytes in an object. /* NBYTES is of a type suitable for holding the count of bytes in an object.
This is typically idx_t, but it should be size_t on (theoretical?) This is typically idx_t, but it should be size_t on (theoretical?)
platforms where SIZE_MAX < IDX_MAX so xpalloc does not pass platforms where SIZE_MAX < IDX_MAX so xpalloc does not pass
values greater than SIZE_MAX to xrealloc. */ values greater than SIZE_MAX to xrealloc. */
#if IDX_MAX <= SIZE_MAX #if IDX_MAX <= SIZE_MAX
idx_t nbytes; idx_t nbytes;
#else #else
size_t nbytes; size_t nbytes;
#endif #endif
idx_t adjusted_nbytes idx_t adjusted_nbytes
= (INT_MULTIPLY_WRAPV (n, s, &nbytes) = (ckd_mul (&nbytes, n, s)
? MIN (IDX_MAX, SIZE_MAX) ? MIN (IDX_MAX, SIZE_MAX)
: nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0); : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0);
if (adjusted_nbytes) if (adjusted_nbytes)
{ {
n = adjusted_nbytes / s; n = adjusted_nbytes / s;
nbytes = adjusted_nbytes - adjusted_nbytes % s; nbytes = adjusted_nbytes - adjusted_nbytes % s;
} }
if (! pa) if (! pa)
*pn = 0; *pn = 0;
if (n - n0 < n_incr_min if (n - n0 < n_incr_min
&& (INT_ADD_WRAPV (n0, n_incr_min, &n) && (ckd_add (&n, n0, n_incr_min)
|| (0 <= n_max && n_max < n) || (0 <= n_max && n_max < n)
|| INT_MULTIPLY_WRAPV (n, s, &nbytes))) || ckd_mul (&nbytes, n, s)))
xalloc_die (); xalloc_die ();
pa = xrealloc (pa, nbytes); pa = xrealloc (pa, nbytes);
*pn = n; *pn = n;
return pa; return pa;
} }
/* Allocate S bytes of zeroed memory dynamically, with error checking. /* Allocate S bytes of zeroed memory dynamically, with error checking.
There's no need for xnzalloc (N, S), since it would be equivalent There's no need for xnzalloc (N, S), since it would be equivalent
to xcalloc (N, S). */ to xcalloc (N, S). */
 End of changes. 7 change blocks. 
6 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)