From ad2531a0eefb6950d589c0d508b1f959f3f58d8b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 3 May 2011 13:01:57 -0300 Subject: more complete (and hopefuly more correct) handling of 'sizeof(char)' --- lstrlib.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lstrlib.c') diff --git a/lstrlib.c b/lstrlib.c index 656953b8..90dba169 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.165 2011/03/18 19:02:33 roberto Exp roberto $ +** $Id: lstrlib.c,v 1.166 2011/04/20 16:36:28 roberto Exp roberto $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -118,10 +118,10 @@ static int str_rep (lua_State *L) { luaL_Buffer b; char *p = luaL_buffinitsize(L, &b, totallen); while (n-- > 1) { /* first n-1 copies (followed by separator) */ - memcpy(p, s, l); p += l; - memcpy(p, sep, lsep); p += lsep; + memcpy(p, s, l * sizeof(char)); p += l; + memcpy(p, sep, lsep * sizeof(char)); p += lsep; } - memcpy(p, s, l); /* last copy (not followed by separator) */ + memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */ luaL_pushresultsize(&b, totallen); } return 1; @@ -820,7 +820,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { if (isdigit(uchar(*p))) luaL_error(L, "invalid format (width or precision too long)"); *(form++) = '%'; - memcpy(form, strfrmt, p - strfrmt + 1); + memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char)); form += p - strfrmt + 1; *form = '\0'; return p; -- cgit v1.2.3-55-g6feb