diff options
| author | Paul Eggert | 2011-06-14 11:57:19 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-14 11:57:19 -0700 |
| commit | f66c7cf8f794d6f7fd9ccb8794ffc519e4e89795 (patch) | |
| tree | 0de26b21c827049c7fa2485204ecf0e2d632b849 /src/data.c | |
| parent | a1759b76246a21c7c07dc2ee00b8db792715104c (diff) | |
| download | emacs-f66c7cf8f794d6f7fd9ccb8794ffc519e4e89795.tar.gz emacs-f66c7cf8f794d6f7fd9ccb8794ffc519e4e89795.zip | |
Variadic C functions now count arguments with ptrdiff_t.
This partly undoes my 2011-03-30 change, which replaced int with size_t.
Back then I didn't know that the Emacs coding style prefers signed int.
Also, in the meantime I found a few more instances where arguments
were being counted with int, which may truncate counts on 64-bit
machines, or EMACS_INT, which may be unnecessarily wide.
* lisp.h (struct Lisp_Subr.function.aMANY)
(DEFUN_ARGS_MANY, internal_condition_case_n, safe_call):
Arg counts are now ptrdiff_t, not size_t.
All variadic functions and their callers changed accordingly.
(struct gcpro.nvars): Now size_t, not size_t. All uses changed.
* bytecode.c (exec_byte_code): Check maxdepth for overflow,
to avoid potential buffer overrun. Don't assume arg counts fit in 'int'.
* callint.c (Fcall_interactively): Check arg count for overflow,
to avoid potential buffer overrun. Use signed char, not 'int',
for 'varies' array, so that we needn't bother to check its size
calculation for overflow.
* editfns.c (Fformat): Use ptrdiff_t, not EMACS_INT, to count args.
* eval.c (apply_lambda):
* fns.c (Fmapconcat): Use XFASTINT, not XINT, to get args length.
(struct textprop_rec.argnum): Now ptrdiff_t, not int. All uses changed.
(mapconcat): Use ptrdiff_t, not int and EMACS_INT, to count args.
Diffstat (limited to 'src/data.c')
| -rw-r--r-- | src/data.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/data.c b/src/data.c index a239a89c2d4..cf01d38036d 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -2503,18 +2503,18 @@ enum arithop | |||
| 2503 | Amin | 2503 | Amin |
| 2504 | }; | 2504 | }; |
| 2505 | 2505 | ||
| 2506 | static Lisp_Object float_arith_driver (double, size_t, enum arithop, | 2506 | static Lisp_Object float_arith_driver (double, ptrdiff_t, enum arithop, |
| 2507 | size_t, Lisp_Object *); | 2507 | ptrdiff_t, Lisp_Object *); |
| 2508 | static Lisp_Object | 2508 | static Lisp_Object |
| 2509 | arith_driver (enum arithop code, size_t nargs, register Lisp_Object *args) | 2509 | arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args) |
| 2510 | { | 2510 | { |
| 2511 | register Lisp_Object val; | 2511 | register Lisp_Object val; |
| 2512 | register size_t argnum; | 2512 | ptrdiff_t argnum; |
| 2513 | register EMACS_INT accum = 0; | 2513 | register EMACS_INT accum = 0; |
| 2514 | register EMACS_INT next; | 2514 | register EMACS_INT next; |
| 2515 | 2515 | ||
| 2516 | int overflow = 0; | 2516 | int overflow = 0; |
| 2517 | size_t ok_args; | 2517 | ptrdiff_t ok_args; |
| 2518 | EMACS_INT ok_accum; | 2518 | EMACS_INT ok_accum; |
| 2519 | 2519 | ||
| 2520 | switch (SWITCH_ENUM_CAST (code)) | 2520 | switch (SWITCH_ENUM_CAST (code)) |
| @@ -2618,8 +2618,8 @@ arith_driver (enum arithop code, size_t nargs, register Lisp_Object *args) | |||
| 2618 | #define isnan(x) ((x) != (x)) | 2618 | #define isnan(x) ((x) != (x)) |
| 2619 | 2619 | ||
| 2620 | static Lisp_Object | 2620 | static Lisp_Object |
| 2621 | float_arith_driver (double accum, register size_t argnum, enum arithop code, | 2621 | float_arith_driver (double accum, ptrdiff_t argnum, enum arithop code, |
| 2622 | size_t nargs, register Lisp_Object *args) | 2622 | ptrdiff_t nargs, Lisp_Object *args) |
| 2623 | { | 2623 | { |
| 2624 | register Lisp_Object val; | 2624 | register Lisp_Object val; |
| 2625 | double next; | 2625 | double next; |
| @@ -2681,7 +2681,7 @@ float_arith_driver (double accum, register size_t argnum, enum arithop code, | |||
| 2681 | DEFUN ("+", Fplus, Splus, 0, MANY, 0, | 2681 | DEFUN ("+", Fplus, Splus, 0, MANY, 0, |
| 2682 | doc: /* Return sum of any number of arguments, which are numbers or markers. | 2682 | doc: /* Return sum of any number of arguments, which are numbers or markers. |
| 2683 | usage: (+ &rest NUMBERS-OR-MARKERS) */) | 2683 | usage: (+ &rest NUMBERS-OR-MARKERS) */) |
| 2684 | (size_t nargs, Lisp_Object *args) | 2684 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2685 | { | 2685 | { |
| 2686 | return arith_driver (Aadd, nargs, args); | 2686 | return arith_driver (Aadd, nargs, args); |
| 2687 | } | 2687 | } |
| @@ -2691,7 +2691,7 @@ DEFUN ("-", Fminus, Sminus, 0, MANY, 0, | |||
| 2691 | With one arg, negates it. With more than one arg, | 2691 | With one arg, negates it. With more than one arg, |
| 2692 | subtracts all but the first from the first. | 2692 | subtracts all but the first from the first. |
| 2693 | usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */) | 2693 | usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */) |
| 2694 | (size_t nargs, Lisp_Object *args) | 2694 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2695 | { | 2695 | { |
| 2696 | return arith_driver (Asub, nargs, args); | 2696 | return arith_driver (Asub, nargs, args); |
| 2697 | } | 2697 | } |
| @@ -2699,7 +2699,7 @@ usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */) | |||
| 2699 | DEFUN ("*", Ftimes, Stimes, 0, MANY, 0, | 2699 | DEFUN ("*", Ftimes, Stimes, 0, MANY, 0, |
| 2700 | doc: /* Return product of any number of arguments, which are numbers or markers. | 2700 | doc: /* Return product of any number of arguments, which are numbers or markers. |
| 2701 | usage: (* &rest NUMBERS-OR-MARKERS) */) | 2701 | usage: (* &rest NUMBERS-OR-MARKERS) */) |
| 2702 | (size_t nargs, Lisp_Object *args) | 2702 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2703 | { | 2703 | { |
| 2704 | return arith_driver (Amult, nargs, args); | 2704 | return arith_driver (Amult, nargs, args); |
| 2705 | } | 2705 | } |
| @@ -2708,9 +2708,9 @@ DEFUN ("/", Fquo, Squo, 2, MANY, 0, | |||
| 2708 | doc: /* Return first argument divided by all the remaining arguments. | 2708 | doc: /* Return first argument divided by all the remaining arguments. |
| 2709 | The arguments must be numbers or markers. | 2709 | The arguments must be numbers or markers. |
| 2710 | usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */) | 2710 | usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */) |
| 2711 | (size_t nargs, Lisp_Object *args) | 2711 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2712 | { | 2712 | { |
| 2713 | size_t argnum; | 2713 | ptrdiff_t argnum; |
| 2714 | for (argnum = 2; argnum < nargs; argnum++) | 2714 | for (argnum = 2; argnum < nargs; argnum++) |
| 2715 | if (FLOATP (args[argnum])) | 2715 | if (FLOATP (args[argnum])) |
| 2716 | return float_arith_driver (0, 0, Adiv, nargs, args); | 2716 | return float_arith_driver (0, 0, Adiv, nargs, args); |
| @@ -2792,7 +2792,7 @@ DEFUN ("max", Fmax, Smax, 1, MANY, 0, | |||
| 2792 | doc: /* Return largest of all the arguments (which must be numbers or markers). | 2792 | doc: /* Return largest of all the arguments (which must be numbers or markers). |
| 2793 | The value is always a number; markers are converted to numbers. | 2793 | The value is always a number; markers are converted to numbers. |
| 2794 | usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) | 2794 | usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) |
| 2795 | (size_t nargs, Lisp_Object *args) | 2795 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2796 | { | 2796 | { |
| 2797 | return arith_driver (Amax, nargs, args); | 2797 | return arith_driver (Amax, nargs, args); |
| 2798 | } | 2798 | } |
| @@ -2801,7 +2801,7 @@ DEFUN ("min", Fmin, Smin, 1, MANY, 0, | |||
| 2801 | doc: /* Return smallest of all the arguments (which must be numbers or markers). | 2801 | doc: /* Return smallest of all the arguments (which must be numbers or markers). |
| 2802 | The value is always a number; markers are converted to numbers. | 2802 | The value is always a number; markers are converted to numbers. |
| 2803 | usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) | 2803 | usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) |
| 2804 | (size_t nargs, Lisp_Object *args) | 2804 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2805 | { | 2805 | { |
| 2806 | return arith_driver (Amin, nargs, args); | 2806 | return arith_driver (Amin, nargs, args); |
| 2807 | } | 2807 | } |
| @@ -2810,7 +2810,7 @@ DEFUN ("logand", Flogand, Slogand, 0, MANY, 0, | |||
| 2810 | doc: /* Return bitwise-and of all the arguments. | 2810 | doc: /* Return bitwise-and of all the arguments. |
| 2811 | Arguments may be integers, or markers converted to integers. | 2811 | Arguments may be integers, or markers converted to integers. |
| 2812 | usage: (logand &rest INTS-OR-MARKERS) */) | 2812 | usage: (logand &rest INTS-OR-MARKERS) */) |
| 2813 | (size_t nargs, Lisp_Object *args) | 2813 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2814 | { | 2814 | { |
| 2815 | return arith_driver (Alogand, nargs, args); | 2815 | return arith_driver (Alogand, nargs, args); |
| 2816 | } | 2816 | } |
| @@ -2819,7 +2819,7 @@ DEFUN ("logior", Flogior, Slogior, 0, MANY, 0, | |||
| 2819 | doc: /* Return bitwise-or of all the arguments. | 2819 | doc: /* Return bitwise-or of all the arguments. |
| 2820 | Arguments may be integers, or markers converted to integers. | 2820 | Arguments may be integers, or markers converted to integers. |
| 2821 | usage: (logior &rest INTS-OR-MARKERS) */) | 2821 | usage: (logior &rest INTS-OR-MARKERS) */) |
| 2822 | (size_t nargs, Lisp_Object *args) | 2822 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2823 | { | 2823 | { |
| 2824 | return arith_driver (Alogior, nargs, args); | 2824 | return arith_driver (Alogior, nargs, args); |
| 2825 | } | 2825 | } |
| @@ -2828,7 +2828,7 @@ DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0, | |||
| 2828 | doc: /* Return bitwise-exclusive-or of all the arguments. | 2828 | doc: /* Return bitwise-exclusive-or of all the arguments. |
| 2829 | Arguments may be integers, or markers converted to integers. | 2829 | Arguments may be integers, or markers converted to integers. |
| 2830 | usage: (logxor &rest INTS-OR-MARKERS) */) | 2830 | usage: (logxor &rest INTS-OR-MARKERS) */) |
| 2831 | (size_t nargs, Lisp_Object *args) | 2831 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2832 | { | 2832 | { |
| 2833 | return arith_driver (Alogxor, nargs, args); | 2833 | return arith_driver (Alogxor, nargs, args); |
| 2834 | } | 2834 | } |