From: Mike Pall Date: Thu, 10 Jan 2019 11:47:28 +0000 (+0100) Subject: Fix os.date() for wider libc strftime() compatibility. X-Git-Tag: v2.1.ROLLING~304 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc63c938b522e147ea728b75f385728bf4a8fc35;p=thirdparty%2FLuaJIT.git Fix os.date() for wider libc strftime() compatibility. Thanks to Jesper Lundgren. --- diff --git a/src/lib_os.c b/src/lib_os.c index 9e78d49a..ffbc3fdc 100644 --- a/src/lib_os.c +++ b/src/lib_os.c @@ -205,12 +205,12 @@ LJLIB_CF(os_date) setboolfield(L, "isdst", stm->tm_isdst); } else if (*s) { SBuf *sb = &G(L)->tmpbuf; - MSize sz = 0; + MSize sz = 0, retry = 4; const char *q; for (q = s; *q; q++) sz += (*q == '%') ? 30 : 1; /* Overflow doesn't matter. */ setsbufL(sb, L); - for (;;) { + while (retry--) { /* Limit growth for invalid format or empty result. */ char *buf = lj_buf_need(sb, sz); size_t len = strftime(buf, sbufsz(sb), s, stm); if (len) {