[Rd] segfault with POSIXlt zone=NULL zone=""

Joshua Ulrich josh.m.ulrich at gmail.com
Tue Dec 6 16:51:16 CET 2016


On Tue, Dec 6, 2016 at 6:37 AM,  <frederik at ofb.net> wrote:
> Hi all,
>
> I ran into a segfault while playing with dates.
>
>     $ R --no-init-file
>     ...
>     > library(lubridate); d=as.POSIXlt(floor_date(Sys.time(),"year")); d$zone=NULL; d$zone=""; d
>
If you're asking about a bug in R, you should provide a *minimal*
reproducible example (i.e. one without any package dependencies).
This has nothing to do with lubridate, so you can reproduce the
behavior with:

d <- as.POSIXlt(Sys.time())
d$zone <- NULL
d$zone <- ""
d

>     Attaching package: ‘lubridate’
>
>     The following object is masked from ‘package:base’:
>
>         date
>
>     Warning message:
>     package ‘lubridate’ was built under R version 3.4.0
>
>      *** caught segfault ***
>     address (nil), cause 'unknown'
>
>     Traceback:
>      1: format.POSIXlt(x, usetz = TRUE)
>      2: format(x, usetz = TRUE)
>      3: print(format(x, usetz = TRUE), ...)
>      4: print.POSIXlt(x)
>      5: function (x, ...) UseMethod("print")(x)
>
>     Possible actions:
>     ...
>
> Hope I'm not doing something illegal...
>
You are.  You're changing the internal structure of a POSIXlt object
by re-ordering the list elements.  You should not expect a malformed
POSIXlt object to behave as if it's correctly formed.  You can see
it's malformed by comparing it's unclass()'d output.

d <- as.POSIXlt(Sys.time())
unclass(d)  # valid POSIXlt object
d$zone <- NULL
d$zone <- ""
unclass(d)  # your malformed POSIXlt object

> Thanks,
>
> Frederick
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2016 | www.rinfinance.com



More information about the R-devel mailing list