summaryrefslogtreecommitdiffstats
path: root/gl/xmalloc.c
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2022-08-23 15:13:04 (GMT)
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2022-08-23 15:13:04 (GMT)
commitbbdcf5a704517d35a76ba8b666075da9ffe39ac4 (patch)
treea36bec4f7c2802dfe5efc5cb2dfc902fec2a23b8 /gl/xmalloc.c
parentfa1ac7ecb247faf58fe65740c0d40e0585f684c9 (diff)
downloadmonitoring-plugins-bbdcf5a.tar.gz
Sync with the latest Gnulib code (fa1ac7ec)
Diffstat (limited to 'gl/xmalloc.c')
-rw-r--r--gl/xmalloc.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/gl/xmalloc.c b/gl/xmalloc.c
index d5def0b..3c3cb20 100644
--- a/gl/xmalloc.c
+++ b/gl/xmalloc.c
@@ -1,10 +1,10 @@
1/* xmalloc.c -- malloc with out of memory checking 1/* xmalloc.c -- malloc with out of memory checking
2 2
3 Copyright (C) 1990-2000, 2002-2006, 2008-2021 Free Software Foundation, Inc. 3 Copyright (C) 1990-2000, 2002-2006, 2008-2022 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or 7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
@@ -22,9 +22,9 @@
22#include "xalloc.h" 22#include "xalloc.h"
23 23
24#include "ialloc.h" 24#include "ialloc.h"
25#include "intprops.h"
26#include "minmax.h" 25#include "minmax.h"
27 26
27#include <stdckdint.h>
28#include <stdlib.h> 28#include <stdlib.h>
29#include <string.h> 29#include <string.h>
30 30
@@ -195,7 +195,7 @@ x2nrealloc (void *p, size_t *pn, size_t s)
195 else 195 else
196 { 196 {
197 /* Set N = floor (1.5 * N) + 1 to make progress even if N == 0. */ 197 /* Set N = floor (1.5 * N) + 1 to make progress even if N == 0. */
198 if (INT_ADD_WRAPV (n, (n >> 1) + 1, &n)) 198 if (ckd_add (&n, n, (n >> 1) + 1))
199 xalloc_die (); 199 xalloc_die ();
200 } 200 }
201 201
@@ -236,7 +236,7 @@ xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
236 N_MAX, and what the C language can represent safely. */ 236 N_MAX, and what the C language can represent safely. */
237 237
238 idx_t n; 238 idx_t n;
239 if (INT_ADD_WRAPV (n0, n0 >> 1, &n)) 239 if (ckd_add (&n, n0, n0 >> 1))
240 n = IDX_MAX; 240 n = IDX_MAX;
241 if (0 <= n_max && n_max < n) 241 if (0 <= n_max && n_max < n)
242 n = n_max; 242 n = n_max;
@@ -251,7 +251,7 @@ xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
251 size_t nbytes; 251 size_t nbytes;
252#endif 252#endif
253 idx_t adjusted_nbytes 253 idx_t adjusted_nbytes
254 = (INT_MULTIPLY_WRAPV (n, s, &nbytes) 254 = (ckd_mul (&nbytes, n, s)
255 ? MIN (IDX_MAX, SIZE_MAX) 255 ? MIN (IDX_MAX, SIZE_MAX)
256 : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0); 256 : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0);
257 if (adjusted_nbytes) 257 if (adjusted_nbytes)
@@ -263,9 +263,9 @@ xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
263 if (! pa) 263 if (! pa)
264 *pn = 0; 264 *pn = 0;
265 if (n - n0 < n_incr_min 265 if (n - n0 < n_incr_min
266 && (INT_ADD_WRAPV (n0, n_incr_min, &n) 266 && (ckd_add (&n, n0, n_incr_min)
267 || (0 <= n_max && n_max < n) 267 || (0 <= n_max && n_max < n)
268 || INT_MULTIPLY_WRAPV (n, s, &nbytes))) 268 || ckd_mul (&nbytes, n, s)))
269 xalloc_die (); 269 xalloc_die ();
270 pa = xrealloc (pa, nbytes); 270 pa = xrealloc (pa, nbytes);
271 *pn = n; 271 *pn = n;