GNU bug report logs - #18410
Use SAFE_ALLOCA etc. to avoid unbounded stack allocation.

Previous Next

Package: emacs;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Fri, 5 Sep 2014 06:10:02 UTC

Severity: wishlist

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 18410 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Antipov <dmantipov <at> yandex.ru>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 18410 <at> debbugs.gnu.org
Subject: Re: bug#18410: Use SAFE_ALLOCA etc. to avoid unbounded stack
 allocation.
Date: Fri, 05 Sep 2014 12:45:27 +0400
On 09/05/2014 10:08 AM, Paul Eggert wrote:

> Attached is a patch to fix the unbounded alloca calls that I found when auditing the Emacs source.
> I'm sending this to bug-gnu-emacs to give Eli a heads-up, as some of the fixes affect Windows code.
> This patch is relative to Emacs trunk bzr 117822.

Code like:

USE_SAFE_ALLOCA;                                                    |-
ptrdiff_t count = SPECPDL_INDEX ();                    |-           |
...                                                    | inner bind | outer bind
Lisp_Object result = unbind_to (count, Fsome_func ()); |-           |
SAFE_FREE ();                                                       |-
return result;

looks suboptimal because it calls unbind_to twice.  May be we need SAFE_FREE_RETURN,
somewhat similar to RETURN_UNGCPRO?  I.e. we should be able to say:

USE_SAFE_ALLOCA;
ptrdiff_t count = SPECPDL_INDEX ();
...
SAFE_FREE_RETURN (Fsome_func ());

Minor note: why specbind can't return previous binding level?
To avoid extra typing, someone can write:

ptrdiff_t count = specbind (Qsome_var, Qnil);

instead of:

ptrdiff_t count = SPECPDL_INDEX ();
specbind (Qsome_var, Qnil);

Dmitry





This bug report was last modified 10 years and 259 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.