diff options
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.230 2011/04/08 19:17:36 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.231 2011/04/19 18:29:41 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 | */ |
@@ -442,8 +442,10 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) { | |||
442 | newsize = B->n + sz; | 442 | newsize = B->n + sz; |
443 | if (newsize < B->n || newsize - B->n < sz) | 443 | if (newsize < B->n || newsize - B->n < sz) |
444 | luaL_error(L, "buffer too large"); | 444 | luaL_error(L, "buffer too large"); |
445 | newbuff = (char *)lua_newuserdata(L, newsize); /* create larger buffer */ | 445 | /* create larger buffer */ |
446 | memcpy(newbuff, B->b, B->n); /* move content to new buffer */ | 446 | newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char)); |
447 | /* move content to new buffer */ | ||
448 | memcpy(newbuff, B->b, B->n * sizeof(char)); | ||
447 | if (buffonstack(B)) | 449 | if (buffonstack(B)) |
448 | lua_remove(L, -2); /* remove old buffer */ | 450 | lua_remove(L, -2); /* remove old buffer */ |
449 | B->b = newbuff; | 451 | B->b = newbuff; |
@@ -455,7 +457,7 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) { | |||
455 | 457 | ||
456 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { | 458 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { |
457 | char *b = luaL_prepbuffsize(B, l); | 459 | char *b = luaL_prepbuffsize(B, l); |
458 | memcpy(b, s, l); | 460 | memcpy(b, s, l * sizeof(char)); |
459 | luaL_addsize(B, l); | 461 | luaL_addsize(B, l); |
460 | } | 462 | } |
461 | 463 | ||