Martin Buchholz <martin(a)xemacs.org> writes:
> The Sun compiler points out that this code looks suspicious:
>
> if (decoded_length < 0)
> {
> return Qnil;
> XMALLOC_UNBIND (decoded, length * MAX_EMCHAR_LEN);
> }
And rightfully so. Fix attached below.
> Also, here is a rewritten XMALLOC_OR_ALLOCA macro that avoids
> multiple evaluation of the `len' argument.
I'll add the patch on the grounds of general saneness, but what's the
point? I mean, the macro is purely local in nature, and if you use
it, you should know what you're doing.
Your rewritten version also adds parentheses around PTR, which is an
lvalue -- is that legal? (I removed them.)
--- src/fns.c.orig Mon Nov 30 00:13:19 1998
+++ src/fns.c Mon Nov 30 00:18:26 1998
@@ -3771,15 +3771,16 @@
ways these functions can blow up, and we don't want to have memory
leaks in those cases. */
#define XMALLOC_OR_ALLOCA(ptr, len, type) do { \
- if ((len) > MAX_ALLOCA) \
+ size_t XOA_len = (len); \
+ if (XOA_len > MAX_ALLOCA) \
{ \
- ptr = (type *)xmalloc ((len) * sizeof (type)); \
+ ptr = (type *)xmalloc (XOA_len * sizeof (type)); \
speccount = specpdl_depth (); \
record_unwind_protect (free_malloced_ptr, \
make_opaque_ptr ((void *)ptr)); \
} \
else \
- ptr = alloca_array (type, len); \
+ ptr = alloca_array (type, XOA_len); \
} while (0)
#define XMALLOC_UNBIND(ptr, len) do { \
@@ -3939,8 +3940,9 @@
if (decoded_length < 0)
{
- return Qnil;
+ /* The decoding wasn't possible. */
XMALLOC_UNBIND (decoded, length * MAX_EMCHAR_LEN);
+ return Qnil;
}
result = make_string (decoded, decoded_length);