fix a segmentation fault when file cannot be opened

This commit is contained in:
Enno Rehling 2011-02-26 23:52:28 -08:00
parent 59f3ebef68
commit ca2556c618
2 changed files with 6 additions and 3 deletions

View File

@ -58,9 +58,11 @@ tolua_storage_read_unit(lua_State *L)
static int static int
tolua_storage_write_unit(lua_State *L) tolua_storage_write_unit(lua_State *L)
{ {
storage * self = (storage *)tolua_tousertype(L, 1, 0); storage * store = (storage *)tolua_tousertype(L, 1, 0);
struct unit * u = (struct unit *)tolua_tousertype(L, 2, 0); struct unit * u = (struct unit *)tolua_tousertype(L, 2, 0);
write_unit(self, u); if (store->version) {
write_unit(store, u);
}
return 0; return 0;
} }
@ -87,7 +89,7 @@ static int
tolua_storage_write(lua_State *L) tolua_storage_write(lua_State *L)
{ {
storage * self = (storage *)tolua_tousertype(L, 1, 0); storage * self = (storage *)tolua_tousertype(L, 1, 0);
if (tolua_isnumber(L, 2, 0, 0)) { if (self->version && tolua_isnumber(L, 2, 0, 0)) {
lua_Number num = tolua_tonumber(L, 2, 0); lua_Number num = tolua_tonumber(L, 2, 0);
double n; double n;
if (modf(num, &n)==0.0) { if (modf(num, &n)==0.0) {

View File

@ -264,6 +264,7 @@ bin_open(struct storage * store, const char * filename, int mode)
store->w_int = bin_w_int; store->w_int = bin_w_int;
} }
} else if (store->encoding==XML_CHAR_ENCODING_UTF8) { } else if (store->encoding==XML_CHAR_ENCODING_UTF8) {
store->version = RELEASE_VERSION;
bin_w_int(store, RELEASE_VERSION); bin_w_int(store, RELEASE_VERSION);
bin_w_int(store, STREAM_VERSION); bin_w_int(store, STREAM_VERSION);
} }