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 /lauxlib.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 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.281 2015/06/18 14:23:14 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.282 2015/10/02 15:46:49 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -512,9 +512,11 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) { | |||
512 | 512 | ||
513 | 513 | ||
514 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { | 514 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { |
515 | char *b = luaL_prepbuffsize(B, l); | 515 | if (l > 0) { /* avoid 'memcpy' when 's' can be NULL */ |
516 | memcpy(b, s, l * sizeof(char)); | 516 | char *b = luaL_prepbuffsize(B, l); |
517 | luaL_addsize(B, l); | 517 | memcpy(b, s, l * sizeof(char)); |
518 | luaL_addsize(B, l); | ||
519 | } | ||
518 | } | 520 | } |
519 | 521 | ||
520 | 522 | ||