__year_to_secs: fix dangling pointer

The lifetime of the compound literal ends after the "if" statement's
implicit block. gcc also warns about this.
This commit is contained in:
Alex Xu (Hello71) 2023-11-01 19:37:44 -04:00 committed by Rich Felker
parent c5459df188
commit 2d84486a08

View file

@ -10,9 +10,9 @@ long long __year_to_secs(long long year, int *is_leap)
return 31536000*(y-70) + 86400*leaps;
}
int cycles, centuries, leaps, rem;
int cycles, centuries, leaps, rem, dummy;
if (!is_leap) is_leap = &(int){0};
if (!is_leap) is_leap = &dummy;
cycles = (year-100) / 400;
rem = (year-100) % 400;
if (rem < 0) {