[tz] Minor (unimportant really) technical UB bug in strftime() ?
Paul Eggert
eggert at cs.ucla.edu
Fri Nov 11 21:14:24 UTC 2022
On 2022-11-11 03:55, Clive D.W. Feather wrote:
> int x;
> int y = x;
>
> is undefined behaviour because it might assign a trap representation to y.
It's undefined even on implementations that don't have trap
representations. Draft C23 6.3.2.1 "Lvalues, arrays, and function
designators" says, "If the lvalue designates an object of automatic
storage duration that could have been declared with the register storage
class (never had its address taken), and that object is uninitialized
(not declared with an initializer and no assignment to it has been
performed prior to use), the behavior is undefined."
Hence, in the typical case where there are no trap representations, this
code:
time_t x, y = x;
return !y;
has undefined behavior, whereas this code:
time_t x, y = x;
return time(&x) == (time_t)-1 ? !y : !!y;
must return 0 or 1 and the implementation cannot reject the first line's
use of the uninitialized variable x. This part of the standard is
strange indeed, and I can't imagine debugging implementation wanting to
conform to the standard as written.
More information about the tz
mailing list