mirror of https://github.com/rusefi/lua.git
bug: os.date throws error when result is the empty string
This commit is contained in:
parent
93d3c8450c
commit
d513c3c66b
9
bugs
9
bugs
|
@ -1142,6 +1142,15 @@ patch = [[
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bug{
|
||||||
|
what = [[os.date throws an error when result is the empty string]],
|
||||||
|
report = [[ ]],
|
||||||
|
since = [[4.0]],
|
||||||
|
example = [[print(os.date(""))]],
|
||||||
|
patch = [[ ]],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Bug{
|
Bug{
|
||||||
what = [[ ]],
|
what = [[ ]],
|
||||||
report = [[ ]],
|
report = [[ ]],
|
||||||
|
|
23
loslib.c
23
loslib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: loslib.c,v 1.18 2006/03/09 18:08:22 roberto Exp roberto $
|
** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp roberto $
|
||||||
** Standard Operating System library
|
** Standard Operating System library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -146,11 +146,22 @@ static int os_date (lua_State *L) {
|
||||||
setboolfield(L, "isdst", stm->tm_isdst);
|
setboolfield(L, "isdst", stm->tm_isdst);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char b[256];
|
char cc[3];
|
||||||
if (strftime(b, sizeof(b), s, stm))
|
luaL_Buffer b;
|
||||||
lua_pushstring(L, b);
|
cc[0] = '%'; cc[2] = '\0';
|
||||||
else
|
luaL_buffinit(L, &b);
|
||||||
return luaL_error(L, LUA_QL("date") " format too long");
|
for (; *s; s++) {
|
||||||
|
if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
|
||||||
|
luaL_addchar(&b, *s);
|
||||||
|
else {
|
||||||
|
size_t reslen;
|
||||||
|
char buff[200]; /* should be big enough for any conversion result */
|
||||||
|
cc[1] = *(++s);
|
||||||
|
reslen = strftime(buff, sizeof(buff), cc, stm);
|
||||||
|
luaL_addlstring(&b, buff, reslen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
luaL_pushresult(&b);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue