Discussion:
[PATCH] malloca: pacify gcc -Wbad-function-cast
(too old to reply)
Paul Eggert
2018-02-23 20:48:23 UTC
Permalink
Raw Message
* lib/malloca.h (malloca): Pacify gcc -Wbad-function-cast
diagnostic that I got on Fedora 27 with gcc 7.3.1 20180130.
To pacify GCC, I had to cast alloca’s result to some type other
than void * before casting that to uintptr_t.
---
ChangeLog | 8 ++++++++
lib/malloca.h | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 15fad2bb5..50a3bb568 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2018-02-23 Paul Eggert <***@cs.ucla.edu>
+
+ malloca: pacify gcc -Wbad-function-cast
+ * lib/malloca.h (malloca): Pacify gcc -Wbad-function-cast
+ diagnostic that I got on Fedora 27 with gcc 7.3.1 20180130.
+ To pacify GCC, I had to cast alloca’s result to some type other
+ than void * before casting that to uintptr_t.
+
2018-02-20 Paul Eggert <***@cs.ucla.edu>

utimecmp: new function utimecmpat
diff --git a/lib/malloca.h b/lib/malloca.h
index cbc8fe7ab..640186586 100644
--- a/lib/malloca.h
+++ b/lib/malloca.h
@@ -57,7 +57,7 @@ extern "C" {
#if HAVE_ALLOCA
# define malloca(N) \
((N) < 4032 - (2 * sa_alignment_max - 1) \
- ? (void *) (((uintptr_t) alloca ((N) + 2 * sa_alignment_max - 1) \
+ ? (void *) (((uintptr_t) (char *) alloca ((N) + 2 * sa_alignment_max - 1) \
+ (2 * sa_alignment_max - 1)) \
& ~(uintptr_t)(2 * sa_alignment_max - 1)) \
: mmalloca (N))
--
2.14.3
Bruno Haible
2018-02-24 00:34:16 UTC
Permalink
Raw Message
Paul Eggert wrote:
> * lib/malloca.h (malloca): Pacify gcc -Wbad-function-cast
> diagnostic that I got on Fedora 27 with gcc 7.3.1 20180130.
> To pacify GCC, I had to cast alloca’s result to some type other
> than void * before casting that to uintptr_t.

Thanks. I wouldn't have expected this warning.

Let me apply the same change to xmalloca.h as well:


2018-02-23 Bruno Haible <***@clisp.org>

xmalloca: pacify gcc -Wbad-function-cast
* lib/xmalloca.h (xmalloca): Insert intermediate cast here as well.

diff --git a/lib/xmalloca.h b/lib/xmalloca.h
index 14fc1b9..2900a07 100644
--- a/lib/xmalloca.h
+++ b/lib/xmalloca.h
@@ -32,10 +32,10 @@ extern "C" {
the function returns. Upon failure, it exits with an error message. */
#if HAVE_ALLOCA
# define xmalloca(N) \
- ((N) < 4032 - (2 * sa_alignment_max - 1) \
- ? (void *) (((uintptr_t) alloca ((N) + 2 * sa_alignment_max - 1) \
- + (2 * sa_alignment_max - 1)) \
- & ~(uintptr_t)(2 * sa_alignment_max - 1)) \
+ ((N) < 4032 - (2 * sa_alignment_max - 1) \
+ ? (void *) (((uintptr_t) (char *) alloca ((N) + 2 * sa_alignment_max - 1) \
+ + (2 * sa_alignment_max - 1)) \
+ & ~(uintptr_t)(2 * sa_alignment_max - 1)) \
: xmmalloca (N))
extern void * xmmalloca (size_t n);
#else
Loading...