Thread (38 messages) flat view 38 messages, 10 authors, 2016-08-13

Re: [PATCH 01/14] Fix non-constant array creation

From: Marius Storm-Olsen <hidden>
Date: 2016-06-15 22:47:17

Erik Faye-Lund said the following on 21.08.2009 15:41:
On Fri, Aug 21, 2009 at 3:30 PM, Marius Storm-Olsen[off-list ref] wrote:
quoted
@@ -1875,7 +1875,7 @@ static int match_fragment(struct image *img,
               size_t imgoff = 0;
               size_t preoff = 0;
               size_t postlen = postimage->len;
-               size_t imglen[preimage->nr];
+               size_t *imglen = xmalloc(sizeof(size_t) * preimage->nr);
How about using alloca instead? It allocates from the stack (just like
the C99-style variable-length array you're replacing), and you don't
need to free the memory afterwards.

... or is alloca frowned upon? I see it's already used both in
compat/regex/regex.c and in compat/nedmalloc/malloc.c, but not
apparently not in the git core.
MSVC compiles regex.c, so it must handle it. I'm fine with that.

--
.marius
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help