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

Joshua Ulrich josh.m.ulrich at gmail.com
Tue Dec 6 17:43:38 CET 2016

On Tue, Dec 6, 2016 at 10:30 AM,  <frederik at ofb.net> wrote:
> Hi Joshua,
> Thank you for minimizing my test case.
>> > 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
> I don't know if these questions are not already obvious, but:
> 1. Is there a reasonable way to fail more elegantly when a user makes
> this mistake?
It's not just "this mistake".  See below.

> 2. Should we update the documentation for POSIXlt to warn people that
> the optional "zone" list element must precede the optional "gmtoff"
> list element, in cases where both are present?
No, because that's not the only way to create a malformed POSIXlt
object. Reordering *any* of the elements results in a segfault, and
there are probably other things you could do to the internal structure
of POSIXlt objects to cause segfaults.

Maybe update the documentation to say, "If you update the internal
structure of a POSIXlt object, you deserve whatever happens."? ;-)

> Thanks,
> Frederick

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

More information about the R-devel mailing list