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/editfns.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/editfns.c')
| -rw-r--r-- | src/editfns.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/editfns.c b/src/editfns.c index 12e82c428ad..9678d4da6a2 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -96,7 +96,7 @@ static void general_insert_function (void (*) (const char *, EMACS_INT), | |||
| 96 | void (*) (Lisp_Object, EMACS_INT, | 96 | void (*) (Lisp_Object, EMACS_INT, |
| 97 | EMACS_INT, EMACS_INT, | 97 | EMACS_INT, EMACS_INT, |
| 98 | EMACS_INT, int), | 98 | EMACS_INT, int), |
| 99 | int, size_t, Lisp_Object *); | 99 | int, ptrdiff_t, Lisp_Object *); |
| 100 | static Lisp_Object subst_char_in_region_unwind (Lisp_Object); | 100 | static Lisp_Object subst_char_in_region_unwind (Lisp_Object); |
| 101 | static Lisp_Object subst_char_in_region_unwind_1 (Lisp_Object); | 101 | static Lisp_Object subst_char_in_region_unwind_1 (Lisp_Object); |
| 102 | static void transpose_markers (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT, | 102 | static void transpose_markers (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT, |
| @@ -1858,7 +1858,7 @@ Years before 1970 are not guaranteed to work. On some systems, | |||
| 1858 | year values as low as 1901 do work. | 1858 | year values as low as 1901 do work. |
| 1859 | 1859 | ||
| 1860 | usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */) | 1860 | usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */) |
| 1861 | (size_t nargs, register Lisp_Object *args) | 1861 | (ptrdiff_t nargs, Lisp_Object *args) |
| 1862 | { | 1862 | { |
| 1863 | time_t value; | 1863 | time_t value; |
| 1864 | struct tm tm; | 1864 | struct tm tm; |
| @@ -2194,9 +2194,9 @@ general_insert_function (void (*insert_func) | |||
| 2194 | void (*insert_from_string_func) | 2194 | void (*insert_from_string_func) |
| 2195 | (Lisp_Object, EMACS_INT, EMACS_INT, | 2195 | (Lisp_Object, EMACS_INT, EMACS_INT, |
| 2196 | EMACS_INT, EMACS_INT, int), | 2196 | EMACS_INT, EMACS_INT, int), |
| 2197 | int inherit, size_t nargs, Lisp_Object *args) | 2197 | int inherit, ptrdiff_t nargs, Lisp_Object *args) |
| 2198 | { | 2198 | { |
| 2199 | register size_t argnum; | 2199 | ptrdiff_t argnum; |
| 2200 | register Lisp_Object val; | 2200 | register Lisp_Object val; |
| 2201 | 2201 | ||
| 2202 | for (argnum = 0; argnum < nargs; argnum++) | 2202 | for (argnum = 0; argnum < nargs; argnum++) |
| @@ -2258,7 +2258,7 @@ buffer; to accomplish this, apply `string-as-multibyte' to the string | |||
| 2258 | and insert the result. | 2258 | and insert the result. |
| 2259 | 2259 | ||
| 2260 | usage: (insert &rest ARGS) */) | 2260 | usage: (insert &rest ARGS) */) |
| 2261 | (size_t nargs, register Lisp_Object *args) | 2261 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2262 | { | 2262 | { |
| 2263 | general_insert_function (insert, insert_from_string, 0, nargs, args); | 2263 | general_insert_function (insert, insert_from_string, 0, nargs, args); |
| 2264 | return Qnil; | 2264 | return Qnil; |
| @@ -2277,7 +2277,7 @@ If the current buffer is unibyte, multibyte strings are converted | |||
| 2277 | to unibyte for insertion. | 2277 | to unibyte for insertion. |
| 2278 | 2278 | ||
| 2279 | usage: (insert-and-inherit &rest ARGS) */) | 2279 | usage: (insert-and-inherit &rest ARGS) */) |
| 2280 | (size_t nargs, register Lisp_Object *args) | 2280 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2281 | { | 2281 | { |
| 2282 | general_insert_function (insert_and_inherit, insert_from_string, 1, | 2282 | general_insert_function (insert_and_inherit, insert_from_string, 1, |
| 2283 | nargs, args); | 2283 | nargs, args); |
| @@ -2294,7 +2294,7 @@ If the current buffer is unibyte, multibyte strings are converted | |||
| 2294 | to unibyte for insertion. | 2294 | to unibyte for insertion. |
| 2295 | 2295 | ||
| 2296 | usage: (insert-before-markers &rest ARGS) */) | 2296 | usage: (insert-before-markers &rest ARGS) */) |
| 2297 | (size_t nargs, register Lisp_Object *args) | 2297 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2298 | { | 2298 | { |
| 2299 | general_insert_function (insert_before_markers, | 2299 | general_insert_function (insert_before_markers, |
| 2300 | insert_from_string_before_markers, 0, | 2300 | insert_from_string_before_markers, 0, |
| @@ -2313,7 +2313,7 @@ If the current buffer is unibyte, multibyte strings are converted | |||
| 2313 | to unibyte for insertion. | 2313 | to unibyte for insertion. |
| 2314 | 2314 | ||
| 2315 | usage: (insert-before-markers-and-inherit &rest ARGS) */) | 2315 | usage: (insert-before-markers-and-inherit &rest ARGS) */) |
| 2316 | (size_t nargs, register Lisp_Object *args) | 2316 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2317 | { | 2317 | { |
| 2318 | general_insert_function (insert_before_markers_and_inherit, | 2318 | general_insert_function (insert_before_markers_and_inherit, |
| 2319 | insert_from_string_before_markers, 1, | 2319 | insert_from_string_before_markers, 1, |
| @@ -3386,7 +3386,7 @@ any existing message; this lets the minibuffer contents show. See | |||
| 3386 | also `current-message'. | 3386 | also `current-message'. |
| 3387 | 3387 | ||
| 3388 | usage: (message FORMAT-STRING &rest ARGS) */) | 3388 | usage: (message FORMAT-STRING &rest ARGS) */) |
| 3389 | (size_t nargs, Lisp_Object *args) | 3389 | (ptrdiff_t nargs, Lisp_Object *args) |
| 3390 | { | 3390 | { |
| 3391 | if (NILP (args[0]) | 3391 | if (NILP (args[0]) |
| 3392 | || (STRINGP (args[0]) | 3392 | || (STRINGP (args[0]) |
| @@ -3414,7 +3414,7 @@ If the first argument is nil or the empty string, clear any existing | |||
| 3414 | message; let the minibuffer contents show. | 3414 | message; let the minibuffer contents show. |
| 3415 | 3415 | ||
| 3416 | usage: (message-box FORMAT-STRING &rest ARGS) */) | 3416 | usage: (message-box FORMAT-STRING &rest ARGS) */) |
| 3417 | (size_t nargs, Lisp_Object *args) | 3417 | (ptrdiff_t nargs, Lisp_Object *args) |
| 3418 | { | 3418 | { |
| 3419 | if (NILP (args[0])) | 3419 | if (NILP (args[0])) |
| 3420 | { | 3420 | { |
| @@ -3471,7 +3471,7 @@ If the first argument is nil or the empty string, clear any existing | |||
| 3471 | message; let the minibuffer contents show. | 3471 | message; let the minibuffer contents show. |
| 3472 | 3472 | ||
| 3473 | usage: (message-or-box FORMAT-STRING &rest ARGS) */) | 3473 | usage: (message-or-box FORMAT-STRING &rest ARGS) */) |
| 3474 | (size_t nargs, Lisp_Object *args) | 3474 | (ptrdiff_t nargs, Lisp_Object *args) |
| 3475 | { | 3475 | { |
| 3476 | #ifdef HAVE_MENUS | 3476 | #ifdef HAVE_MENUS |
| 3477 | if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) | 3477 | if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) |
| @@ -3495,11 +3495,11 @@ First argument is the string to copy. | |||
| 3495 | Remaining arguments form a sequence of PROPERTY VALUE pairs for text | 3495 | Remaining arguments form a sequence of PROPERTY VALUE pairs for text |
| 3496 | properties to add to the result. | 3496 | properties to add to the result. |
| 3497 | usage: (propertize STRING &rest PROPERTIES) */) | 3497 | usage: (propertize STRING &rest PROPERTIES) */) |
| 3498 | (size_t nargs, Lisp_Object *args) | 3498 | (ptrdiff_t nargs, Lisp_Object *args) |
| 3499 | { | 3499 | { |
| 3500 | Lisp_Object properties, string; | 3500 | Lisp_Object properties, string; |
| 3501 | struct gcpro gcpro1, gcpro2; | 3501 | struct gcpro gcpro1, gcpro2; |
| 3502 | size_t i; | 3502 | ptrdiff_t i; |
| 3503 | 3503 | ||
| 3504 | /* Number of args must be odd. */ | 3504 | /* Number of args must be odd. */ |
| 3505 | if ((nargs & 1) == 0) | 3505 | if ((nargs & 1) == 0) |
| @@ -3584,9 +3584,9 @@ decimal point itself is omitted. For %s and %S, the precision | |||
| 3584 | specifier truncates the string to the given width. | 3584 | specifier truncates the string to the given width. |
| 3585 | 3585 | ||
| 3586 | usage: (format STRING &rest OBJECTS) */) | 3586 | usage: (format STRING &rest OBJECTS) */) |
| 3587 | (size_t nargs, register Lisp_Object *args) | 3587 | (ptrdiff_t nargs, Lisp_Object *args) |
| 3588 | { | 3588 | { |
| 3589 | EMACS_INT n; /* The number of the next arg to substitute */ | 3589 | ptrdiff_t n; /* The number of the next arg to substitute */ |
| 3590 | char initial_buffer[4000]; | 3590 | char initial_buffer[4000]; |
| 3591 | char *buf = initial_buffer; | 3591 | char *buf = initial_buffer; |
| 3592 | EMACS_INT bufsize = sizeof initial_buffer; | 3592 | EMACS_INT bufsize = sizeof initial_buffer; |
| @@ -3635,7 +3635,7 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 3635 | 3635 | ||
| 3636 | /* Allocate the info and discarded tables. */ | 3636 | /* Allocate the info and discarded tables. */ |
| 3637 | { | 3637 | { |
| 3638 | EMACS_INT i; | 3638 | ptrdiff_t i; |
| 3639 | if ((SIZE_MAX - formatlen) / sizeof (struct info) <= nargs) | 3639 | if ((SIZE_MAX - formatlen) / sizeof (struct info) <= nargs) |
| 3640 | memory_full (SIZE_MAX); | 3640 | memory_full (SIZE_MAX); |
| 3641 | SAFE_ALLOCA (info, struct info *, (nargs + 1) * sizeof *info + formatlen); | 3641 | SAFE_ALLOCA (info, struct info *, (nargs + 1) * sizeof *info + formatlen); |
| @@ -3674,7 +3674,7 @@ usage: (format STRING &rest OBJECTS) */) | |||
| 3674 | while (format != end) | 3674 | while (format != end) |
| 3675 | { | 3675 | { |
| 3676 | /* The values of N and FORMAT when the loop body is entered. */ | 3676 | /* The values of N and FORMAT when the loop body is entered. */ |
| 3677 | EMACS_INT n0 = n; | 3677 | ptrdiff_t n0 = n; |
| 3678 | char *format0 = format; | 3678 | char *format0 = format; |
| 3679 | 3679 | ||
| 3680 | /* Bytes needed to represent the output of this conversion. */ | 3680 | /* Bytes needed to represent the output of this conversion. */ |