Browse files

Port r49804 from trunk.

git-svn-id: https://svn.r-project.org/R/branches/R-2-9-branch@49805 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information...
1 parent 7539dcb commit 13b698c797dccb4056c96ec3dd2302822d276ebd murdoch committed Sep 24, 2009
Showing with 20 additions and 13 deletions.
  1. +4 −1 NEWS
  2. +16 −12 src/main/print.c
View
5 NEWS
@@ -26,7 +26,10 @@ BUG FIXES
list elements). (PR#13942)
o cat() on an unopened connection could close it twice, and
- file() connections segfaulted on some systems..
+ file() connections segfaulted on some systems.
+
+ o Printing a list could segfault if the elements are nested too
+ deeply.
View
28 src/main/print.c
@@ -377,9 +377,10 @@ static void PrintGenericVector(SEXP s, SEXP env)
STRING_ELT(names, i) != R_NilValue &&
*CHAR(STRING_ELT(names, i)) != '\0') {
const char *ss = translateChar(STRING_ELT(names, i));
- if (taglen + strlen(ss) > TAGBUFLEN)
- sprintf(ptag, "$...");
- else {
+ if (taglen + strlen(ss) > TAGBUFLEN) {
+ if (taglen <= TAGBUFLEN)
+ sprintf(ptag, "$...");
+ } else {
/* we need to distinguish character NA from "NA", which
is a valid (if non-syntactic) name */
if (STRING_ELT(names, i) == NA_STRING)
@@ -391,9 +392,10 @@ static void PrintGenericVector(SEXP s, SEXP env)
}
}
else {
- if (taglen + IndexWidth(i) > TAGBUFLEN)
- sprintf(ptag, "$...");
- else
+ if (taglen + IndexWidth(i) > TAGBUFLEN) {
+ if (taglen <= TAGBUFLEN)
+ sprintf(ptag, "$...");
+ } else
sprintf(ptag, "[[%d]]", i+1);
}
Rprintf("%s\n", tagbuf);
@@ -518,9 +520,10 @@ static void printList(SEXP s, SEXP env)
while (TYPEOF(s) == LISTSXP) {
if (i > 1) Rprintf("\n");
if (TAG(s) != R_NilValue && isSymbol(TAG(s))) {
- if (taglen + strlen(CHAR(PRINTNAME(TAG(s)))) > TAGBUFLEN)
- sprintf(ptag, "$...");
- else {
+ if (taglen + strlen(CHAR(PRINTNAME(TAG(s)))) > TAGBUFLEN) {
+ if (taglen <= TAGBUFLEN)
+ sprintf(ptag, "$...");
+ } else {
/* we need to distinguish character NA from "NA", which
is a valid (if non-syntactic) name */
if (PRINTNAME(TAG(s)) == NA_STRING)
@@ -532,9 +535,10 @@ static void printList(SEXP s, SEXP env)
}
}
else {
- if (taglen + IndexWidth(i) > TAGBUFLEN)
- sprintf(ptag, "$...");
- else
+ if (taglen + IndexWidth(i) > TAGBUFLEN) {
+ if (taglen <= TAGBUFLEN)
+ sprintf(ptag, "$...");
+ } else
sprintf(ptag, "[[%d]]", i);
}
Rprintf("%s\n", tagbuf);

0 comments on commit 13b698c

Please sign in to comment.