mirror of https://github.com/rusefi/lua.git
allow NULL string when length is zero in 'lua_pushlstring' and
'luaL_addlstring'
This commit is contained in:
parent
9294466234
commit
8949904783
10
lapi.c
10
lapi.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 2.254 2015/08/25 18:50:37 roberto Exp roberto $
|
** $Id: lapi.c,v 2.255 2015/09/09 13:45:50 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -472,15 +472,15 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Pushes on the stack a string with given length. Even when 'len' == 0,
|
** Pushes on the stack a string with given length. Avoid using 's' when
|
||||||
** 's' cannot be NULL due to later use of 'memcmp' and 'memcpy'.
|
** 'len' == 0 (as 's' can be NULL in that case), due to later use of
|
||||||
|
** 'memcmp' and 'memcpy'.
|
||||||
*/
|
*/
|
||||||
LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
|
LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
|
||||||
TString *ts;
|
TString *ts;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
luaC_checkGC(L);
|
luaC_checkGC(L);
|
||||||
api_check(L, s != NULL, "pointer cannot be NULL");
|
ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
|
||||||
ts = luaS_newlstr(L, s, len);
|
|
||||||
setsvalue2s(L, L->top, ts);
|
setsvalue2s(L, L->top, ts);
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lauxlib.c,v 1.281 2015/06/18 14:23:14 roberto Exp roberto $
|
** $Id: lauxlib.c,v 1.282 2015/10/02 15:46:49 roberto Exp roberto $
|
||||||
** Auxiliary functions for building Lua libraries
|
** Auxiliary functions for building Lua libraries
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -512,10 +512,12 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
|
||||||
|
|
||||||
|
|
||||||
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
|
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
|
||||||
|
if (l > 0) { /* avoid 'memcpy' when 's' can be NULL */
|
||||||
char *b = luaL_prepbuffsize(B, l);
|
char *b = luaL_prepbuffsize(B, l);
|
||||||
memcpy(b, s, l * sizeof(char));
|
memcpy(b, s, l * sizeof(char));
|
||||||
luaL_addsize(B, l);
|
luaL_addsize(B, l);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
|
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
|
||||||
|
|
Loading…
Reference in New Issue