aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorPaul Eggert2011-06-15 12:57:25 -0700
committerPaul Eggert2011-06-15 12:57:25 -0700
commita7af7fdede602a111401c2352e81311a9dc38b99 (patch)
treedaebcb8a73345231337d0a461c01ae7804b2b646 /src/eval.c
parent8c9b210626493dd93f236d7fb312c4f6dba62892 (diff)
parentb1c46f026de9d185ba86ffb1b23c50f2bd095ccf (diff)
downloademacs-a7af7fdede602a111401c2352e81311a9dc38b99.tar.gz
emacs-a7af7fdede602a111401c2352e81311a9dc38b99.zip
Integer overflow and signedness fixes (Bug#8873).
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c61
1 files changed, 28 insertions, 33 deletions
diff --git a/src/eval.c b/src/eval.c
index d6f9a9ede81..be582775fea 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -32,10 +32,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
32#include "xterm.h" 32#include "xterm.h"
33#endif 33#endif
34 34
35#ifndef SIZE_MAX
36# define SIZE_MAX ((size_t) -1)
37#endif
38
39/* This definition is duplicated in alloc.c and keyboard.c. */ 35/* This definition is duplicated in alloc.c and keyboard.c. */
40/* Putting it in lisp.h makes cc bomb out! */ 36/* Putting it in lisp.h makes cc bomb out! */
41 37
@@ -139,7 +135,7 @@ Lisp_Object Vsignaling_function;
139 135
140int handling_signal; 136int handling_signal;
141 137
142static Lisp_Object funcall_lambda (Lisp_Object, size_t, Lisp_Object *); 138static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
143static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN; 139static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN;
144static int interactive_p (int); 140static int interactive_p (int);
145static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args); 141static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args);
@@ -1053,7 +1049,7 @@ usage: (let VARLIST BODY...) */)
1053 Lisp_Object *temps, tem, lexenv; 1049 Lisp_Object *temps, tem, lexenv;
1054 register Lisp_Object elt, varlist; 1050 register Lisp_Object elt, varlist;
1055 int count = SPECPDL_INDEX (); 1051 int count = SPECPDL_INDEX ();
1056 register size_t argnum; 1052 ptrdiff_t argnum;
1057 struct gcpro gcpro1, gcpro2; 1053 struct gcpro gcpro1, gcpro2;
1058 USE_SAFE_ALLOCA; 1054 USE_SAFE_ALLOCA;
1059 1055
@@ -1609,8 +1605,8 @@ internal_condition_case_2 (Lisp_Object (*bfun) (Lisp_Object, Lisp_Object),
1609 and ARGS as second argument. */ 1605 and ARGS as second argument. */
1610 1606
1611Lisp_Object 1607Lisp_Object
1612internal_condition_case_n (Lisp_Object (*bfun) (size_t, Lisp_Object *), 1608internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1613 size_t nargs, 1609 ptrdiff_t nargs,
1614 Lisp_Object *args, 1610 Lisp_Object *args,
1615 Lisp_Object handlers, 1611 Lisp_Object handlers,
1616 Lisp_Object (*hfun) (Lisp_Object)) 1612 Lisp_Object (*hfun) (Lisp_Object))
@@ -1995,7 +1991,7 @@ verror (const char *m, va_list ap)
1995{ 1991{
1996 char buf[4000]; 1992 char buf[4000];
1997 size_t size = sizeof buf; 1993 size_t size = sizeof buf;
1998 size_t size_max = STRING_BYTES_MAX + 1; 1994 size_t size_max = STRING_BYTES_BOUND + 1;
1999 size_t mlen = strlen (m); 1995 size_t mlen = strlen (m);
2000 char *buffer = buf; 1996 char *buffer = buf;
2001 size_t used; 1997 size_t used;
@@ -2337,7 +2333,7 @@ eval_sub (Lisp_Object form)
2337 { 2333 {
2338 /* Pass a vector of evaluated arguments. */ 2334 /* Pass a vector of evaluated arguments. */
2339 Lisp_Object *vals; 2335 Lisp_Object *vals;
2340 register size_t argnum = 0; 2336 ptrdiff_t argnum = 0;
2341 USE_SAFE_ALLOCA; 2337 USE_SAFE_ALLOCA;
2342 2338
2343 SAFE_ALLOCA_LISP (vals, XINT (numargs)); 2339 SAFE_ALLOCA_LISP (vals, XINT (numargs));
@@ -2467,9 +2463,9 @@ DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
2467Then return the value FUNCTION returns. 2463Then return the value FUNCTION returns.
2468Thus, (apply '+ 1 2 '(3 4)) returns 10. 2464Thus, (apply '+ 1 2 '(3 4)) returns 10.
2469usage: (apply FUNCTION &rest ARGUMENTS) */) 2465usage: (apply FUNCTION &rest ARGUMENTS) */)
2470 (size_t nargs, Lisp_Object *args) 2466 (ptrdiff_t nargs, Lisp_Object *args)
2471{ 2467{
2472 register size_t i, numargs; 2468 ptrdiff_t i, numargs;
2473 register Lisp_Object spread_arg; 2469 register Lisp_Object spread_arg;
2474 register Lisp_Object *funcall_args; 2470 register Lisp_Object *funcall_args;
2475 Lisp_Object fun, retval; 2471 Lisp_Object fun, retval;
@@ -2551,7 +2547,7 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
2551/* Run hook variables in various ways. */ 2547/* Run hook variables in various ways. */
2552 2548
2553static Lisp_Object 2549static Lisp_Object
2554funcall_nil (size_t nargs, Lisp_Object *args) 2550funcall_nil (ptrdiff_t nargs, Lisp_Object *args)
2555{ 2551{
2556 Ffuncall (nargs, args); 2552 Ffuncall (nargs, args);
2557 return Qnil; 2553 return Qnil;
@@ -2572,10 +2568,10 @@ hook; they should use `run-mode-hooks' instead.
2572Do not use `make-local-variable' to make a hook variable buffer-local. 2568Do not use `make-local-variable' to make a hook variable buffer-local.
2573Instead, use `add-hook' and specify t for the LOCAL argument. 2569Instead, use `add-hook' and specify t for the LOCAL argument.
2574usage: (run-hooks &rest HOOKS) */) 2570usage: (run-hooks &rest HOOKS) */)
2575 (size_t nargs, Lisp_Object *args) 2571 (ptrdiff_t nargs, Lisp_Object *args)
2576{ 2572{
2577 Lisp_Object hook[1]; 2573 Lisp_Object hook[1];
2578 register size_t i; 2574 ptrdiff_t i;
2579 2575
2580 for (i = 0; i < nargs; i++) 2576 for (i = 0; i < nargs; i++)
2581 { 2577 {
@@ -2601,7 +2597,7 @@ as that may change.
2601Do not use `make-local-variable' to make a hook variable buffer-local. 2597Do not use `make-local-variable' to make a hook variable buffer-local.
2602Instead, use `add-hook' and specify t for the LOCAL argument. 2598Instead, use `add-hook' and specify t for the LOCAL argument.
2603usage: (run-hook-with-args HOOK &rest ARGS) */) 2599usage: (run-hook-with-args HOOK &rest ARGS) */)
2604 (size_t nargs, Lisp_Object *args) 2600 (ptrdiff_t nargs, Lisp_Object *args)
2605{ 2601{
2606 return run_hook_with_args (nargs, args, funcall_nil); 2602 return run_hook_with_args (nargs, args, funcall_nil);
2607} 2603}
@@ -2621,13 +2617,13 @@ However, if they all return nil, we return nil.
2621Do not use `make-local-variable' to make a hook variable buffer-local. 2617Do not use `make-local-variable' to make a hook variable buffer-local.
2622Instead, use `add-hook' and specify t for the LOCAL argument. 2618Instead, use `add-hook' and specify t for the LOCAL argument.
2623usage: (run-hook-with-args-until-success HOOK &rest ARGS) */) 2619usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2624 (size_t nargs, Lisp_Object *args) 2620 (ptrdiff_t nargs, Lisp_Object *args)
2625{ 2621{
2626 return run_hook_with_args (nargs, args, Ffuncall); 2622 return run_hook_with_args (nargs, args, Ffuncall);
2627} 2623}
2628 2624
2629static Lisp_Object 2625static Lisp_Object
2630funcall_not (size_t nargs, Lisp_Object *args) 2626funcall_not (ptrdiff_t nargs, Lisp_Object *args)
2631{ 2627{
2632 return NILP (Ffuncall (nargs, args)) ? Qt : Qnil; 2628 return NILP (Ffuncall (nargs, args)) ? Qt : Qnil;
2633} 2629}
@@ -2646,13 +2642,13 @@ Then we return nil. However, if they all return non-nil, we return non-nil.
2646Do not use `make-local-variable' to make a hook variable buffer-local. 2642Do not use `make-local-variable' to make a hook variable buffer-local.
2647Instead, use `add-hook' and specify t for the LOCAL argument. 2643Instead, use `add-hook' and specify t for the LOCAL argument.
2648usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */) 2644usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2649 (size_t nargs, Lisp_Object *args) 2645 (ptrdiff_t nargs, Lisp_Object *args)
2650{ 2646{
2651 return NILP (run_hook_with_args (nargs, args, funcall_not)) ? Qt : Qnil; 2647 return NILP (run_hook_with_args (nargs, args, funcall_not)) ? Qt : Qnil;
2652} 2648}
2653 2649
2654static Lisp_Object 2650static Lisp_Object
2655run_hook_wrapped_funcall (size_t nargs, Lisp_Object *args) 2651run_hook_wrapped_funcall (ptrdiff_t nargs, Lisp_Object *args)
2656{ 2652{
2657 Lisp_Object tmp = args[0], ret; 2653 Lisp_Object tmp = args[0], ret;
2658 args[0] = args[1]; 2654 args[0] = args[1];
@@ -2670,7 +2666,7 @@ it calls WRAP-FUNCTION with arguments FUN and ARGS.
2670As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped' 2666As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2671aborts and returns that value. 2667aborts and returns that value.
2672usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */) 2668usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2673 (size_t nargs, Lisp_Object *args) 2669 (ptrdiff_t nargs, Lisp_Object *args)
2674{ 2670{
2675 return run_hook_with_args (nargs, args, run_hook_wrapped_funcall); 2671 return run_hook_with_args (nargs, args, run_hook_wrapped_funcall);
2676} 2672}
@@ -2683,8 +2679,8 @@ usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2683 except that it isn't necessary to gcpro ARGS[0]. */ 2679 except that it isn't necessary to gcpro ARGS[0]. */
2684 2680
2685Lisp_Object 2681Lisp_Object
2686run_hook_with_args (size_t nargs, Lisp_Object *args, 2682run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2687 Lisp_Object (*funcall) (size_t nargs, Lisp_Object *args)) 2683 Lisp_Object (*funcall) (ptrdiff_t nargs, Lisp_Object *args))
2688{ 2684{
2689 Lisp_Object sym, val, ret = Qnil; 2685 Lisp_Object sym, val, ret = Qnil;
2690 struct gcpro gcpro1, gcpro2, gcpro3; 2686 struct gcpro gcpro1, gcpro2, gcpro3;
@@ -2957,16 +2953,16 @@ DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
2957Return the value that function returns. 2953Return the value that function returns.
2958Thus, (funcall 'cons 'x 'y) returns (x . y). 2954Thus, (funcall 'cons 'x 'y) returns (x . y).
2959usage: (funcall FUNCTION &rest ARGUMENTS) */) 2955usage: (funcall FUNCTION &rest ARGUMENTS) */)
2960 (size_t nargs, Lisp_Object *args) 2956 (ptrdiff_t nargs, Lisp_Object *args)
2961{ 2957{
2962 Lisp_Object fun, original_fun; 2958 Lisp_Object fun, original_fun;
2963 Lisp_Object funcar; 2959 Lisp_Object funcar;
2964 size_t numargs = nargs - 1; 2960 ptrdiff_t numargs = nargs - 1;
2965 Lisp_Object lisp_numargs; 2961 Lisp_Object lisp_numargs;
2966 Lisp_Object val; 2962 Lisp_Object val;
2967 struct backtrace backtrace; 2963 struct backtrace backtrace;
2968 register Lisp_Object *internal_args; 2964 register Lisp_Object *internal_args;
2969 register size_t i; 2965 ptrdiff_t i;
2970 2966
2971 QUIT; 2967 QUIT;
2972 if ((consing_since_gc > gc_cons_threshold 2968 if ((consing_since_gc > gc_cons_threshold
@@ -3120,14 +3116,13 @@ static Lisp_Object
3120apply_lambda (Lisp_Object fun, Lisp_Object args) 3116apply_lambda (Lisp_Object fun, Lisp_Object args)
3121{ 3117{
3122 Lisp_Object args_left; 3118 Lisp_Object args_left;
3123 size_t numargs; 3119 ptrdiff_t i, numargs;
3124 register Lisp_Object *arg_vector; 3120 register Lisp_Object *arg_vector;
3125 struct gcpro gcpro1, gcpro2, gcpro3; 3121 struct gcpro gcpro1, gcpro2, gcpro3;
3126 register size_t i;
3127 register Lisp_Object tem; 3122 register Lisp_Object tem;
3128 USE_SAFE_ALLOCA; 3123 USE_SAFE_ALLOCA;
3129 3124
3130 numargs = XINT (Flength (args)); 3125 numargs = XFASTINT (Flength (args));
3131 SAFE_ALLOCA_LISP (arg_vector, numargs); 3126 SAFE_ALLOCA_LISP (arg_vector, numargs);
3132 args_left = args; 3127 args_left = args;
3133 3128
@@ -3163,12 +3158,12 @@ apply_lambda (Lisp_Object fun, Lisp_Object args)
3163 FUN must be either a lambda-expression or a compiled-code object. */ 3158 FUN must be either a lambda-expression or a compiled-code object. */
3164 3159
3165static Lisp_Object 3160static Lisp_Object
3166funcall_lambda (Lisp_Object fun, size_t nargs, 3161funcall_lambda (Lisp_Object fun, ptrdiff_t nargs,
3167 register Lisp_Object *arg_vector) 3162 register Lisp_Object *arg_vector)
3168{ 3163{
3169 Lisp_Object val, syms_left, next, lexenv; 3164 Lisp_Object val, syms_left, next, lexenv;
3170 int count = SPECPDL_INDEX (); 3165 int count = SPECPDL_INDEX ();
3171 size_t i; 3166 ptrdiff_t i;
3172 int optional, rest; 3167 int optional, rest;
3173 3168
3174 if (CONSP (fun)) 3169 if (CONSP (fun))
@@ -3585,7 +3580,7 @@ Output stream used is value of `standard-output'. */)
3585 } 3580 }
3586 else 3581 else
3587 { 3582 {
3588 size_t i; 3583 ptrdiff_t i;
3589 for (i = 0; i < backlist->nargs; i++) 3584 for (i = 0; i < backlist->nargs; i++)
3590 { 3585 {
3591 if (i) write_string (" ", -1); 3586 if (i) write_string (" ", -1);
@@ -3645,7 +3640,7 @@ void
3645mark_backtrace (void) 3640mark_backtrace (void)
3646{ 3641{
3647 register struct backtrace *backlist; 3642 register struct backtrace *backlist;
3648 register size_t i; 3643 ptrdiff_t i;
3649 3644
3650 for (backlist = backtrace_list; backlist; backlist = backlist->next) 3645 for (backlist = backtrace_list; backlist; backlist = backlist->next)
3651 { 3646 {