aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-02-07 17:15:24 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-02-07 17:15:24 -0200
commite7a9c45a4847d3ce058ac0e6051308591e7caf00 (patch)
treea802304497cd206432adc56a4f5bd1ab979c22d2
parentfd6c1f489862d8ecf7055ca18898fffd006711fa (diff)
downloadlua-e7a9c45a4847d3ce058ac0e6051308591e7caf00.tar.gz
lua-e7a9c45a4847d3ce058ac0e6051308591e7caf00.tar.bz2
lua-e7a9c45a4847d3ce058ac0e6051308591e7caf00.zip
trying to avoid assumption that sizeof(char)==1
-rw-r--r--loadlib.c4
-rw-r--r--lobject.c4
-rw-r--r--lstrlib.c4
-rw-r--r--lundump.c6
-rw-r--r--lvm.c7
5 files changed, 13 insertions, 12 deletions
diff --git a/loadlib.c b/loadlib.c
index c9e93ac7..2e5e31a6 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.94 2010/11/10 20:00:04 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.95 2011/01/07 18:54:49 roberto Exp roberto $
3** Dynamic library loader for Lua 3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5** 5**
@@ -164,7 +164,7 @@ static void pusherror (lua_State *L) {
164 int error = GetLastError(); 164 int error = GetLastError();
165 char buffer[128]; 165 char buffer[128];
166 if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, 166 if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
167 NULL, error, 0, buffer, sizeof(buffer), NULL)) 167 NULL, error, 0, buffer, sizeof(buffer)/sizeof(char), NULL))
168 lua_pushstring(L, buffer); 168 lua_pushstring(L, buffer);
169 else 169 else
170 lua_pushfstring(L, "system error %d\n", error); 170 lua_pushfstring(L, "system error %d\n", error);
diff --git a/lobject.c b/lobject.c
index cb8ead92..be00daf0 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.44 2010/12/06 21:08:36 roberto Exp roberto $ 2** $Id: lobject.c,v 2.45 2010/12/10 19:03:46 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -265,7 +265,7 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
265 265
266 266
267 267
268#define LL(x) (sizeof(x) - 1) 268#define LL(x) ((sizeof(x) - 1)/sizeof(char))
269#define RETS "..." 269#define RETS "..."
270#define PRE "[string \"" 270#define PRE "[string \""
271#define POS "\"]" 271#define POS "\"]"
diff --git a/lstrlib.c b/lstrlib.c
index 255bc51f..2efed9c0 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.162 2011/01/12 20:36:01 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.163 2011/01/26 16:30:02 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*/
@@ -808,7 +808,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
808static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { 808static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
809 const char *p = strfrmt; 809 const char *p = strfrmt;
810 while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ 810 while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
811 if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) 811 if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char))
812 luaL_error(L, "invalid format (repeated flags)"); 812 luaL_error(L, "invalid format (repeated flags)");
813 if (isdigit(uchar(*p))) p++; /* skip width */ 813 if (isdigit(uchar(*p))) p++; /* skip width */
814 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ 814 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
diff --git a/lundump.c b/lundump.c
index 184b768f..161ef1d4 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.67 2010/10/13 21:04:52 lhf Exp $ 2** $Id: lundump.c,v 2.14 2010/10/25 14:33:38 roberto Exp roberto $
3** load precompiled Lua chunks 3** load precompiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -211,8 +211,8 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
211void luaU_header (char* h) 211void luaU_header (char* h)
212{ 212{
213 int x=1; 213 int x=1;
214 memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); 214 memcpy(h,LUA_SIGNATURE,(sizeof(LUA_SIGNATURE)-1)*sizeof(char));
215 h+=sizeof(LUA_SIGNATURE)-1; 215 h+=(sizeof(LUA_SIGNATURE)-1)*sizeof(char);
216 *h++=(char)LUAC_VERSION; 216 *h++=(char)LUAC_VERSION;
217 *h++=(char)LUAC_FORMAT; 217 *h++=(char)LUAC_FORMAT;
218 *h++=(char)*(char*)&x; /* endianness */ 218 *h++=(char)*(char*)&x; /* endianness */
diff --git a/lvm.c b/lvm.c
index fc36e445..99339637 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.129 2011/02/01 18:32:55 roberto Exp roberto $ 2** $Id: lvm.c,v 2.130 2011/02/07 12:24:42 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -288,14 +288,15 @@ void luaV_concat (lua_State *L, int total) {
288 /* collect total length */ 288 /* collect total length */
289 for (n = 1; n < total && tostring(L, top-n-1); n++) { 289 for (n = 1; n < total && tostring(L, top-n-1); n++) {
290 size_t l = tsvalue(top-n-1)->len; 290 size_t l = tsvalue(top-n-1)->len;
291 if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); 291 if (l >= (MAX_SIZET/sizeof(char)) - tl)
292 luaG_runerror(L, "string length overflow");
292 tl += l; 293 tl += l;
293 } 294 }
294 buffer = luaZ_openspace(L, &G(L)->buff, tl); 295 buffer = luaZ_openspace(L, &G(L)->buff, tl);
295 tl = 0; 296 tl = 0;
296 for (i=n; i>0; i--) { /* concat all strings */ 297 for (i=n; i>0; i--) { /* concat all strings */
297 size_t l = tsvalue(top-i)->len; 298 size_t l = tsvalue(top-i)->len;
298 memcpy(buffer+tl, svalue(top-i), l); 299 memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
299 tl += l; 300 tl += l;
300 } 301 }
301 setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); 302 setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));