diff options
author | Peter Wu <peter@lekensteyn.nl> | 2016-04-03 11:10:02 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2016-06-14 18:33:51 +0000 |
commit | e86af3a5fc0d236925a818c4f6ce673ed9dcf4ec (patch) | |
tree | 6d2a75749b69e9d800cb9844f5db74ad712d77a1 | |
parent | f6e223c89540c6acc8a89244f050189f88ecfb78 (diff) |
wslua: remove FAIL_ON_NULL_MEMBER_OR_EXPIRED
Ensure that the member cannot be NULL at initialization, simplifies
checkCaptureInfo and checkCaptureInfoConst logic.
Change-Id: I2d9caa4a235310569ebbf0b30199dd3df7a4c093
Reviewed-on: https://code.wireshark.org/review/14791
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r-- | epan/wslua/wslua.h | 8 | ||||
-rw-r--r-- | epan/wslua/wslua_capture_info.c | 20 |
2 files changed, 16 insertions, 12 deletions
diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index 8211d839c5..32f5bcb2ec 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -645,14 +645,6 @@ extern int wslua_set__index(lua_State *L); #define FAIL_ON_NULL(s) if (! *p) luaL_argerror(L,idx,"null " s) -#define FAIL_ON_NULL_MEMBER_OR_EXPIRED(s,member) if (!*p) { \ - luaL_argerror(L,idx,"null " s); \ - } else if ((*p)->member == NULL) { \ - luaL_argerror(L,idx,"null " s " member " #member); \ - } else if ((*p)->expired) { \ - luaL_argerror(L,idx,"expired " s); \ - } - #define FAIL_ON_NULL_OR_EXPIRED(s) if (!*p) { \ luaL_argerror(L,idx,"null " s); \ } else if ((*p)->expired) { \ diff --git a/epan/wslua/wslua_capture_info.c b/epan/wslua/wslua_capture_info.c index a05d9e44e0..e63a1516ee 100644 --- a/epan/wslua/wslua_capture_info.c +++ b/epan/wslua/wslua_capture_info.c @@ -34,7 +34,7 @@ /* WSLUA_CONTINUE_MODULE File */ -WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfo",wth)); +WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_OR_EXPIRED("CaptureInfo")); /* A `CaptureInfo` object, passed into Lua as an argument by `FileHandler` callback function `read_open()`, `read()`, `seek_read()`, `seq_read_close()`, and `read_close()`. @@ -50,7 +50,13 @@ WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfo",wth) */ CaptureInfo* push_CaptureInfo(lua_State* L, wtap *wth, const gboolean first_time) { - CaptureInfo f = (CaptureInfo) g_malloc0(sizeof(struct _wslua_captureinfo)); + CaptureInfo f; + + if (!wth) { + luaL_error(L, "Internal error: wth is NULL!"); + } + + f = (CaptureInfo) g_malloc0(sizeof(struct _wslua_captureinfo)); f->wth = wth; f->wdh = NULL; f->expired = FALSE; @@ -300,7 +306,7 @@ int CaptureInfo_register(lua_State* L) { } -WSLUA_CLASS_DEFINE(CaptureInfoConst,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfoConst",wdh)); +WSLUA_CLASS_DEFINE(CaptureInfoConst,FAIL_ON_NULL_OR_EXPIRED("CaptureInfoConst")); /* A `CaptureInfoConst` object, passed into Lua as an argument to the `FileHandler` callback function `write_open()`. @@ -317,7 +323,13 @@ WSLUA_CLASS_DEFINE(CaptureInfoConst,FAIL_ON_NULL_MEMBER_OR_EXPIRED("CaptureInfoC */ CaptureInfoConst* push_CaptureInfoConst(lua_State* L, wtap_dumper *wdh) { - CaptureInfoConst f = (CaptureInfoConst) g_malloc0(sizeof(struct _wslua_captureinfo)); + CaptureInfoConst f; + + if (!wdh) { + luaL_error(L, "Internal error: wdh is NULL!"); + } + + f = (CaptureInfoConst) g_malloc0(sizeof(struct _wslua_captureinfo)); f->wth = NULL; f->wdh = wdh; f->expired = FALSE; |