aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog11
-rw-r--r--src/eval.c40
2 files changed, 34 insertions, 17 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 0993b67cbca..68f3dbdedcb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
12011-04-08 Paul Eggert <eggert@cs.ucla.edu>
2
3 * eval.c: Port to Windows vsnprintf (Bug#8435).
4 Include <limits.h>.
5 (SIZE_MAX): Define if the headers do not.
6 (verror): Do not give up if vsnprintf returns a negative count.
7 Instead, grow the buffer. This ports to Windows vsnprintf, which
8 does not conform to C99. Problem reported by Eli Zaretskii.
9 Also, simplify the allocation scheme, by avoiding the need for
10 calling realloc, and removing the ALLOCATED variable.
11
12011-04-07 Paul Eggert <eggert@cs.ucla.edu> 122011-04-07 Paul Eggert <eggert@cs.ucla.edu>
2 13
3 * eval.c (verror): Initial buffer size is 4000 (not 200) bytes. 14 * eval.c (verror): Initial buffer size is 4000 (not 200) bytes.
diff --git a/src/eval.c b/src/eval.c
index f794a18da7d..0f9e012b823 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -18,6 +18,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18 18
19 19
20#include <config.h> 20#include <config.h>
21#include <limits.h>
21#include <setjmp.h> 22#include <setjmp.h>
22#include "lisp.h" 23#include "lisp.h"
23#include "blockinput.h" 24#include "blockinput.h"
@@ -30,6 +31,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30#include "xterm.h" 31#include "xterm.h"
31#endif 32#endif
32 33
34#ifndef SIZE_MAX
35# define SIZE_MAX ((size_t) -1)
36#endif
37
33/* This definition is duplicated in alloc.c and keyboard.c. */ 38/* This definition is duplicated in alloc.c and keyboard.c. */
34/* Putting it in lisp.h makes cc bomb out! */ 39/* Putting it in lisp.h makes cc bomb out! */
35 40
@@ -1978,36 +1983,37 @@ verror (const char *m, va_list ap)
1978{ 1983{
1979 char buf[4000]; 1984 char buf[4000];
1980 size_t size = sizeof buf; 1985 size_t size = sizeof buf;
1981 size_t size_max = (size_t) -1; 1986 size_t size_max =
1987 min (MOST_POSITIVE_FIXNUM, min (INT_MAX, SIZE_MAX - 1)) + 1;
1982 char *buffer = buf; 1988 char *buffer = buf;
1983 int allocated = 0;
1984 int used; 1989 int used;
1985 Lisp_Object string; 1990 Lisp_Object string;
1986 1991
1987 while (1) 1992 while (1)
1988 { 1993 {
1989 used = vsnprintf (buffer, size, m, ap); 1994 used = vsnprintf (buffer, size, m, ap);
1995
1990 if (used < 0) 1996 if (used < 0)
1991 used = 0;
1992 if (used < size)
1993 break;
1994 if (size <= size_max / 2)
1995 size *= 2;
1996 else if (size < size_max)
1997 size = size_max;
1998 else
1999 memory_full ();
2000 if (allocated)
2001 buffer = (char *) xrealloc (buffer, size);
2002 else
2003 { 1997 {
2004 buffer = (char *) xmalloc (size); 1998 /* Non-C99 vsnprintf, such as w32, returns -1 when SIZE is too small.
2005 allocated = 1; 1999 Guess a larger USED to work around the incompatibility. */
2000 used = (size <= size_max / 2 ? 2 * size
2001 : size < size_max ? size_max - 1
2002 : size_max);
2006 } 2003 }
2004 else if (used < size)
2005 break;
2006 if (size_max <= used)
2007 memory_full ();
2008 size = used + 1;
2009
2010 if (buffer != buf)
2011 xfree (buffer);
2012 buffer = (char *) xmalloc (size);
2007 } 2013 }
2008 2014
2009 string = make_string (buffer, used); 2015 string = make_string (buffer, used);
2010 if (allocated) 2016 if (buffer != buf)
2011 xfree (buffer); 2017 xfree (buffer);
2012 2018
2013 xsignal1 (Qerror, string); 2019 xsignal1 (Qerror, string);