[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
malloca.c non-top variable declaration
From: |
Simon Josefsson |
Subject: |
malloca.c non-top variable declaration |
Date: |
Wed, 11 Sep 2024 09:38:00 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Hi
I noticed a build failure of libidn on an old architecture that doesn't
permit non-top variable declarations. How about the patch below? The
rest builds fine and passes self-tests on the platform, so presumably
this was a recently introduced regression in malloca.c related to
ckd_add. Thoughts?
For readability, a 'diff -w' patch is easier to read:
diff --git a/lib/malloca.c b/lib/malloca.c
index e75c72df84..6938cdce7a 100644
--- a/lib/malloca.c
+++ b/lib/malloca.c
@@ -69,6 +69,7 @@ mmalloca (size_t n)
theoretical platforms where UINTPTR_MAX <= INT_MAX. */
uintptr_t umemplus;
ckd_add (&umemplus, umem, sizeof (small_t) + sa_alignment_max - 1);
+ {
idx_t offset = (umemplus - umemplus % (2 * sa_alignment_max)
+ sa_alignment_max - umem);
void *p = mem + offset;
@@ -90,6 +91,7 @@ mmalloca (size_t n)
return p;
}
}
+ }
/* Out of memory. */
return NULL;
#else
/Simon
From c162d25fde4cd3eecf8cb0645a831b894576c285 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <simon@josefsson.org>
Date: Wed, 11 Sep 2024 09:12:25 +0200
Subject: [PATCH] malloca: Fix compilation on old compilers.
* lib/malloca.c (mmalloca): Add scope, for variable declaration.
---
ChangeLog | 5 +++++
lib/malloca.c | 32 +++++++++++++++++---------------
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 73d43cf40b..1ac9d6a257 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-09-11 Simon Josefsson <simon@josefsson.org>
+
+ malloca: Fix compilation on old compilers.
+ * lib/malloca.c (mmalloca): Add scope, for variable declaration.
+
2024-09-10 Bruno Haible <bruno@clisp.org>
mbrtoc16: Fix undefined behaviour.
diff --git a/lib/malloca.c b/lib/malloca.c
index e75c72df84..6938cdce7a 100644
--- a/lib/malloca.c
+++ b/lib/malloca.c
@@ -69,25 +69,27 @@ mmalloca (size_t n)
theoretical platforms where UINTPTR_MAX <= INT_MAX. */
uintptr_t umemplus;
ckd_add (&umemplus, umem, sizeof (small_t) + sa_alignment_max - 1);
- idx_t offset = (umemplus - umemplus % (2 * sa_alignment_max)
- + sa_alignment_max - umem);
- void *p = mem + offset;
- /* Here p >= mem + sizeof (small_t),
- and p <= mem + sizeof (small_t) + 2 * sa_alignment_max - 1
- hence p + n <= mem + nplus.
- So, the memory range [p, p+n) lies in the allocated memory range
- [mem, mem + nplus). */
- small_t *sp = p;
+ {
+ idx_t offset = (umemplus - umemplus % (2 * sa_alignment_max)
+ + sa_alignment_max - umem);
+ void *p = mem + offset;
+ /* Here p >= mem + sizeof (small_t),
+ and p <= mem + sizeof (small_t) + 2 * sa_alignment_max - 1
+ hence p + n <= mem + nplus.
+ So, the memory range [p, p+n) lies in the allocated memory range
+ [mem, mem + nplus). */
+ small_t *sp = p;
# if defined __CHERI_PURE_CAPABILITY__
- sp[-1] = umem;
- p = (char *) cheri_bounds_set ((char *) p - sizeof (small_t),
- sizeof (small_t) + n)
+ sp[-1] = umem;
+ p = (char *) cheri_bounds_set ((char *) p - sizeof (small_t),
+ sizeof (small_t) + n)
+ sizeof (small_t);
# else
- sp[-1] = offset;
+ sp[-1] = offset;
# endif
- /* p ≡ sa_alignment_max mod 2*sa_alignment_max. */
- return p;
+ /* p ≡ sa_alignment_max mod 2*sa_alignment_max. */
+ return p;
+ }
}
}
/* Out of memory. */
--
2.45.2
signature.asc
Description: PGP signature
- malloca.c non-top variable declaration,
Simon Josefsson <=