diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-10-06 13:10:22 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-10-06 13:10:22 -0300 |
| commit | 8949904783c2fdda1b6c6cec99637cf6d5471359 (patch) | |
| tree | 3d5e5a7c91f325c3f66e87acd551eb29cb7657da /lapi.c | |
| parent | 9294466234f4304fd1d31e343fb5ca48aec03b16 (diff) | |
| download | lua-8949904783c2fdda1b6c6cec99637cf6d5471359.tar.gz lua-8949904783c2fdda1b6c6cec99637cf6d5471359.tar.bz2 lua-8949904783c2fdda1b6c6cec99637cf6d5471359.zip | |
allow NULL string when length is zero in 'lua_pushlstring' and
'luaL_addlstring'
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 10 |
1 files changed, 5 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.254 2015/08/25 18:50:37 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.255 2015/09/09 13:45:50 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -472,15 +472,15 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { | |||
| 472 | 472 | ||
| 473 | 473 | ||
| 474 | /* | 474 | /* |
| 475 | ** Pushes on the stack a string with given length. Even when 'len' == 0, | 475 | ** Pushes on the stack a string with given length. Avoid using 's' when |
| 476 | ** 's' cannot be NULL due to later use of 'memcmp' and 'memcpy'. | 476 | ** 'len' == 0 (as 's' can be NULL in that case), due to later use of |
| 477 | ** 'memcmp' and 'memcpy'. | ||
| 477 | */ | 478 | */ |
| 478 | LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { | 479 | LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { |
| 479 | TString *ts; | 480 | TString *ts; |
| 480 | lua_lock(L); | 481 | lua_lock(L); |
| 481 | luaC_checkGC(L); | 482 | luaC_checkGC(L); |
| 482 | api_check(L, s != NULL, "pointer cannot be NULL"); | 483 | ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); |
| 483 | ts = luaS_newlstr(L, s, len); | ||
| 484 | setsvalue2s(L, L->top, ts); | 484 | setsvalue2s(L, L->top, ts); |
| 485 | api_incr_top(L); | 485 | api_incr_top(L); |
| 486 | lua_unlock(L); | 486 | lua_unlock(L); |
