all chars used in binary dumps are unsigned ('lu_byte')

This commit is contained in:
Roberto Ierusalimschy 2014-02-28 09:25:12 -03:00
parent de84b3fecb
commit 93e28031de
2 changed files with 23 additions and 24 deletions

36
ldump.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldump.c,v 2.20 2014/02/27 16:56:20 roberto Exp roberto $ ** $Id: ldump.c,v 2.21 2014/02/27 18:56:15 roberto Exp roberto $
** save precompiled Lua chunks ** save precompiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -36,9 +36,9 @@ static void DumpBlock(const void* b, size_t size, DumpState* D)
} }
} }
static void DumpChar(int y, DumpState* D) static void DumpByte(int y, DumpState* D)
{ {
char x=(char)y; lu_byte x=(lu_byte)y;
DumpVar(x,D); DumpVar(x,D);
} }
@ -89,13 +89,13 @@ static void DumpConstants(const Proto* f, DumpState* D)
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
const TValue* o=&f->k[i]; const TValue* o=&f->k[i];
DumpChar(ttype(o),D); DumpByte(ttype(o),D);
switch (ttype(o)) switch (ttype(o))
{ {
case LUA_TNIL: case LUA_TNIL:
break; break;
case LUA_TBOOLEAN: case LUA_TBOOLEAN:
DumpChar(bvalue(o),D); DumpByte(bvalue(o),D);
break; break;
case LUA_TNUMFLT: case LUA_TNUMFLT:
DumpNumber(fltvalue(o),D); DumpNumber(fltvalue(o),D);
@ -120,8 +120,8 @@ static void DumpUpvalues(const Proto* f, DumpState* D)
DumpInt(n,D); DumpInt(n,D);
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
DumpChar(f->upvalues[i].instack,D); DumpByte(f->upvalues[i].instack,D);
DumpChar(f->upvalues[i].idx,D); DumpByte(f->upvalues[i].idx,D);
} }
} }
@ -148,9 +148,9 @@ static void DumpFunction(const Proto* f, DumpState* D)
{ {
DumpInt(f->linedefined,D); DumpInt(f->linedefined,D);
DumpInt(f->lastlinedefined,D); DumpInt(f->lastlinedefined,D);
DumpChar(f->numparams,D); DumpByte(f->numparams,D);
DumpChar(f->is_vararg,D); DumpByte(f->is_vararg,D);
DumpChar(f->maxstacksize,D); DumpByte(f->maxstacksize,D);
DumpCode(f,D); DumpCode(f,D);
DumpConstants(f,D); DumpConstants(f,D);
DumpUpvalues(f,D); DumpUpvalues(f,D);
@ -161,13 +161,13 @@ static void DumpHeader(DumpState* D)
{ {
DumpBlock(LUA_SIGNATURE,sizeof(LUA_SIGNATURE),D); DumpBlock(LUA_SIGNATURE,sizeof(LUA_SIGNATURE),D);
DumpBlock(LUAC_DATA,sizeof(LUAC_DATA),D); DumpBlock(LUAC_DATA,sizeof(LUAC_DATA),D);
DumpChar(LUAC_VERSION,D); DumpByte(LUAC_VERSION,D);
DumpChar(LUAC_FORMAT,D); DumpByte(LUAC_FORMAT,D);
DumpChar(sizeof(int),D); DumpByte(sizeof(int),D);
DumpChar(sizeof(size_t),D); DumpByte(sizeof(size_t),D);
DumpChar(sizeof(Instruction),D); DumpByte(sizeof(Instruction),D);
DumpChar(sizeof(lua_Integer),D); DumpByte(sizeof(lua_Integer),D);
DumpChar(sizeof(lua_Number),D); DumpByte(sizeof(lua_Number),D);
DumpInteger(LUAC_INT,D); DumpInteger(LUAC_INT,D);
DumpNumber(LUAC_NUM,D); DumpNumber(LUAC_NUM,D);
} }
@ -184,7 +184,7 @@ int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip
D.strip=strip; D.strip=strip;
D.status=0; D.status=0;
DumpHeader(&D); DumpHeader(&D);
DumpChar(f->sizeupvalues,&D); DumpByte(f->sizeupvalues,&D);
DumpFunction(f,&D); DumpFunction(f,&D);
return D.status; return D.status;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lundump.c,v 2.26 2014/02/27 16:56:20 roberto Exp roberto $ ** $Id: lundump.c,v 2.27 2014/02/27 18:56:15 roberto Exp roberto $
** load precompiled Lua chunks ** load precompiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -34,7 +34,6 @@ static l_noret error(LoadState* S, const char* why)
} }
#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) #define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
#define LoadByte(S) (lu_byte)LoadChar(S)
#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) #define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
#define LoadVector(S,b,n,size) LoadMem(S,b,n,size) #define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
@ -47,9 +46,9 @@ static void LoadBlock(LoadState* S, void* b, size_t size)
if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated"); if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated");
} }
static int LoadChar(LoadState* S) static lu_byte LoadByte(LoadState* S)
{ {
char x; lu_byte x;
LoadVar(S,x); LoadVar(S,x);
return x; return x;
} }
@ -110,14 +109,14 @@ static void LoadConstants(LoadState* S, Proto* f)
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
TValue* o=&f->k[i]; TValue* o=&f->k[i];
int t=LoadChar(S); int t=LoadByte(S);
switch (t) switch (t)
{ {
case LUA_TNIL: case LUA_TNIL:
setnilvalue(o); setnilvalue(o);
break; break;
case LUA_TBOOLEAN: case LUA_TBOOLEAN:
setbvalue(o,LoadChar(S)); setbvalue(o,LoadByte(S));
break; break;
case LUA_TNUMFLT: case LUA_TNUMFLT:
setnvalue(o,LoadNumber(S)); setnvalue(o,LoadNumber(S));