summaryrefslogtreecommitdiffstats
path: root/gl/malloca.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/malloca.c')
-rw-r--r--gl/malloca.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/gl/malloca.c b/gl/malloca.c
index b488423..183783a 100644
--- a/gl/malloca.c
+++ b/gl/malloca.c
@@ -1,5 +1,5 @@
1/* Safe automatic memory allocation. 1/* Safe automatic memory allocation.
2 Copyright (C) 2003, 2006-2007, 2009-2021 Free Software Foundation, Inc. 2 Copyright (C) 2003, 2006-2007, 2009-2022 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2003, 2018. 3 Written by Bruno Haible <bruno@clisp.org>, 2003, 2018.
4 4
5 This file is free software: you can redistribute it and/or modify 5 This file is free software: you can redistribute it and/or modify
@@ -21,8 +21,9 @@
21/* Specification. */ 21/* Specification. */
22#include "malloca.h" 22#include "malloca.h"
23 23
24#include <stdckdint.h>
25
24#include "idx.h" 26#include "idx.h"
25#include "intprops.h"
26#include "verify.h" 27#include "verify.h"
27 28
28/* The speed critical point in this file is freea() applied to an alloca() 29/* The speed critical point in this file is freea() applied to an alloca()
@@ -50,17 +51,16 @@ mmalloca (size_t n)
50 uintptr_t alignment2_mask = 2 * sa_alignment_max - 1; 51 uintptr_t alignment2_mask = 2 * sa_alignment_max - 1;
51 int plus = sizeof (small_t) + alignment2_mask; 52 int plus = sizeof (small_t) + alignment2_mask;
52 idx_t nplus; 53 idx_t nplus;
53 if (!INT_ADD_WRAPV (n, plus, &nplus) && !xalloc_oversized (nplus, 1)) 54 if (!ckd_add (&nplus, n, plus) && !xalloc_oversized (nplus, 1))
54 { 55 {
55 char *mem = (char *) malloc (nplus); 56 char *mem = (char *) malloc (nplus);
56 57
57 if (mem != NULL) 58 if (mem != NULL)
58 { 59 {
59 uintptr_t umem = (uintptr_t)mem, umemplus; 60 uintptr_t umem = (uintptr_t)mem, umemplus;
60 /* The INT_ADD_WRAPV avoids signed integer overflow on 61 /* The ckd_add avoids signed integer overflow on
61 theoretical platforms where UINTPTR_MAX <= INT_MAX. */ 62 theoretical platforms where UINTPTR_MAX <= INT_MAX. */
62 INT_ADD_WRAPV (umem, sizeof (small_t) + sa_alignment_max - 1, 63 ckd_add (&umemplus, umem, sizeof (small_t) + sa_alignment_max - 1);
63 &umemplus);
64 idx_t offset = ((umemplus & ~alignment2_mask) 64 idx_t offset = ((umemplus & ~alignment2_mask)
65 + sa_alignment_max - umem); 65 + sa_alignment_max - umem);
66 void *vp = mem + offset; 66 void *vp = mem + offset;