aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua/wslua_dissector.c
diff options
context:
space:
mode:
authorMartin Kaiser <wireshark@kaiser.cx>2019-06-10 20:23:34 +0200
committerAnders Broman <a.broman58@gmail.com>2019-06-16 02:15:05 +0000
commit13795914a13fc559800aa123f29171b8d700e22d (patch)
treeeefb1189e90a5664686759cf6130333b2cdcc47a /epan/wslua/wslua_dissector.c
parentfea4856667a68e356dab5efce33b997c24d36a36 (diff)
wslua: clean up DissectorTable_new()
Reorder the code to have a single return statement at the end. Take advantage of the fact that WSLUA_OPTARG_ERROR terminates the C function that called it. Do only the parameter checks in the switch-case statement. Get rid of the intermediate steps when we copy name and ui_name. Change-Id: Ie8917d19589a6ee16a4a5d14f2c1711d35cc8114 Reviewed-on: https://code.wireshark.org/review/33607 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/wslua/wslua_dissector.c')
-rw-r--r--epan/wslua/wslua_dissector.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/epan/wslua/wslua_dissector.c b/epan/wslua/wslua_dissector.c
index 0d7590e6ec..4a6b383dce 100644
--- a/epan/wslua/wslua_dissector.c
+++ b/epan/wslua/wslua_dissector.c
@@ -175,45 +175,50 @@ WSLUA_CONSTRUCTOR DissectorTable_new (lua_State *L) {
const gchar* ui_name = (const gchar*)luaL_optstring(L,WSLUA_OPTARG_DissectorTable_new_UINAME,name);
enum ftenum type = (enum ftenum)luaL_optinteger(L,WSLUA_OPTARG_DissectorTable_new_TYPE,FT_UINT32);
unsigned base = (unsigned)luaL_optinteger(L,WSLUA_OPTARG_DissectorTable_new_BASE,BASE_DEC);
+ DissectorTable dt;
switch(type) {
case FT_STRING:
base = BASE_NONE;
- /* fallthrough */
+ break;
+
case FT_NONE:
- /* fallthrough */
+ break;
+
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
- {
- DissectorTable dt = (DissectorTable)g_malloc(sizeof(struct _wslua_distbl_t));
-
- name = g_strdup(name);
- ui_name = g_strdup(ui_name);
-
- /* XXX - can't determine dependencies of Lua protocols if they don't provide protocol name */
- dt->table = (type == FT_NONE) ?
- register_decode_as_next_proto(-1, name, ui_name, NULL) :
- register_dissector_table(name, ui_name, -1, type, base);
- dt->name = name;
- dt->ui_name = ui_name;
- dt->created = TRUE;
- dt->expired = FALSE;
-
- lua_rawgeti(L, LUA_REGISTRYINDEX, dissectortable_table_ref);
- lua_pushstring(L, name);
- pushDissectorTable(L, dt);
- lua_settable(L, -3);
-
- pushDissectorTable(L, dt);
- }
- WSLUA_RETURN(1); /* The newly created DissectorTable. */
+ break;
+
default:
- WSLUA_OPTARG_ERROR(DissectorTable_new,TYPE,"must be ftypes.UINT{8,16,24,32}, ftypes.STRING or ftypes.NONE");
+ /* Calling WSLUA_OPTARG_ERROR raises a Lua error and
+ returns from this function. */
+ WSLUA_OPTARG_ERROR(
+ DissectorTable_new, TYPE,
+ "must be ftypes.UINT{8,16,24,32}, ftypes.STRING or ftypes.NONE");
break;
}
- return 0;
+
+ dt = (DissectorTable)g_malloc(sizeof(struct _wslua_distbl_t));
+
+ /* XXX - can't determine dependencies of Lua protocols
+ if they don't provide protocol name */
+ dt->table = (type == FT_NONE) ?
+ register_decode_as_next_proto(-1, name, ui_name, NULL) :
+ register_dissector_table(name, ui_name, -1, type, base);
+ dt->name = g_strdup(name);
+ dt->ui_name = g_strdup(ui_name);
+ dt->created = TRUE;
+ dt->expired = FALSE;
+
+ lua_rawgeti(L, LUA_REGISTRYINDEX, dissectortable_table_ref);
+ lua_pushstring(L, name);
+ pushDissectorTable(L, dt);
+ lua_settable(L, -3);
+
+ pushDissectorTable(L, dt);
+ WSLUA_RETURN(1); /* The newly created DissectorTable. */
}
/* this struct is used for passing ourselves user_data through dissector_all_tables_foreach_table(). */