tm2sec: clear new fields in tm

Old users of the time APIs would hand-craft
time structs without first zeroing all the
members. When this got into tmnorm(), we
would try to access the new members, and
things would go off the rails.

This makes tm2sec() clear the new fields
before passing them to the new APIs, so
that the hand-crafted structs remain
valid.
front
Ori Bernstein 2020-08-24 14:47:10 -07:00
parent 0505f8fb3a
commit b1a13414cd
1 changed files with 9 additions and 0 deletions

View File

@ -7,5 +7,14 @@ tm2sec(Tm *tm)
Tm tt;
tt = *tm;
/*
* The zone offset should be calculated,
* but old code may not init tz member.
* nil it out so we don't access junk.
* while we're at it, old code probably
* leaves junk in nsec.
*/
tt.nsec = 0;
tt.tz = nil;
return tmnorm(&tt);
}