aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-06-08 12:54:32 -0700
committerPaul Eggert2011-06-08 12:54:32 -0700
commit9c4c5f81ceb3fb3100a6a81adffcf764b843363c (patch)
treeddb255b95a05dd32e8fde8c2ce081c79a1c31aaa /src
parente46bb31a9f62b157947257b444fb44b1f9a42db6 (diff)
downloademacs-9c4c5f81ceb3fb3100a6a81adffcf764b843363c.tar.gz
emacs-9c4c5f81ceb3fb3100a6a81adffcf764b843363c.zip
* lisp.h (SAFE_ALLOCA_LISP): Check for integer overflow.
(struct Lisp_Save_Value): Use ptrdiff_t, not int, for 'integer' member. * alloc.c (make_save_value): Integer argument is now of type ptrdiff_t, not int. (mark_object): Use ptrdiff_t, not int. * lisp.h (pD): New macro. * print.c (print_object): Use it.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/alloc.c4
-rw-r--r--src/lisp.h30
-rw-r--r--src/print.c2
4 files changed, 34 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 0c3028fb94a..100a7b0f000 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,13 @@
12011-06-08 Paul Eggert <eggert@cs.ucla.edu> 12011-06-08 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * lisp.h (SAFE_ALLOCA_LISP): Check for integer overflow.
4 (struct Lisp_Save_Value): Use ptrdiff_t, not int, for 'integer' member.
5 * alloc.c (make_save_value): Integer argument is now of type
6 ptrdiff_t, not int.
7 (mark_object): Use ptrdiff_t, not int.
8 * lisp.h (pD): New macro.
9 * print.c (print_object): Use it.
10
3 * alloc.c: Use EMACS_INT, not int, to count objects. 11 * alloc.c: Use EMACS_INT, not int, to count objects.
4 (total_conses, total_markers, total_symbols, total_vector_size) 12 (total_conses, total_markers, total_symbols, total_vector_size)
5 (total_free_conses, total_free_markers, total_free_symbols) 13 (total_free_conses, total_free_markers, total_free_symbols)
diff --git a/src/alloc.c b/src/alloc.c
index 4530e0a7377..fd2884af1c3 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3160,7 +3160,7 @@ free_misc (Lisp_Object misc)
3160 The unwind function can get the C values back using XSAVE_VALUE. */ 3160 The unwind function can get the C values back using XSAVE_VALUE. */
3161 3161
3162Lisp_Object 3162Lisp_Object
3163make_save_value (void *pointer, int integer) 3163make_save_value (void *pointer, ptrdiff_t integer)
3164{ 3164{
3165 register Lisp_Object val; 3165 register Lisp_Object val;
3166 register struct Lisp_Save_Value *p; 3166 register struct Lisp_Save_Value *p;
@@ -5514,7 +5514,7 @@ mark_object (Lisp_Object arg)
5514 if (ptr->dogc) 5514 if (ptr->dogc)
5515 { 5515 {
5516 Lisp_Object *p = (Lisp_Object *) ptr->pointer; 5516 Lisp_Object *p = (Lisp_Object *) ptr->pointer;
5517 int nelt; 5517 ptrdiff_t nelt;
5518 for (nelt = ptr->integer; nelt > 0; nelt--, p++) 5518 for (nelt = ptr->integer; nelt > 0; nelt--, p++)
5519 mark_maybe_object (*p); 5519 mark_maybe_object (*p);
5520 } 5520 }
diff --git a/src/lisp.h b/src/lisp.h
index a1bc794ead5..6003daee8fa 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -60,6 +60,21 @@ extern void check_cons_list (void);
60# define EMACS_UINT unsigned EMACS_INT 60# define EMACS_UINT unsigned EMACS_INT
61#endif 61#endif
62 62
63/* Use pD to format ptrdiff_t values, which suffice for indexes into
64 buffers and strings. Emacs never allocates objects larger than
65 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
66 In C99, pD can always be "t"; configure it here for the sake of
67 pre-C99 libraries such as glibc 2.0 and Solaris 8. */
68#if PTRDIFF_MAX == INT_MAX
69# define pD ""
70#elif PTRDIFF_MAX == LONG_MAX
71# define pD "l"
72#elif PTRDIFF_MAX == LLONG_MAX
73# define pD "ll"
74#else
75# define pD "t"
76#endif
77
63/* Extra internal type checking? */ 78/* Extra internal type checking? */
64 79
65#ifdef ENABLE_CHECKING 80#ifdef ENABLE_CHECKING
@@ -1455,7 +1470,7 @@ struct Lisp_Save_Value
1455 area containing INTEGER potential Lisp_Objects. */ 1470 area containing INTEGER potential Lisp_Objects. */
1456 unsigned int dogc : 1; 1471 unsigned int dogc : 1;
1457 void *pointer; 1472 void *pointer;
1458 int integer; 1473 ptrdiff_t integer;
1459 }; 1474 };
1460 1475
1461 1476
@@ -2786,7 +2801,7 @@ extern int abort_on_gc;
2786extern Lisp_Object make_float (double); 2801extern Lisp_Object make_float (double);
2787extern void display_malloc_warning (void); 2802extern void display_malloc_warning (void);
2788extern int inhibit_garbage_collection (void); 2803extern int inhibit_garbage_collection (void);
2789extern Lisp_Object make_save_value (void *, int); 2804extern Lisp_Object make_save_value (void *, ptrdiff_t);
2790extern void free_marker (Lisp_Object); 2805extern void free_marker (Lisp_Object);
2791extern void free_cons (struct Lisp_Cons *); 2806extern void free_cons (struct Lisp_Cons *);
2792extern void init_alloc_once (void); 2807extern void init_alloc_once (void);
@@ -3678,18 +3693,19 @@ extern Lisp_Object safe_alloca_unwind (Lisp_Object);
3678 3693
3679#define SAFE_ALLOCA_LISP(buf, nelt) \ 3694#define SAFE_ALLOCA_LISP(buf, nelt) \
3680 do { \ 3695 do { \
3681 int size_ = (nelt) * sizeof (Lisp_Object); \ 3696 if ((nelt) < MAX_ALLOCA / sizeof (Lisp_Object)) \
3682 if (size_ < MAX_ALLOCA) \ 3697 buf = (Lisp_Object *) alloca ((nelt) * sizeof (Lisp_Object)); \
3683 buf = (Lisp_Object *) alloca (size_); \ 3698 else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)) \
3684 else \
3685 { \ 3699 { \
3686 Lisp_Object arg_; \ 3700 Lisp_Object arg_; \
3687 buf = (Lisp_Object *) xmalloc (size_); \ 3701 buf = (Lisp_Object *) xmalloc ((nelt) * sizeof (Lisp_Object)); \
3688 arg_ = make_save_value (buf, nelt); \ 3702 arg_ = make_save_value (buf, nelt); \
3689 XSAVE_VALUE (arg_)->dogc = 1; \ 3703 XSAVE_VALUE (arg_)->dogc = 1; \
3690 sa_must_free = 1; \ 3704 sa_must_free = 1; \
3691 record_unwind_protect (safe_alloca_unwind, arg_); \ 3705 record_unwind_protect (safe_alloca_unwind, arg_); \
3692 } \ 3706 } \
3707 else \
3708 memory_full (SIZE_MAX); \
3693 } while (0) 3709 } while (0)
3694 3710
3695 3711
diff --git a/src/print.c b/src/print.c
index 803e3a17214..7a3e1bdcdf7 100644
--- a/src/print.c
+++ b/src/print.c
@@ -2004,7 +2004,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2004 2004
2005 case Lisp_Misc_Save_Value: 2005 case Lisp_Misc_Save_Value:
2006 strout ("#<save_value ", -1, -1, printcharfun); 2006 strout ("#<save_value ", -1, -1, printcharfun);
2007 sprintf(buf, "ptr=%p int=%d", 2007 sprintf(buf, "ptr=%p int=%"pD,
2008 XSAVE_VALUE (obj)->pointer, 2008 XSAVE_VALUE (obj)->pointer,
2009 XSAVE_VALUE (obj)->integer); 2009 XSAVE_VALUE (obj)->integer);
2010 strout (buf, -1, -1, printcharfun); 2010 strout (buf, -1, -1, printcharfun);