aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode.c
diff options
context:
space:
mode:
authorPaul Eggert2011-06-14 11:57:19 -0700
committerPaul Eggert2011-06-14 11:57:19 -0700
commitf66c7cf8f794d6f7fd9ccb8794ffc519e4e89795 (patch)
tree0de26b21c827049c7fa2485204ecf0e2d632b849 /src/bytecode.c
parenta1759b76246a21c7c07dc2ee00b8db792715104c (diff)
downloademacs-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/bytecode.c')
-rw-r--r--src/bytecode.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 74cf401bf1d..adc9352fb6e 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -433,7 +433,7 @@ If the third argument is incorrect, Emacs may crash. */)
433 433
434Lisp_Object 434Lisp_Object
435exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, 435exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
436 Lisp_Object args_template, int nargs, Lisp_Object *args) 436 Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args)
437{ 437{
438 int count = SPECPDL_INDEX (); 438 int count = SPECPDL_INDEX ();
439#ifdef BYTE_CODE_METER 439#ifdef BYTE_CODE_METER
@@ -464,7 +464,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
464 464
465 CHECK_STRING (bytestr); 465 CHECK_STRING (bytestr);
466 CHECK_VECTOR (vector); 466 CHECK_VECTOR (vector);
467 CHECK_NUMBER (maxdepth); 467 CHECK_NATNUM (maxdepth);
468 468
469#ifdef BYTE_CODE_SAFE 469#ifdef BYTE_CODE_SAFE
470 const_length = ASIZE (vector); 470 const_length = ASIZE (vector);
@@ -486,6 +486,8 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
486 stack.byte_string = bytestr; 486 stack.byte_string = bytestr;
487 stack.pc = stack.byte_string_start = SDATA (bytestr); 487 stack.pc = stack.byte_string_start = SDATA (bytestr);
488 stack.constants = vector; 488 stack.constants = vector;
489 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object) < XFASTINT (maxdepth))
490 memory_full (SIZE_MAX);
489 top = (Lisp_Object *) alloca (XFASTINT (maxdepth) 491 top = (Lisp_Object *) alloca (XFASTINT (maxdepth)
490 * sizeof (Lisp_Object)); 492 * sizeof (Lisp_Object));
491#if BYTE_MAINTAIN_TOP 493#if BYTE_MAINTAIN_TOP
@@ -502,14 +504,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
502 504
503 if (INTEGERP (args_template)) 505 if (INTEGERP (args_template))
504 { 506 {
505 int at = XINT (args_template); 507 ptrdiff_t at = XINT (args_template);
506 int rest = at & 128; 508 int rest = at & 128;
507 int mandatory = at & 127; 509 int mandatory = at & 127;
508 int nonrest = at >> 8; 510 ptrdiff_t nonrest = at >> 8;
509 eassert (mandatory <= nonrest); 511 eassert (mandatory <= nonrest);
510 if (nargs <= nonrest) 512 if (nargs <= nonrest)
511 { 513 {
512 int i; 514 ptrdiff_t i;
513 for (i = 0 ; i < nargs; i++, args++) 515 for (i = 0 ; i < nargs; i++, args++)
514 PUSH (*args); 516 PUSH (*args);
515 if (nargs < mandatory) 517 if (nargs < mandatory)
@@ -528,7 +530,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
528 } 530 }
529 else if (rest) 531 else if (rest)
530 { 532 {
531 int i; 533 ptrdiff_t i;
532 for (i = 0 ; i < nonrest; i++, args++) 534 for (i = 0 ; i < nonrest; i++, args++)
533 PUSH (*args); 535 PUSH (*args);
534 PUSH (Flist (nargs - nonrest, args)); 536 PUSH (Flist (nargs - nonrest, args));