Fix strftime if tm_zone is null.
Upstream tzcode said "On platforms with tm_zone, strftime.c now assumes it is not NULL". Which is fine for any struct tm generated by tzcode, but not necessarily true of a struct tm constructed by arbitrary code. In particular, Netflix on Nexus Player was failing to start because they format "%Z" with a struct tm whose tm_zone is null (the other fields are valid, but, yeah, that's probably not intentional). glibc takes a null tm_zone to mean "the current time zone", so let's do that too. (Historically Android would use the empty string, and POSIX doesn't clarify which of this is the appropriate behavior when tm_zone is null.) Bug: http://b/25170306 Change-Id: Idbf68bfe90d143aca7dada8607742905188b1d33
This commit is contained in:
@@ -502,7 +502,23 @@ label:
|
||||
continue;
|
||||
case 'Z':
|
||||
#ifdef TM_ZONE
|
||||
pt = _add(t->TM_ZONE, pt, ptlim, modifier);
|
||||
// BEGIN: Android-changed.
|
||||
{
|
||||
const char* zone = t->TM_ZONE;
|
||||
if (!zone || !*zone) {
|
||||
// "The value of tm_isdst shall be positive if Daylight Savings Time is
|
||||
// in effect, 0 if Daylight Savings Time is not in effect, and negative
|
||||
// if the information is not available."
|
||||
if (t->tm_isdst == 0) zone = tzname[0];
|
||||
else if (t->tm_isdst > 0) zone = tzname[1];
|
||||
|
||||
// "Replaced by the timezone name or abbreviation, or by no bytes if no
|
||||
// timezone information exists."
|
||||
if (!zone || !*zone) zone = "";
|
||||
}
|
||||
pt = _add(zone, pt, ptlim, modifier);
|
||||
}
|
||||
// END: Android-changed.
|
||||
#else
|
||||
if (t->tm_isdst >= 0)
|
||||
pt = _add(tzname[t->tm_isdst != 0],
|
||||
|
Reference in New Issue
Block a user