aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-09-19 10:57:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-09-19 10:57:08 -0300
commitd513c3c66b3c71412d87a3f24b8f792b7b728e93 (patch)
tree8f93f05c3a707967369956b0c4acf0bcfb48cec1
parent93d3c8450c7a78321cf7f9db9173d46c62ebe958 (diff)
downloadlua-d513c3c66b3c71412d87a3f24b8f792b7b728e93.tar.gz
lua-d513c3c66b3c71412d87a3f24b8f792b7b728e93.tar.bz2
lua-d513c3c66b3c71412d87a3f24b8f792b7b728e93.zip
bug: os.date throws error when result is the empty string
-rw-r--r--bugs9
-rw-r--r--loslib.c23
2 files changed, 26 insertions, 6 deletions
diff --git a/bugs b/bugs
index eaf2fd26..a489872f 100644
--- a/bugs
+++ b/bugs
@@ -1143,6 +1143,15 @@ patch = [[
1143 1143
1144 1144
1145Bug{ 1145Bug{
1146what = [[os.date throws an error when result is the empty string]],
1147report = [[ ]],
1148since = [[4.0]],
1149example = [[print(os.date(""))]],
1150patch = [[ ]],
1151}
1152
1153
1154Bug{
1146what = [[ ]], 1155what = [[ ]],
1147report = [[ ]], 1156report = [[ ]],
1148since = [[ ]], 1157since = [[ ]],
diff --git a/loslib.c b/loslib.c
index 3a1e8409..05138417 100644
--- a/loslib.c
+++ b/loslib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loslib.c,v 1.18 2006/03/09 18:08:22 roberto Exp roberto $ 2** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp roberto $
3** Standard Operating System library 3** Standard Operating System library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -146,11 +146,22 @@ static int os_date (lua_State *L) {
146 setboolfield(L, "isdst", stm->tm_isdst); 146 setboolfield(L, "isdst", stm->tm_isdst);
147 } 147 }
148 else { 148 else {
149 char b[256]; 149 char cc[3];
150 if (strftime(b, sizeof(b), s, stm)) 150 luaL_Buffer b;
151 lua_pushstring(L, b); 151 cc[0] = '%'; cc[2] = '\0';
152 else 152 luaL_buffinit(L, &b);
153 return luaL_error(L, LUA_QL("date") " format too long"); 153 for (; *s; s++) {
154 if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
155 luaL_addchar(&b, *s);
156 else {
157 size_t reslen;
158 char buff[200]; /* should be big enough for any conversion result */
159 cc[1] = *(++s);
160 reslen = strftime(buff, sizeof(buff), cc, stm);
161 luaL_addlstring(&b, buff, reslen);
162 }
163 }
164 luaL_pushresult(&b);
154 } 165 }
155 return 1; 166 return 1;
156} 167}