Skip to content

Commit

Permalink
Fix Singe 'nil arithmetic' issue, Lua 5.1 'tonumber' workaround.
Browse files Browse the repository at this point in the history
  - Time Gal and Ninja Hayate work with original byecode
  - Cleanup gcc9 warnings
  • Loading branch information
DirtBagXon committed Oct 30, 2020
1 parent 25c8446 commit 0cc0426
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/game/singe/lvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
/* limit for table tag-method chains (to avoid loops) */
#define MAXTAGLOOP 100

const TValue *luaV_tofloat (const TValue *obj, TValue *n) {
lua_Number num;
if (ttisnumber(obj)) return obj;
if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {
setnvalue(n, num);
return n;
}
else {
setnvalue(n, 0);
return n;
}
}

const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
lua_Number num;
Expand Down
3 changes: 2 additions & 1 deletion src/game/singe/lvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))

#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \
(((o) = luaV_tonumber(o,n)) != NULL))
(((o) = luaV_tofloat(o,n)) != NULL))

#define equalobj(L,o1,o2) \
(ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
Expand All @@ -25,6 +25,7 @@
LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
LUAI_FUNC const TValue *luaV_tofloat (const TValue *obj, TValue *n);
LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
StkId val);
Expand Down
4 changes: 3 additions & 1 deletion src/io/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ unsigned int get_sys_mem()
F = popen(s, "r");
if (F)
{
fscanf(F, "%u", &mem); // this breaks if they have over 2 gigs of ram :)
// this breaks if they have over 2 gigs of ram :)
if (fscanf(F, "%u", &mem) != 1)
fprintf(stderr, "Failed to read kcore!\n");
pclose(F);
}

Expand Down
3 changes: 2 additions & 1 deletion src/vldp2/vldp/vldp_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,8 @@ VLDP_BOOL ivldp_get_mpeg_frame_offsets(char *mpeg_name)
// now that file exists and we have it open, we have to read it

fseek(data_file, 0L, SEEK_SET);
fread(&header, sizeof(header), 1, data_file); // read .DAT file header
if (fread(&header, sizeof(header), 1, data_file) != 1)
fprintf(stderr, "Failed to read .DAT file header!\n");

// if version, file size, or finished are wrong, the dat file is no good and has to be regenerated
if ((header.length != mpeg_size) || (header.version != DAT_VERSION) || (header.finished != 1))
Expand Down

0 comments on commit 0cc0426

Please sign in to comment.