Skip to content

Commit fc63c93

Browse files
author
Mike Pall
committed
Fix os.date() for wider libc strftime() compatibility.
Thanks to Jesper Lundgren.
1 parent c4f36ce commit fc63c93

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib_os.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ LJLIB_CF(os_date)
205205
setboolfield(L, "isdst", stm->tm_isdst);
206206
} else if (*s) {
207207
SBuf *sb = &G(L)->tmpbuf;
208-
MSize sz = 0;
208+
MSize sz = 0, retry = 4;
209209
const char *q;
210210
for (q = s; *q; q++)
211211
sz += (*q == '%') ? 30 : 1; /* Overflow doesn't matter. */
212212
setsbufL(sb, L);
213-
for (;;) {
213+
while (retry--) { /* Limit growth for invalid format or empty result. */
214214
char *buf = lj_buf_need(sb, sz);
215215
size_t len = strftime(buf, sbufsz(sb), s, stm);
216216
if (len) {

0 commit comments

Comments
 (0)