From: Paul Eggert Date: Sat, 26 Mar 2011 04:17:38 +0000 (-0700) Subject: * alloc.c (garbage_collect): Don't assume stack size fits in int. X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~460^2~20 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=dd3f25f792d724f59fac3e2d4faa21b311f21137;p=emacs.git * alloc.c (garbage_collect): Don't assume stack size fits in int. (stack_copy_size): Now size_t, not int. (stack_copy, stack_copy_size): Define only if MAX_SAVE_STACK > 0. --- diff --git a/src/ChangeLog b/src/ChangeLog index cc40c863e97..cf9ca86a798 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2011-03-26 Paul Eggert + + * alloc.c (garbage_collect): Don't assume stack size fits in int. + (stack_copy_size): Now size_t, not int. + (stack_copy, stack_copy_size): Define only if MAX_SAVE_STACK > 0. + 2011-03-26 Juanma Barranquero * w32.c (read_unc_volume): Use parameter `henum', instead of diff --git a/src/alloc.c b/src/alloc.c index 66695e7a9bc..00f053e9090 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -254,8 +254,10 @@ const char *pending_malloc_warning; /* Buffer in which we save a copy of the C stack at each GC. */ +#if MAX_SAVE_STACK > 0 static char *stack_copy; -static int stack_copy_size; +static size_t stack_copy_size; +#endif /* Non-zero means ignore malloc warnings. Set during initialization. Currently not used. */ @@ -4903,21 +4905,26 @@ returns nil, because real GC can't be done. */) #if MAX_SAVE_STACK > 0 if (NILP (Vpurify_flag)) { - i = &stack_top_variable - stack_bottom; - if (i < 0) i = -i; - if (i < MAX_SAVE_STACK) + char *stack; + size_t stack_size; + if (&stack_top_variable < stack_bottom) + { + stack = &stack_top_variable; + stack_size = stack_bottom - &stack_top_variable; + } + else + { + stack = stack_bottom; + stack_size = &stack_top_variable - stack_bottom; + } + if (stack_size <= MAX_SAVE_STACK) { - if (stack_copy == 0) - stack_copy = (char *) xmalloc (stack_copy_size = i); - else if (stack_copy_size < i) - stack_copy = (char *) xrealloc (stack_copy, (stack_copy_size = i)); - if (stack_copy) + if (stack_copy_size < stack_size) { - if ((EMACS_INT) (&stack_top_variable - stack_bottom) > 0) - memcpy (stack_copy, stack_bottom, i); - else - memcpy (stack_copy, &stack_top_variable, i); + stack_copy = (char *) xrealloc (stack_copy, stack_size); + stack_copy_size = stack_size; } + memcpy (stack_copy, stack, stack_size); } } #endif /* MAX_SAVE_STACK > 0 */