From ca2556c618edd30d95540ce4009a37ee97406495 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 Feb 2011 23:52:28 -0800 Subject: [PATCH] fix a segmentation fault when file cannot be opened --- src/bindings/bind_storage.c | 8 +++++--- src/kernel/binarystore.c | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bindings/bind_storage.c b/src/bindings/bind_storage.c index 23b9a0a5a..a8914a5cb 100644 --- a/src/bindings/bind_storage.c +++ b/src/bindings/bind_storage.c @@ -58,9 +58,11 @@ tolua_storage_read_unit(lua_State *L) static int 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); - write_unit(self, u); + if (store->version) { + write_unit(store, u); + } return 0; } @@ -87,7 +89,7 @@ static int tolua_storage_write(lua_State *L) { 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); double n; if (modf(num, &n)==0.0) { diff --git a/src/kernel/binarystore.c b/src/kernel/binarystore.c index 13780c981..3c35183bc 100644 --- a/src/kernel/binarystore.c +++ b/src/kernel/binarystore.c @@ -264,6 +264,7 @@ bin_open(struct storage * store, const char * filename, int mode) store->w_int = bin_w_int; } } else if (store->encoding==XML_CHAR_ENCODING_UTF8) { + store->version = RELEASE_VERSION; bin_w_int(store, RELEASE_VERSION); bin_w_int(store, STREAM_VERSION); }