Eric Blake <ebb9 <at> byu.net> writes: > | That cast looks unnecessary -- unless you care about C++ compilers. > > Yes, at one point, I got M4 to compile with C++; I've tried to keep it > that way (although inadvertent regressions may have crept in since). In > other words, I deliberately added that cast. It's a shame that memchr is > prototyped to return void* instead of char*.
Speaking of casts, I _have_ let some inadvertent regressions in. Fixed as follows (thankfully, xalloc.h has magic such that xcharalloc and xrealloc don't need casts). From: Eric Blake <[EMAIL PROTECTED]> Date: Thu, 13 Mar 2008 12:14:45 -0600 Subject: [PATCH] Consistently cast malloc results, for C++ compilation. * src/builtin.c (compile_pattern): Add cast. * src/macro.c (expand_macro): Likewise. * src/output.c (m4_tmpname): Likewise. * src/stackovf.c (setup_stackovf_trap): Use correct type. Signed-off-by: Eric Blake <[EMAIL PROTECTED]> --- ChangeLog | 8 ++++++++ src/builtin.c | 2 +- src/macro.c | 6 ++++-- src/output.c | 7 ++++--- src/stackovf.c | 5 +++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa9745a..751893e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-03-13 Eric Blake <[EMAIL PROTECTED]> + + Consistently cast malloc results, for C++ compilation. + * src/builtin.c (compile_pattern): Add cast. + * src/macro.c (expand_macro): Likewise. + * src/output.c (m4_tmpname): Likewise. + * src/stackovf.c (setup_stackovf_trap): Use correct type. + 2008-03-06 Eric Blake <[EMAIL PROTECTED]> Fix nested builtin(`shift',$@) regression from 2008-02-22. diff --git a/src/builtin.c b/src/builtin.c index 09322ea..a1d4d01 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -308,7 +308,7 @@ compile_pattern (const char *str, size_t len, struct re_pattern_buffer **buf, } /* Next, check if STR can be compiled. */ - new_buf = xzalloc (sizeof *new_buf); + new_buf = (struct re_pattern_buffer *) xzalloc (sizeof *new_buf); msg = re_compile_pattern (str, len, new_buf); #ifdef DEBUG_REGEX if (trace_file) diff --git a/src/macro.c b/src/macro.c index 4558e9c..6123f05 100644 --- a/src/macro.c +++ b/src/macro.c @@ -661,8 +661,10 @@ expand_macro (symbol *sym) if (!stacks[level].args) { assert (!stacks[level].refcount); - stacks[level].args = xmalloc (sizeof (struct obstack)); - stacks[level].argv = xmalloc (sizeof (struct obstack)); + stacks[level].args = + (struct obstack *) xmalloc (sizeof *stacks[level].args); + stacks[level].argv = + (struct obstack *) xmalloc (sizeof *stacks[level].args); obstack_init (stacks[level].args); obstack_init (stacks[level].argv); stacks[level].args_base = obstack_finish (stacks[level].args); diff --git a/src/output.c b/src/output.c index 7b2d6de..24b6fa8 100644 --- a/src/output.c +++ b/src/output.c @@ -198,7 +198,8 @@ m4_tmpname (int divnum) obstack_1grow (&diversion_storage, '4'); obstack_1grow (&diversion_storage, '-'); offset = obstack_object_size (&diversion_storage); - buffer = obstack_alloc (&diversion_storage, INT_BUFSIZE_BOUND (divnum)); + buffer = (char *) obstack_alloc (&diversion_storage, + INT_BUFSIZE_BOUND (divnum)); } if (snprintf (&buffer[offset], INT_BUFSIZE_BOUND (divnum), "%d", divnum) < 0) m4_error (EXIT_FAILURE, errno, NULL, @@ -385,8 +386,8 @@ make_room_for (int length) } /* The current buffer may be safely reallocated. */ - output_diversion->u.buffer - = xrealloc (output_diversion->u.buffer, (size_t) wanted_size); + output_diversion->u.buffer = xrealloc (output_diversion->u.buffer, + (size_t) wanted_size); total_buffer_size += wanted_size - output_diversion->size; output_diversion->size = wanted_size; diff --git a/src/stackovf.c b/src/stackovf.c index 3877cd9..514e806 100644 --- a/src/stackovf.c +++ b/src/stackovf.c @@ -1,6 +1,7 @@ /* Detect stack overflow (when getrlimit and sigaction or sigvec are available) - Copyright (C) 1993, 1994, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1993, 1994, 2006, 2007, 2008 Free Software + Foundation, Inc. Jim Avera <[EMAIL PROTECTED]>, October 1993. This file is part of GNU M4. @@ -370,7 +371,7 @@ Error - Do not know how to set up stack-ovf trap handler... { struct sigstack ss; - char *stackbuf = xmalloc (2 * SIGSTKSZ); + void *stackbuf = xmalloc (2 * SIGSTKSZ); ss.ss_sp = stackbuf + SIGSTKSZ; ss.ss_onstack = 0; -- 1.5.4 _______________________________________________ M4-discuss mailing list M4-discuss@gnu.org http://lists.gnu.org/mailman/listinfo/m4-discuss