Skip to content

Commit

Permalink
R_print.max now at most INT_MAX-1 -- no integer overflow+ segfault an…
Browse files Browse the repository at this point in the history
…ymore ..

git-svn-id: https://svn.r-project.org/R/trunk@60807 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Sep 25, 2012
1 parent 03b2764 commit f07fb08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/print.c
Expand Up @@ -96,6 +96,7 @@ void PrintDefaults(void)
if (R_print.scipen == NA_INTEGER) R_print.scipen = 0;
R_print.max = asInteger(GetOption1(install("max.print")));
if (R_print.max == NA_INTEGER || R_print.max < 0) R_print.max = 99999;
else if(R_print.max = INT_MAX) R_print.max--; // so we can add
R_print.gap = 1;
R_print.width = GetOptionWidth();
R_print.useSource = USESOURCE;
Expand Down Expand Up @@ -268,6 +269,7 @@ SEXP attribute_hidden do_printdefault(SEXP call, SEXP op, SEXP args, SEXP rho)
R_print.max = asInteger(CAR(args));
if(R_print.max == NA_INTEGER || R_print.max < 0)
error(_("invalid '%s' argument"), "max");
else if(R_print.max = INT_MAX) R_print.max--; // so we can add
}
args = CDR(args);

Expand Down
3 changes: 3 additions & 0 deletions tests/reg-tests-1b.R
Expand Up @@ -1976,5 +1976,8 @@ f <- function(depth) if(depth < 20) f(depth+1) else Cstack_info()
stopifnot(z[2] > f(10)[2])
## Previous test ould be defeated by compiler optimization.

options(max.print=.Machine$integer.max)
1 ## segfaulted because of integer overflow
stopifnot(identical(.Machine$integer.max, getOption("max.print")))

proc.time()

0 comments on commit f07fb08

Please sign in to comment.