diff options
| author | Paul Eggert | 2011-06-15 12:57:25 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-15 12:57:25 -0700 |
| commit | a7af7fdede602a111401c2352e81311a9dc38b99 (patch) | |
| tree | daebcb8a73345231337d0a461c01ae7804b2b646 /src/eval.c | |
| parent | 8c9b210626493dd93f236d7fb312c4f6dba62892 (diff) | |
| parent | b1c46f026de9d185ba86ffb1b23c50f2bd095ccf (diff) | |
| download | emacs-a7af7fdede602a111401c2352e81311a9dc38b99.tar.gz emacs-a7af7fdede602a111401c2352e81311a9dc38b99.zip | |
Integer overflow and signedness fixes (Bug#8873).
Diffstat (limited to 'src/eval.c')
| -rw-r--r-- | src/eval.c | 61 |
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 | ||
| 140 | int handling_signal; | 136 | int handling_signal; |
| 141 | 137 | ||
| 142 | static Lisp_Object funcall_lambda (Lisp_Object, size_t, Lisp_Object *); | 138 | static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *); |
| 143 | static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN; | 139 | static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN; |
| 144 | static int interactive_p (int); | 140 | static int interactive_p (int); |
| 145 | static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args); | 141 | static 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 | ||
| 1611 | Lisp_Object | 1607 | Lisp_Object |
| 1612 | internal_condition_case_n (Lisp_Object (*bfun) (size_t, Lisp_Object *), | 1608 | internal_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, | |||
| 2467 | Then return the value FUNCTION returns. | 2463 | Then return the value FUNCTION returns. |
| 2468 | Thus, (apply '+ 1 2 '(3 4)) returns 10. | 2464 | Thus, (apply '+ 1 2 '(3 4)) returns 10. |
| 2469 | usage: (apply FUNCTION &rest ARGUMENTS) */) | 2465 | usage: (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 | ||
| 2553 | static Lisp_Object | 2549 | static Lisp_Object |
| 2554 | funcall_nil (size_t nargs, Lisp_Object *args) | 2550 | funcall_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. | |||
| 2572 | Do not use `make-local-variable' to make a hook variable buffer-local. | 2568 | Do not use `make-local-variable' to make a hook variable buffer-local. |
| 2573 | Instead, use `add-hook' and specify t for the LOCAL argument. | 2569 | Instead, use `add-hook' and specify t for the LOCAL argument. |
| 2574 | usage: (run-hooks &rest HOOKS) */) | 2570 | usage: (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. | |||
| 2601 | Do not use `make-local-variable' to make a hook variable buffer-local. | 2597 | Do not use `make-local-variable' to make a hook variable buffer-local. |
| 2602 | Instead, use `add-hook' and specify t for the LOCAL argument. | 2598 | Instead, use `add-hook' and specify t for the LOCAL argument. |
| 2603 | usage: (run-hook-with-args HOOK &rest ARGS) */) | 2599 | usage: (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. | |||
| 2621 | Do not use `make-local-variable' to make a hook variable buffer-local. | 2617 | Do not use `make-local-variable' to make a hook variable buffer-local. |
| 2622 | Instead, use `add-hook' and specify t for the LOCAL argument. | 2618 | Instead, use `add-hook' and specify t for the LOCAL argument. |
| 2623 | usage: (run-hook-with-args-until-success HOOK &rest ARGS) */) | 2619 | usage: (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 | ||
| 2629 | static Lisp_Object | 2625 | static Lisp_Object |
| 2630 | funcall_not (size_t nargs, Lisp_Object *args) | 2626 | funcall_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. | |||
| 2646 | Do not use `make-local-variable' to make a hook variable buffer-local. | 2642 | Do not use `make-local-variable' to make a hook variable buffer-local. |
| 2647 | Instead, use `add-hook' and specify t for the LOCAL argument. | 2643 | Instead, use `add-hook' and specify t for the LOCAL argument. |
| 2648 | usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */) | 2644 | usage: (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 | ||
| 2654 | static Lisp_Object | 2650 | static Lisp_Object |
| 2655 | run_hook_wrapped_funcall (size_t nargs, Lisp_Object *args) | 2651 | run_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. | |||
| 2670 | As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped' | 2666 | As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped' |
| 2671 | aborts and returns that value. | 2667 | aborts and returns that value. |
| 2672 | usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */) | 2668 | usage: (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 | ||
| 2685 | Lisp_Object | 2681 | Lisp_Object |
| 2686 | run_hook_with_args (size_t nargs, Lisp_Object *args, | 2682 | run_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, | |||
| 2957 | Return the value that function returns. | 2953 | Return the value that function returns. |
| 2958 | Thus, (funcall 'cons 'x 'y) returns (x . y). | 2954 | Thus, (funcall 'cons 'x 'y) returns (x . y). |
| 2959 | usage: (funcall FUNCTION &rest ARGUMENTS) */) | 2955 | usage: (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 | |||
| 3120 | apply_lambda (Lisp_Object fun, Lisp_Object args) | 3116 | apply_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 | ||
| 3165 | static Lisp_Object | 3160 | static Lisp_Object |
| 3166 | funcall_lambda (Lisp_Object fun, size_t nargs, | 3161 | funcall_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 | |||
| 3645 | mark_backtrace (void) | 3640 | mark_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 | { |