Przeglądaj źródła

Fix os.date() for wider libc strftime() compatibility.

Thanks to Jesper Lundgren.
Mike Pall 6 lat temu
rodzic
commit
fc63c938b5
1 zmienionych plików z 2 dodań i 2 usunięć
  1. 2 2
      src/lib_os.c

+ 2 - 2
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) {