Skip to content

Commit

Permalink
Closes #970. rare alloccol error/segfault fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Jan 28, 2015
1 parent 41b749f commit 5d7a09e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@

33. List columns can be assigned to columns of `factor` type by reference. Closes [#936](https://github.com/Rdatatable/data.table/issues/936). Thanks to @richierocks for the minimal example.

34. After setting the `datatable.alloccol` option, creating a data.table with more than the set `truelength` resulted in error or segfault. This is now fixed. Closes [#970](https://github.com/Rdatatable/data.table/issues/970). Thanks to @caneff for the nice minimal example.

#### NOTES

1. Clearer explanation of what `duplicated()` does (borrowed from base). Thanks to @matthieugomez for pointing out. Closes [#872](https://github.com/Rdatatable/data.table/issues/872).
Expand Down
8 changes: 8 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -5912,6 +5912,14 @@ test(1479, rbindlist(replicate(4,rbindlist(replicate(47, NULL),
DT <- data.table(x = factor(c("a", "b c", "d e f")))
test(1480, DT[, x := strsplit(as.character(x), " ")], data.table(x=list("a", letters[2:3], letters[4:6])))

# #970, over-allocation issue
a=data.frame(matrix(1,ncol=101))
options(datatable.alloccol=100)
ans1 = data.table(a)
options(datatable.alloccol=101)
ans2 = data.table(a)
test(1481, ans1, ans2)

##########################


Expand Down
3 changes: 2 additions & 1 deletion src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ SEXP alloccol(SEXP dt, R_len_t n, Rboolean verbose)
// So, careful to use length() on names, not LENGTH().
if (length(names)!=l) error("Internal error: length of names (%d) is not length of dt (%d)",length(names),l);
if (!selfrefok(dt,verbose))
return shallow(dt,R_NilValue,n); // e.g. test 848 and 851 in R > 3.0.2
return shallow(dt,R_NilValue,(n>l) ? n : l); // e.g. test 848 and 851 in R > 3.0.2
// added (n>l) ? ... for #970, see test 1481.
// TO DO: test realloc names if selfrefnamesok (users can setattr(x,"name") themselves for example.
// if (TRUELENGTH(getAttrib(dt,R_NamesSymbol))!=tl)
// error("Internal error: tl of dt passes checks, but tl of names (%d) != tl of dt (%d)", tl, TRUELENGTH(getAttrib(dt,R_NamesSymbol)));
Expand Down

0 comments on commit 5d7a09e

Please sign in to comment.