summaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-05-03 13:01:57 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-05-03 13:01:57 -0300
commitad2531a0eefb6950d589c0d508b1f959f3f58d8b (patch)
tree706eca04d13655367b3743bd6a4e8c544a2b0928 /lstrlib.c
parentbc1c718cc02d4a0163110cb21bcbdd2985e4d28d (diff)
downloadlua-ad2531a0eefb6950d589c0d508b1f959f3f58d8b.tar.gz
lua-ad2531a0eefb6950d589c0d508b1f959f3f58d8b.tar.bz2
lua-ad2531a0eefb6950d589c0d508b1f959f3f58d8b.zip
more complete (and hopefuly more correct) handling of 'sizeof(char)'
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 656953b8..90dba169 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.165 2011/03/18 19:02:33 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.166 2011/04/20 16:36:28 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -118,10 +118,10 @@ static int str_rep (lua_State *L) {
118 luaL_Buffer b; 118 luaL_Buffer b;
119 char *p = luaL_buffinitsize(L, &b, totallen); 119 char *p = luaL_buffinitsize(L, &b, totallen);
120 while (n-- > 1) { /* first n-1 copies (followed by separator) */ 120 while (n-- > 1) { /* first n-1 copies (followed by separator) */
121 memcpy(p, s, l); p += l; 121 memcpy(p, s, l * sizeof(char)); p += l;
122 memcpy(p, sep, lsep); p += lsep; 122 memcpy(p, sep, lsep * sizeof(char)); p += lsep;
123 } 123 }
124 memcpy(p, s, l); /* last copy (not followed by separator) */ 124 memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */
125 luaL_pushresultsize(&b, totallen); 125 luaL_pushresultsize(&b, totallen);
126 } 126 }
127 return 1; 127 return 1;
@@ -820,7 +820,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
820 if (isdigit(uchar(*p))) 820 if (isdigit(uchar(*p)))
821 luaL_error(L, "invalid format (width or precision too long)"); 821 luaL_error(L, "invalid format (width or precision too long)");
822 *(form++) = '%'; 822 *(form++) = '%';
823 memcpy(form, strfrmt, p - strfrmt + 1); 823 memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char));
824 form += p - strfrmt + 1; 824 form += p - strfrmt + 1;
825 *form = '\0'; 825 *form = '\0';
826 return p; 826 return p;