oehl_list@gmx.de
2002-May-07 11:15 UTC
[Rd] names(unlist(...)) may construct corrupt strings (PR#1524)
names(unlist(...)) seems to be able to construct corrupt strings detected via: two identical strings behave different in paste observed in RW1.4.1 and RW1.5.0 pure replication code after output Best Jens Oehlschlägel> l <- names(unlist(list(aa = list(bb = 1)))) > l[1] "aa.bb"> # this is exactly "aa.bb" > identical(l, "aa.bb")[1] TRUE> > # BUT > identical(paste("aa.bb", "this should be added"), paste(l, "this should beadded")) [1] FALSE> > # this of course works > paste("aa.bb", "this should be added")[1] "aa.bb this should be added"> > # BUT THIS FAILS > paste(l, "this should be added")[1] "aa.bb" l <- names(unlist(list(aa = list(bb = 1)))) l # this is exactly "aa.bb" identical(l, "aa.bb") # BUT identical(paste("aa.bb", "this should be added"), paste(l, "this should be added")) # this of course works paste("aa.bb", "this should be added") # BUT THIS FAILS paste(l, "this should be added") --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 1 minor = 5.0 year = 2002 month = 04 day = 29 language = R Windows 2000 Professional (build 2195) Service Pack 1.0 Search Path: .GlobalEnv, package:ctest, Autoloads, package:base -- GMX - Die Kommunikationsplattform im Internet. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Lumley
2002-May-07 15:55 UTC
[Rd] names(unlist(...)) may construct corrupt strings (PR#1524)
On Tue, 7 May 2002 oehl_list@gmx.de wrote:> names(unlist(...)) seems to be able to construct corrupt strings > detected via: two identical strings behave different in paste > observed in RW1.4.1 and RW1.5.0 > pure replication code after output > > Best > > > Jens Oehlschlägel > > > > l <- names(unlist(list(aa = list(bb = 1)))) > > l > [1] "aa.bb"This is the same problem with do_paste that showed up with read.dta. If you look at the C level, LENGTH() is 6 for l and 5 for "aa.bb". In general we have the problem that a string has two ways of defining its length: LENGTH() and strlen() Most functions use just one of these, but paste() uses LENGTH() to set up the buffer and then strcpy() to copy into it. The string l has LENGTH 6, but strlen 5, and the result from paste() is a string with a null as its sixth character, which thus appears to be a five-character string. Given that this is the second appearance of the problem perhaps do_paste() should be changed instead of (as well as?) unlist(). -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ripley@stats.ox.ac.uk
2002-May-07 16:26 UTC
[Rd] names(unlist(...)) may construct corrupt strings (PR#1524)
On Tue, 7 May 2002, Thomas Lumley wrote:> On Tue, 7 May 2002 oehl_list@gmx.de wrote: > > > names(unlist(...)) seems to be able to construct corrupt strings > > detected via: two identical strings behave different in paste > > observed in RW1.4.1 and RW1.5.0 > > pure replication code after output > > > > Best > > > > > > Jens Oehlschlägel > > > > > > > l <- names(unlist(list(aa = list(bb = 1)))) > > > l > > [1] "aa.bb" > > This is the same problem with do_paste that showed up with read.dta. If > you look at the C level, LENGTH() is 6 for l and 5 for "aa.bb". > > In general we have the problem that a string has two ways of defining its > length: LENGTH() and strlen() > > Most functions use just one of these, but paste() uses LENGTH() to set up > the buffer and then strcpy() to copy into it. The string l has LENGTH 6, > but strlen 5, and the result from paste() is a string with a null as its > sixth character, which thus appears to be a five-character string. > > Given that this is the second appearance of the problem perhaps do_paste() > should be changed instead of (as well as?) unlist().I'm fixing both. The root bug is on line 334 of bind.c. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._