aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHadriel Kaplan <hadrielk@yahoo.com>2014-02-26 23:42:15 -0500
committerGerald Combs <gerald@wireshark.org>2014-02-27 21:23:09 +0000
commitc826191be02132251a9bd7cdaa44647b24bfce95 (patch)
tree61acb2aad3b0243f22abe3084564a34161891635
parentc875dc8597a6ff3a513cd6b8397626c331564f5e (diff)
Fix coverity warnings for all wslua files. (redux)
This fixes/addresses all the coverity warnings shown by the buildbots. (I hope) Change-Id: Ic2722df97c577d274e3cf3f0cbdca1902edde047 Reviewed-on: https://code.wireshark.org/review/423 Reviewed-by: Gerald Combs <gerald@wireshark.org>
-rw-r--r--epan/wslua/init_wslua.c2
-rw-r--r--epan/wslua/wslua.h53
-rw-r--r--epan/wslua/wslua_dumper.c27
-rw-r--r--epan/wslua/wslua_field.c28
-rw-r--r--epan/wslua/wslua_gui.c99
-rw-r--r--epan/wslua/wslua_int64.c43
-rw-r--r--epan/wslua/wslua_internals.c4
-rw-r--r--epan/wslua/wslua_listener.c5
-rw-r--r--epan/wslua/wslua_pinfo.c24
-rw-r--r--epan/wslua/wslua_proto.c184
-rw-r--r--epan/wslua/wslua_struct.c10
-rw-r--r--epan/wslua/wslua_tree.c8
-rw-r--r--epan/wslua/wslua_tvb.c36
-rw-r--r--epan/wslua/wslua_util.c31
14 files changed, 383 insertions, 171 deletions
diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c
index 447ba2f382..d4b11a5d23 100644
--- a/epan/wslua/init_wslua.c
+++ b/epan/wslua/init_wslua.c
@@ -115,7 +115,7 @@ int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data
/* if the Lua dissector reported the consumed bytes, pass it to our caller */
if (lua_isnumber(L, -1)) {
/* we got the consumed bytes or the missing bytes as a negative number */
- consumed_bytes = (int) lua_tonumber(L, -1);
+ consumed_bytes = wslua_togint(L, -1);
lua_pop(L, 1);
}
}
diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h
index 05045e3a5f..8746b93791 100644
--- a/epan/wslua/wslua.h
+++ b/epan/wslua/wslua.h
@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <math.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
@@ -68,6 +69,31 @@
#define WSLUA_PREFS_CHANGED "prefs_changed"
#define LOG_DOMAIN_LUA "wslua"
+/* type conversion macros - lua_Number is a double, so casting isn't kosher; and
+ using Lua's already-available lua_tointeger() and luaL_checkint() might be different
+ on different machines; so use these instead please! */
+#define wslua_togint(L,i) (gint) ( lua_tointeger(L,i) )
+#define wslua_togint32(L,i) (gint32) lround ( lua_tonumber(L,i) )
+#define wslua_togint64(L,i) (gint64) llround ( lua_tonumber(L,i) )
+#define wslua_toguint(L,i) (guint) ( lua_tointeger(L,i) )
+#define wslua_toguint32(L,i) (guint32) lround ( lua_tonumber(L,i) )
+#define wslua_toguint64(L,i) (guint64) llround ( lua_tonumber(L,i) )
+
+#define wslua_checkgint(L,i) (gint) ( luaL_checkint(L,i) )
+#define wslua_checkgint32(L,i) (gint32) lround ( luaL_checknumber(L,i) )
+#define wslua_checkgint64(L,i) (gint64) llround ( luaL_checknumber(L,i) )
+#define wslua_checkguint(L,i) (guint) ( luaL_checkint(L,i) )
+#define wslua_checkguint32(L,i) (guint32) lround ( luaL_checknumber(L,i) )
+#define wslua_checkguint64(L,i) (guint64) llround ( luaL_checknumber(L,i) )
+
+#define wslua_optgint(L,i,d) (gint) ( luaL_optint(L,i,d) )
+#define wslua_optgint32(L,i,d) (gint32) lround ( luaL_optnumber(L,i,d) )
+#define wslua_optgint64(L,i,d) (gint64) llround ( luaL_optnumber(L,i,d) )
+#define wslua_optguint(L,i,d) (guint) ( luaL_optint(L,i,d) )
+#define wslua_optguint32(L,i,d) (guint32) lround ( luaL_optnumber(L,i,d) )
+#define wslua_optguint64(L,i,d) (guint64) llround ( luaL_optnumber(L,i,d) )
+
+
struct _wslua_tvb {
tvbuff_t* ws_tvb;
gboolean expired;
@@ -124,7 +150,7 @@ typedef struct _wslua_pref_t {
union {
gboolean b;
guint u;
- const gchar* s;
+ gchar* s;
gint e;
range_t *r;
void* p;
@@ -424,14 +450,18 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb
return luaL_error(L, "%s's attribute `%s' must be a function", #C , #field ); \
obj->field##_ref = luaL_ref(L, LUA_REGISTRYINDEX); \
return 0; \
- }
+ } \
+ /* silly little trick so we can add a semicolon after this macro */ \
+ static int C##_set_##field(lua_State*)
#define WSLUA_ATTRIBUTE_GET(C,name,block) \
static int C##_get_##name (lua_State* L) { \
C obj = check##C (L,1); \
block \
return 1; \
- }
+ } \
+ /* silly little trick so we can add a semicolon after this macro */ \
+ static int C##_get_##name(lua_State*)
#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(C,name,member) \
WSLUA_ATTRIBUTE_GET(C,name,{lua_pushboolean(L, obj->member );})
@@ -459,22 +489,26 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb
C obj = check##C (L,1); \
block; \
return 0; \
- }
+ } \
+ /* silly little trick so we can add a semicolon after this macro */ \
+ static int C##_set_##name(lua_State*)
+/* to make this integral-safe, we treat it as int32 and then cast
+ Note: this will truncate 64-bit integers (but then Lua itself only has doubles */
#define WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(C,name,member,cast) \
WSLUA_ATTRIBUTE_SET(C,name, { \
if (! lua_isnumber(L,-1) ) \
return luaL_error(L, "%s's attribute `%s' must be a number", #C , #name ); \
- obj->member = (cast) lua_tointeger(L,-1); \
+ obj->member = (cast) wslua_togint32(L,-1); \
})
#define WSLUA_ATTRIBUTE_NUMBER_SETTER(C,member,cast) \
WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(C,member,member,cast)
-#define WSLUA_ERROR(name,error) { luaL_error(L, ep_strdup_printf("%s%s", #name ": " ,error) ); return 0; }
-#define WSLUA_ARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); return 0; }
-#define WSLUA_OPTARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); return 0; }
+#define WSLUA_ERROR(name,error) { luaL_error(L, ep_strdup_printf("%s%s", #name ": " ,error) ); }
+#define WSLUA_ARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); }
+#define WSLUA_OPTARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); }
#define WSLUA_REG_GLOBAL_BOOL(L,n,v) { lua_pushboolean(L,v); lua_setglobal(L,n); }
#define WSLUA_REG_GLOBAL_STRING(L,n,v) { lua_pushstring(L,v); lua_setglobal(L,n); }
@@ -484,7 +518,8 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb
#define WSLUA_API extern
-#define NOP
+/* empty macro arguments trigger ISO C90 warnings, so do this */
+#define NOP (void)p
#define FAIL_ON_NULL(s) if (! *p) luaL_argerror(L,idx,"null " s)
#define FAIL_ON_NULL_OR_EXPIRED(s) if (!*p) { \
luaL_argerror(L,idx,"null " s); \
diff --git a/epan/wslua/wslua_dumper.c b/epan/wslua/wslua_dumper.c
index 6da3f4003e..7db98ef41a 100644
--- a/epan/wslua/wslua_dumper.c
+++ b/epan/wslua/wslua_dumper.c
@@ -253,8 +253,10 @@ WSLUA_METHOD Dumper_close(lua_State* L) {
Dumper* dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
int err;
- if (! *dp)
+ if (! *dp) {
WSLUA_ERROR(Dumper_close,"Cannot operate on a closed dumper");
+ return 0;
+ }
g_hash_table_remove(dumper_encaps,*dp);
@@ -303,16 +305,22 @@ WSLUA_METHOD Dumper_dump(lua_State* L) {
ts = luaL_checknumber(L,WSLUA_ARG_Dumper_dump_TIMESTAMP);
ph = checkPseudoHeader(L,WSLUA_ARG_Dumper_dump_PSEUDOHEADER);
- if (!ph) WSLUA_ARG_ERROR(Dumper_dump,TIMESTAMP,"need a PseudoHeader");
+ if (!ph) {
+ WSLUA_ARG_ERROR(Dumper_dump,TIMESTAMP,"need a PseudoHeader");
+ return 0;
+ }
ba = checkByteArray(L,WSLUA_ARG_Dumper_dump_BYTEARRAY);
- if (! ba) WSLUA_ARG_ERROR(Dumper_dump,BYTEARRAY,"must be a ByteArray");
+ if (! ba) {
+ WSLUA_ARG_ERROR(Dumper_dump,BYTEARRAY,"must be a ByteArray");
+ return 0;
+ }
memset(&pkthdr, 0, sizeof(pkthdr));
- pkthdr.ts.secs = (unsigned)floor(ts);
- pkthdr.ts.nsecs = (unsigned)floor((ts - (double)pkthdr.ts.secs) * 1000000000);
+ pkthdr.ts.secs = (unsigned int)(floor(ts));
+ pkthdr.ts.nsecs = (unsigned int)(floor((ts - (double)pkthdr.ts.secs) * 1000000000));
pkthdr.len = ba->len;
pkthdr.caplen = ba->len;
@@ -347,8 +355,10 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) {
filename = cross_plat_fname(fname);
- if (! lua_pinfo )
+ if (! lua_pinfo ) {
WSLUA_ERROR(Dumper_new_for_current,"Cannot be used outside a tap or a dissector");
+ return 0;
+ }
encap = lua_pinfo->fd->lnk_t;
@@ -394,7 +404,10 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) {
if (!d) return 0;
- if (! lua_pinfo ) WSLUA_ERROR(Dumper_new_for_current,"Cannot be used outside a tap or a dissector");
+ if (! lua_pinfo ) {
+ WSLUA_ERROR(Dumper_new_for_current,"Cannot be used outside a tap or a dissector");
+ return 0;
+ }
data_src = (struct data_source*) (lua_pinfo->data_src->data);
if (!data_src)
diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c
index 5fc5930ed7..0ad986d46b 100644
--- a/epan/wslua/wslua_field.c
+++ b/epan/wslua/wslua_field.c
@@ -86,20 +86,20 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) {
case FT_UINT24:
case FT_UINT32:
case FT_FRAMENUM:
- lua_pushnumber(L,(lua_Number)fvalue_get_uinteger(&(fi->ws_fi->value)));
+ lua_pushnumber(L,(lua_Number)(fvalue_get_uinteger(&(fi->ws_fi->value))));
return 1;
case FT_INT8:
case FT_INT16:
case FT_INT24:
case FT_INT32:
- lua_pushnumber(L,(lua_Number)fvalue_get_sinteger(&(fi->ws_fi->value)));
+ lua_pushnumber(L,(lua_Number)(fvalue_get_sinteger(&(fi->ws_fi->value))));
return 1;
case FT_FLOAT:
case FT_DOUBLE:
- lua_pushnumber(L,(lua_Number)fvalue_get_floating(&(fi->ws_fi->value)));
+ lua_pushnumber(L,(lua_Number)(fvalue_get_floating(&(fi->ws_fi->value))));
return 1;
case FT_INT64: {
- pushInt64(L,(Int64)fvalue_get_integer64(&(fi->ws_fi->value)));
+ pushInt64(L,(Int64)(fvalue_get_integer64(&(fi->ws_fi->value))));
return 1;
}
case FT_UINT64: {
@@ -266,8 +266,10 @@ WSLUA_METAMETHOD FieldInfo__eq(lua_State* L) {
FieldInfo l = checkFieldInfo(L,1);
FieldInfo r = checkFieldInfo(L,2);
- if (l->ws_fi->ds_tvb != r->ws_fi->ds_tvb)
+ if (l->ws_fi->ds_tvb != r->ws_fi->ds_tvb) {
WSLUA_ERROR(FieldInfo__eq,"Data source must be the same for both fields");
+ return 0;
+ }
if (l->ws_fi->start <= r->ws_fi->start && r->ws_fi->start + r->ws_fi->length <= l->ws_fi->start + r->ws_fi->length) {
lua_pushboolean(L,1);
@@ -298,8 +300,10 @@ WSLUA_METAMETHOD FieldInfo__lt(lua_State* L) {
FieldInfo l = checkFieldInfo(L,1);
FieldInfo r = checkFieldInfo(L,2);
- if (l->ws_fi->ds_tvb != r->ws_fi->ds_tvb)
+ if (l->ws_fi->ds_tvb != r->ws_fi->ds_tvb) {
WSLUA_ERROR(FieldInfo__lt,"Data source must be the same for both fields");
+ return 0;
+ }
if (r->ws_fi->start + r->ws_fi->length < l->ws_fi->start) {
lua_pushboolean(L,1);
@@ -372,6 +376,7 @@ WSLUA_FUNCTION wslua_all_field_infos(lua_State* L) {
if (! lua_tree || ! lua_tree->tree ) {
WSLUA_ERROR(wslua_all_field_infos,"Cannot be called outside a listener or dissector");
+ return 0;
}
found = proto_all_finfos(lua_tree->tree);
@@ -480,14 +485,18 @@ WSLUA_CONSTRUCTOR Field_new(lua_State *L) {
if (!name) return 0;
- if (!proto_registrar_get_byname(name) && !wslua_is_field_available(L, name))
+ if (!proto_registrar_get_byname(name) && !wslua_is_field_available(L, name)) {
WSLUA_ARG_ERROR(Field_new,FIELDNAME,"a field with this name must exist");
+ return 0;
+ }
- if (!wanted_fields)
+ if (!wanted_fields) {
WSLUA_ERROR(Field_new,"A Field extractor must be defined before Taps or Dissectors get called");
+ return 0;
+ }
f = (Field)g_malloc(sizeof(void*));
- *f = (header_field_info*)g_strdup(name); /* cheating */
+ *f = (header_field_info*)(void*)g_strdup(name); /* cheating */
g_ptr_array_add(wanted_fields,f);
@@ -536,6 +545,7 @@ WSLUA_METAMETHOD Field__call (lua_State* L) {
if (! lua_pinfo ) {
WSLUA_ERROR(Field__call,"Fields cannot be used outside dissectors or taps");
+ return 0;
}
while (in) {
diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c
index 81475d9bf0..3ddaace9ce 100644
--- a/epan/wslua/wslua_gui.c
+++ b/epan/wslua/wslua_gui.c
@@ -95,16 +95,22 @@ WSLUA_FUNCTION wslua_register_menu(lua_State* L) { /* Register a menu item in o
const gchar* name = luaL_checkstring(L,WSLUA_ARG_register_menu_NAME);
struct _lua_menu_data* md;
gboolean retap = FALSE;
- register_stat_group_t group = (register_stat_group_t)luaL_optnumber(L,WSLUA_OPTARG_register_menu_GROUP,REGISTER_STAT_GROUP_GENERIC);
+ register_stat_group_t group = (register_stat_group_t)wslua_optguint(L,WSLUA_OPTARG_register_menu_GROUP,REGISTER_STAT_GROUP_GENERIC);
- if ( group > REGISTER_TOOLS_GROUP_UNSORTED)
+ if ( group > REGISTER_TOOLS_GROUP_UNSORTED) {
WSLUA_OPTARG_ERROR(register_menu,GROUP,"Must be a defined MENU_* (see init.lua)");
+ return 0;
+ }
- if(!name)
+ if(!name) {
WSLUA_ARG_ERROR(register_menu,NAME,"Must be a string");
+ return 0;
+ }
- if (!lua_isfunction(L,WSLUA_ARG_register_menu_ACTION))
+ if (!lua_isfunction(L,WSLUA_ARG_register_menu_ACTION)) {
WSLUA_ARG_ERROR(register_menu,ACTION,"Must be a function");
+ return 0;
+ }
md = (struct _lua_menu_data *)g_malloc(sizeof(struct _lua_menu_data));
md->L = L;
@@ -232,18 +238,22 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */
if (!ops->new_dialog) {
WSLUA_ERROR(new_dialog,"GUI not available");
+ return 0;
}
if (! (title = luaL_checkstring(L,WSLUA_ARG_new_dialog_TITLE)) ) {
WSLUA_ARG_ERROR(new_dialog,TITLE,"Must be a string");
+ return 0;
}
if (! lua_isfunction(L,WSLUA_ARG_new_dialog_ACTION)) {
WSLUA_ARG_ERROR(new_dialog,ACTION,"Must be a function");
+ return 0;
}
if (top < 3) {
WSLUA_ERROR(new_dialog,"At least one field required");
+ return 0;
}
@@ -261,20 +271,22 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */
top -= 2;
for (i = 1; i <= top; i++) {
- const char* label = luaL_checkstring(L,i);
+ gchar* label = g_strdup(luaL_checkstring(L,i));
- /* XXX leaks labels on error */
- if (! label)
+ if (! label) {
+ g_ptr_array_free(labels,TRUE);
WSLUA_ERROR(new_dialog,"All fields must be strings");
+ return 0;
+ }
g_ptr_array_add(labels,(gpointer)label);
}
g_ptr_array_add(labels,NULL);
- ops->new_dialog(title, (const gchar**)labels->pdata, lua_dialog_cb, dcbd);
+ ops->new_dialog(title, (const gchar**)(labels->pdata), lua_dialog_cb, dcbd);
- g_ptr_array_free(labels,FALSE);
+ g_ptr_array_free(labels,TRUE);
WSLUA_RETURN(0);
}
@@ -295,6 +307,7 @@ WSLUA_CONSTRUCTOR ProgDlg_new(lua_State* L) { /* Creates a new TextWindow. */
pd->pw = ops->new_progress_window(pd->title,pd->task,TRUE,&(pd->stopped));
} else {
WSLUA_ERROR(ProgDlg_new, "GUI not available");
+ return 0;
}
pushProgDlg(L,pd);
@@ -311,6 +324,7 @@ WSLUA_METHOD ProgDlg_update(lua_State* L) { /* Appends text */
if (!ops->update_progress) {
WSLUA_ERROR(ProgDlg_update,"GUI not available");
+ return 0;
}
g_free(pd->task);
@@ -325,6 +339,7 @@ WSLUA_METHOD ProgDlg_update(lua_State* L) { /* Appends text */
ops->update_progress(pd->pw, (float) pr, task);
} else {
WSLUA_ERROR(ProgDlg_update,"Progress value out of range (must be between 0.0 and 1.0)");
+ return 0;
}
return 0;
@@ -345,6 +360,7 @@ WSLUA_METHOD ProgDlg_close(lua_State* L) { /* Appends text */
if (!ops->destroy_progress_window) {
WSLUA_ERROR(ProgDlg_close,"GUI not available");
+ return 0;
}
if (pd->pw) {
@@ -420,6 +436,7 @@ WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /* Creates a new TextWindow. */
if (!ops->new_text_window || !ops->set_close_cb) {
WSLUA_ERROR(TextWindow_new,"GUI not available");
+ return 0;
}
title = luaL_optstring(L,WSLUA_OPTARG_TextWindow_new_TITLE,"Untitled Window");
@@ -448,12 +465,15 @@ WSLUA_METHOD TextWindow_set_atclose(lua_State* L) { /* Set the function that wil
if (!ops->set_close_cb) {
WSLUA_ERROR(TextWindow_set_atclose,"GUI not available");
+ return 0;
}
lua_settop(L,2);
- if (! lua_isfunction(L,2))
+ if (! lua_isfunction(L,2)) {
WSLUA_ARG_ERROR(TextWindow_at_close,ACTION,"Must be a function");
+ return 0;
+ }
cbd = (struct _close_cb_data *)g_malloc(sizeof(struct _close_cb_data));
@@ -472,11 +492,15 @@ WSLUA_METHOD TextWindow_set(lua_State* L) { /* Sets the text. */
TextWindow tw = checkTextWindow(L,1);
const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_set_TEXT);
- if (!ops->set_text)
+ if (!ops->set_text) {
WSLUA_ERROR(TextWindow_set,"GUI not available");
+ return 0;
+ }
- if (!text)
+ if (!text) {
WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Must be a string");
+ return 0;
+ }
ops->set_text(tw->ws_tw,text);
@@ -488,11 +512,15 @@ WSLUA_METHOD TextWindow_append(lua_State* L) { /* Appends text */
TextWindow tw = checkTextWindow(L,1);
const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_append_TEXT);
- if (!ops->append_text)
+ if (!ops->append_text) {
WSLUA_ERROR(TextWindow_append,"GUI not available");
+ return 0;
+ }
- if (!text)
+ if (!text) {
WSLUA_ARG_ERROR(TextWindow_append,TEXT,"Must be a string");
+ return 0;
+ }
ops->append_text(tw->ws_tw,text);
@@ -504,11 +532,15 @@ WSLUA_METHOD TextWindow_prepend(lua_State* L) { /* Prepends text */
TextWindow tw = checkTextWindow(L,1);
const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_prepend_TEXT);
- if (!ops->prepend_text)
+ if (!ops->prepend_text) {
WSLUA_ERROR(TextWindow_prepend,"GUI not available");
+ return 0;
+ }
- if (!text)
+ if (!text) {
WSLUA_ARG_ERROR(TextWindow_prepend,TEXT,"Must be a string");
+ return 0;
+ }
ops->prepend_text(tw->ws_tw,text);
@@ -518,8 +550,10 @@ WSLUA_METHOD TextWindow_prepend(lua_State* L) { /* Prepends text */
WSLUA_METHOD TextWindow_clear(lua_State* L) { /* Erases all text in the window. */
TextWindow tw = checkTextWindow(L,1);
- if (!ops->clear_text)
+ if (!ops->clear_text) {
WSLUA_ERROR(TextWindow_clear,"GUI not available");
+ return 0;
+ }
ops->clear_text(tw->ws_tw);
@@ -530,8 +564,10 @@ WSLUA_METHOD TextWindow_get_text(lua_State* L) { /* Get the text of the window *
TextWindow tw = checkTextWindow(L,1);
const gchar* text;
- if (!ops->get_text)
+ if (!ops->get_text) {
WSLUA_ERROR(TextWindow_get_text,"GUI not available");
+ return 0;
+ }
text = ops->get_text(tw->ws_tw);
@@ -564,8 +600,10 @@ WSLUA_METHOD TextWindow_set_editable(lua_State* L) { /* Make this window editabl
TextWindow tw = checkTextWindow(L,1);
gboolean editable = wslua_optbool(L,WSLUA_OPTARG_TextWindow_set_editable_EDITABLE,TRUE);
- if (!ops->set_editable)
+ if (!ops->set_editable) {
WSLUA_ERROR(TextWindow_set_editable,"GUI not available");
+ return 0;
+ }
ops->set_editable(tw->ws_tw,editable);
@@ -614,11 +652,15 @@ WSLUA_METHOD TextWindow_add_button(lua_State* L) {
funnel_bt_t* fbt;
wslua_bt_cb_t* cbd;
- if (!ops->add_button)
+ if (!ops->add_button) {
WSLUA_ERROR(TextWindow_add_button,"GUI not available");
+ return 0;
+ }
- if (! lua_isfunction(L,WSLUA_ARG_TextWindow_add_button_FUNCTION) )
+ if (! lua_isfunction(L,WSLUA_ARG_TextWindow_add_button_FUNCTION) ) {
WSLUA_ARG_ERROR(TextWindow_add_button,FUNCTION,"must be a function");
+ return 0;
+ }
lua_settop(L,3);
@@ -691,10 +733,12 @@ WSLUA_FUNCTION wslua_copy_to_clipboard(lua_State* L) { /* Copy a string into the
GString* gstr;
if (!ops->copy_to_clipboard) {
WSLUA_ERROR(copy_to_clipboard, "GUI not available");
+ return 0;
}
if (!copied_str) {
WSLUA_ARG_ERROR(copy_to_clipboard,TEXT,"Must be a string");
+ return 0;
}
gstr = g_string_new(copied_str);
@@ -716,10 +760,12 @@ WSLUA_FUNCTION wslua_open_capture_file(lua_State* L) { /* Open and display a cap
if (!ops->open_file) {
WSLUA_ERROR(open_capture_file, "GUI not available");
+ return 0;
}
if (!fname) {
WSLUA_ARG_ERROR(open_capture_file,FILENAME,"Must be a string");
+ return 0;
}
if (! ops->open_file(fname,filter,&error) ) {
@@ -742,6 +788,7 @@ WSLUA_FUNCTION wslua_get_filter(lua_State* L) { /* Get the main filter text */
if (!ops->get_filter) {
WSLUA_ERROR(get_filter, "GUI not available");
+ return 0;
}
filter_str = ops->get_filter();
@@ -756,10 +803,12 @@ WSLUA_FUNCTION wslua_set_filter(lua_State* L) { /* Set the main filter text */
if (!ops->set_filter) {
WSLUA_ERROR(set_filter, "GUI not available");
+ return 0;
}
if (!filter_str) {
WSLUA_ARG_ERROR(set_filter,TEXT,"Must be a string");
+ return 0;
}
ops->set_filter(filter_str);
@@ -775,10 +824,12 @@ WSLUA_FUNCTION wslua_set_color_filter_slot(lua_State* L) { /* Set packet-colorin
if (!ops->set_color_filter_slot) {
WSLUA_ERROR(set_color_filter_slot, "GUI not available");
+ return 0;
}
if (!filter_str) {
WSLUA_ARG_ERROR(set_color_filter_slot,TEXT,"Must be a string");
+ return 0;
}
ops->set_color_filter_slot(row, filter_str);
@@ -789,6 +840,7 @@ WSLUA_FUNCTION wslua_set_color_filter_slot(lua_State* L) { /* Set packet-colorin
WSLUA_FUNCTION wslua_apply_filter(lua_State* L) { /* Apply the filter in the main filter box */
if (!ops->apply_filter) {
WSLUA_ERROR(apply_filter, "GUI not available");
+ return 0;
}
ops->apply_filter();
@@ -801,6 +853,7 @@ WSLUA_FUNCTION wslua_reload(lua_State* L) { /* Reload the current capture file *
if (!ops->reload) {
WSLUA_ERROR(reload, "GUI not available");
+ return 0;
}
ops->reload();
@@ -815,10 +868,12 @@ WSLUA_FUNCTION wslua_browser_open_url(lua_State* L) { /* Open an url in a browse
if (!ops->browser_open_url) {
WSLUA_ERROR(browser_open_url, "GUI not available");
+ return 0;
}
if (!url) {
WSLUA_ARG_ERROR(browser_open_url,URL,"Must be a string");
+ return 0;
}
ops->browser_open_url(url);
@@ -832,10 +887,12 @@ WSLUA_FUNCTION wslua_browser_open_data_file(lua_State* L) { /* Open an file in a
if (!ops->browser_open_data_file) {
WSLUA_ERROR(browser_open_data_file, "GUI not available");
+ return 0;
}
if (!file) {
WSLUA_ARG_ERROR(browser_open_data_file,FILENAME,"Must be a string");
+ return 0;
}
ops->browser_open_data_file(file);
diff --git a/epan/wslua/wslua_int64.c b/epan/wslua/wslua_int64.c
index e781747a52..aa2e3d7b13 100644
--- a/epan/wslua/wslua_int64.c
+++ b/epan/wslua/wslua_int64.c
@@ -55,11 +55,6 @@ WSLUA_CLASS_DEFINE_BASE(Int64,NOP,NOP,0);
For details, see: http://wiki.wireshark.org/LuaAPI/Int64
*/
-/* these declarations are here because some funcs in Int64 need to know about UInt64 */
-UInt64 toUInt64(lua_State* L, int i);
-gboolean isUInt64(lua_State* L, int i);
-UInt64 checkUInt64(lua_State* L, int i);
-
/* A checkInt64 but that also auto-converts numbers, strings, and UINT64 to a gint64 */
static gint64 getInt64(lua_State *L, int i)
{
@@ -68,13 +63,12 @@ static gint64 getInt64(lua_State *L, int i)
switch (lua_type(L,i))
{
case LUA_TNUMBER:
- return (gint64)luaL_checknumber(L,i);
+ return wslua_checkgint64(L,i);
case LUA_TSTRING:
return g_ascii_strtoll(luaL_checkstring(L,i),&end,10);
case LUA_TUSERDATA:
if (isUInt64(L, i)) {
return (Int64) toUInt64(L, i);
- break;
}
/* fall through */
default:
@@ -176,9 +170,9 @@ WSLUA_CONSTRUCTOR Int64_new(lua_State* L) { /* Creates a Int64 Object */
if (lua_gettop(L) >= 1) {
switch(lua_type(L, WSLUA_OPTARG_Int64_new_VALUE)) {
case LUA_TNUMBER:
- value = (gint64)lua_tonumber(L, WSLUA_OPTARG_Int64_new_VALUE);
+ value = wslua_togint64(L, WSLUA_OPTARG_Int64_new_VALUE);
if (lua_gettop(L) == 2 && lua_type(L, WSLUA_OPTARG_Int64_new_HIGHVALUE) == LUA_TNUMBER) {
- gint64 h = (gint64)lua_tonumber(L, WSLUA_OPTARG_Int64_new_HIGHVALUE);
+ gint64 h = wslua_togint64(L, WSLUA_OPTARG_Int64_new_HIGHVALUE);
value &= G_GUINT64_CONSTANT(0x00000000FFFFFFFF);
h <<= 32; h &= G_GUINT64_CONSTANT(0xFFFFFFFF00000000);
value += h;
@@ -217,7 +211,7 @@ WSLUA_CONSTRUCTOR Int64_min(lua_State* L) { /* Gets the min possible value */
WSLUA_METHOD Int64_tonumber(lua_State* L) {
/* Returns a Lua number of the Int64 value - this may lose precision. */
- lua_pushnumber(L, (lua_Number)checkInt64(L,1));
+ lua_pushnumber(L, (lua_Number)(checkInt64(L,1)));
WSLUA_RETURN(1); /* The Lua number */
}
@@ -410,7 +404,7 @@ WSLUA_METHOD Int64_lshift(lua_State* L) {
/* Returns a Int64 of the bitwise logical left-shift operation, by the given number of bits. */
#define WSLUA_ARG_Int64_lshift_NUMBITS 2 /* The number of bits to left-shift by */
guint64 b = (guint64) getInt64(L,1);
- guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_Int64_lshift_NUMBITS);
+ guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_lshift_NUMBITS);
pushInt64(L,(gint64)(b << n));
WSLUA_RETURN(1); /* The Int64 object */
}
@@ -419,7 +413,7 @@ WSLUA_METHOD Int64_rshift(lua_State* L) {
/* Returns a Int64 of the bitwise logical right-shift operation, by the given number of bits. */
#define WSLUA_ARG_Int64_rshift_NUMBITS 2 /* The number of bits to right-shift by */
guint64 b = (guint64) getInt64(L,1);
- guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_Int64_rshift_NUMBITS);
+ guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_rshift_NUMBITS);
pushInt64(L,(gint64)(b >> n));
WSLUA_RETURN(1); /* The Int64 object */
}
@@ -428,7 +422,7 @@ WSLUA_METHOD Int64_arshift(lua_State* L) {
/* Returns a Int64 of the bitwise arithmetic right-shift operation, by the given number of bits. */
#define WSLUA_ARG_Int64_arshift_NUMBITS 2 /* The number of bits to right-shift by */
gint64 b = getInt64(L,1);
- gint32 n = (gint32) luaL_checknumber(L,WSLUA_ARG_Int64_arshift_NUMBITS);
+ gint32 n = wslua_checkgint32(L,WSLUA_ARG_Int64_arshift_NUMBITS);
pushInt64(L,(b >> n));
WSLUA_RETURN(1); /* The Int64 object */
}
@@ -437,7 +431,7 @@ WSLUA_METHOD Int64_rol(lua_State* L) {
/* Returns a Int64 of the bitwise left rotation operation, by the given number of bits (up to 63). */
#define WSLUA_ARG_Int64_rol_NUMBITS 2 /* The number of bits to roll left by */
guint64 b = (guint64) getInt64(L,1);
- guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_Int64_rol_NUMBITS);
+ guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_rol_NUMBITS);
pushInt64(L,(gint64)((b << n) | (b >> (64-n))));
WSLUA_RETURN(1); /* The Int64 object */
}
@@ -446,7 +440,7 @@ WSLUA_METHOD Int64_ror(lua_State* L) {
/* Returns a Int64 of the bitwise right rotation operation, by the given number of bits (up to 63). */
#define WSLUA_ARG_Int64_ror_NUMBITS 2 /* The number of bits to roll right by */
guint64 b = (guint64) getInt64(L,1);
- guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_Int64_ror_NUMBITS);
+ guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_ror_NUMBITS);
pushInt64(L,(gint64)((b << (64-n)) | (b >> n)));
WSLUA_RETURN(1); /* The Int64 object */
}
@@ -530,13 +524,12 @@ static guint64 getUInt64(lua_State *L, int i)
switch (lua_type(L,i))
{
case LUA_TNUMBER:
- return (guint64) luaL_checknumber(L,i);
+ return wslua_checkguint64(L,i);
case LUA_TSTRING:
return g_ascii_strtoull(luaL_checkstring(L,i), &end, 10);
case LUA_TUSERDATA:
if (isInt64(L, i)) {
return (UInt64) toInt64(L, i);
- break;
}
/* fall through */
default:
@@ -637,9 +630,9 @@ WSLUA_CONSTRUCTOR UInt64_new(lua_State* L) { /* Creates a UInt64 Object */
if (lua_gettop(L) >= 1) {
switch(lua_type(L, WSLUA_OPTARG_UInt64_new_VALUE)) {
case LUA_TNUMBER:
- value = (guint64)lua_tonumber(L, WSLUA_OPTARG_UInt64_new_VALUE);
+ value = wslua_toguint64(L, WSLUA_OPTARG_UInt64_new_VALUE);
if (lua_gettop(L) == 2 && lua_type(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE) == LUA_TNUMBER) {
- guint64 h = (guint64)lua_tonumber(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE);
+ guint64 h = wslua_toguint64(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE);
value &= G_GUINT64_CONSTANT(0x00000000FFFFFFFF);
h <<= 32; h &= G_GUINT64_CONSTANT(0xFFFFFFFF00000000);
value += h;
@@ -677,7 +670,7 @@ WSLUA_CONSTRUCTOR UInt64_min(lua_State* L) { /* Gets the min possible value (i.e
WSLUA_METHOD UInt64_tonumber(lua_State* L) {
/* Returns a Lua number of the UInt64 value - this may lose precision. */
- lua_pushnumber(L,(lua_Number)checkUInt64(L,1));
+ lua_pushnumber(L,(lua_Number)(checkUInt64(L,1)));
WSLUA_RETURN(1); /* The Lua number */
}
@@ -845,7 +838,7 @@ WSLUA_METHOD UInt64_lshift(lua_State* L) {
/* Returns a UInt64 of the bitwise logical left-shift operation, by the given number of bits. */
#define WSLUA_ARG_UInt64_lshift_NUMBITS 2 /* The number of bits to left-shift by */
guint64 b = getUInt64(L,1);
- guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_lshift_NUMBITS);
+ guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_lshift_NUMBITS);
pushUInt64(L,(b << n));
WSLUA_RETURN(1); /* The UInt64 object */
}
@@ -854,7 +847,7 @@ WSLUA_METHOD UInt64_rshift(lua_State* L) {
/* Returns a UInt64 of the bitwise logical right-shift operation, by the given number of bits. */
#define WSLUA_ARG_UInt64_rshift_NUMBITS 2 /* The number of bits to right-shift by */
guint64 b = getUInt64(L,1);
- guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_rshift_NUMBITS);
+ guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_rshift_NUMBITS);
pushUInt64(L,(b >> n));
WSLUA_RETURN(1); /* The UInt64 object */
}
@@ -863,7 +856,7 @@ WSLUA_METHOD UInt64_arshift(lua_State* L) {
/* Returns a UInt64 of the bitwise arithmetic right-shift operation, by the given number of bits. */
#define WSLUA_ARG_UInt64_arshift_NUMBITS 2 /* The number of bits to right-shift by */
guint64 b = getUInt64(L,1);
- guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_arshift_NUMBITS);
+ guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_arshift_NUMBITS);
pushUInt64(L,(b >> n));
WSLUA_RETURN(1); /* The UInt64 object */
}
@@ -872,7 +865,7 @@ WSLUA_METHOD UInt64_rol(lua_State* L) {
/* Returns a UInt64 of the bitwise left rotation operation, by the given number of bits (up to 63). */
#define WSLUA_ARG_UInt64_rol_NUMBITS 2 /* The number of bits to roll left by */
guint64 b = getUInt64(L,1);
- guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_rol_NUMBITS);
+ guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_rol_NUMBITS);
pushUInt64(L,((b << n) | (b >> (64-n))));
WSLUA_RETURN(1); /* The UInt64 object */
}
@@ -881,7 +874,7 @@ WSLUA_METHOD UInt64_ror(lua_State* L) {
/* Returns a UInt64 of the bitwise right rotation operation, by the given number of bits (up to 63). */
#define WSLUA_ARG_UInt64_ror_NUMBITS 2 /* The number of bits to roll right by */
guint64 b = getUInt64(L,1);
- guint32 n = (guint32) luaL_checknumber(L,WSLUA_ARG_UInt64_ror_NUMBITS);
+ guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_ror_NUMBITS);
pushUInt64(L,((b << (64-n)) | (b >> n)));
WSLUA_RETURN(1); /* The UInt64 object */
}
diff --git a/epan/wslua/wslua_internals.c b/epan/wslua/wslua_internals.c
index a89d5dee2f..c8c1614f17 100644
--- a/epan/wslua/wslua_internals.c
+++ b/epan/wslua/wslua_internals.c
@@ -100,13 +100,13 @@ WSLUA_API void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup) {
}
/* identical to lua_getfield but without triggering metamethods */
-WSLUA_API void lua_rawgetfield(lua_State *L, int idx, const char *k) {
+static void lua_rawgetfield(lua_State *L, int idx, const char *k) {
lua_pushstring(L, k);
lua_rawget(L, idx);
}
/* identical to lua_setfield but without triggering metamethods */
-WSLUA_API void lua_rawsetfield (lua_State *L, int idx, const char *k) {
+static void lua_rawsetfield (lua_State *L, int idx, const char *k) {
lua_pushstring(L, k);
lua_insert(L, -2);
lua_rawset(L, idx);
diff --git a/epan/wslua/wslua_listener.c b/epan/wslua/wslua_listener.c
index 14438631e2..238fc8ecab 100644
--- a/epan/wslua/wslua_listener.c
+++ b/epan/wslua/wslua_listener.c
@@ -225,8 +225,9 @@ WSLUA_CONSTRUCTOR Listener_new(lua_State* L) {
g_free(tap->name);
g_free(tap);
/* WSLUA_ERROR(new_tap,"tap registration error"); */
- luaL_error(L,"Error while registering tap:\n%s",error->str);
- g_string_free(error,TRUE); /* XXX LEAK? */
+ lua_pushfstring(L,"Error while registering tap:\n%s",error->str);
+ g_string_free(error,TRUE);
+ luaL_error(L,lua_tostring(L,-1));
}
if (all_fields) {
diff --git a/epan/wslua/wslua_pinfo.c b/epan/wslua/wslua_pinfo.c
index 5fb217553e..2236092757 100644
--- a/epan/wslua/wslua_pinfo.c
+++ b/epan/wslua/wslua_pinfo.c
@@ -389,8 +389,8 @@ static int Address__gc(lua_State* L) {
Address addr = toAddress(L,1);
if (addr) {
- g_free((void*)addr->data);
- g_free((void*)addr);
+ g_free((void*)(addr->data));
+ g_free((void*)(addr));
}
return 0;
@@ -578,7 +578,10 @@ WSLUA_METHOD Column_set(lua_State *L) {
if (!(c->cinfo))
return 0;
- if (!s) WSLUA_ARG_ERROR(Column_set,TEXT,"must be a string");
+ if (!s) {
+ WSLUA_ARG_ERROR(Column_set,TEXT,"must be a string");
+ return 0;
+ }
col_add_str(c->cinfo, c->col, s);
@@ -594,7 +597,10 @@ WSLUA_METHOD Column_append(lua_State *L) {
if (!(c->cinfo))
return 0;
- if (!s) WSLUA_ARG_ERROR(Column_append,TEXT,"must be a string");
+ if (!s) {
+ WSLUA_ARG_ERROR(Column_append,TEXT,"must be a string");
+ return 0;
+ }
col_append_str(c->cinfo, c->col, s);
@@ -610,7 +616,10 @@ WSLUA_METHOD Column_prepend(lua_State *L) {
if (!(c->cinfo))
return 0;
- if (!s) WSLUA_ARG_ERROR(Column_prepend,TEXT,"must be a string");
+ if (!s) {
+ WSLUA_ARG_ERROR(Column_prepend,TEXT,"must be a string");
+ return 0;
+ }
col_prepend_fstr(c->cinfo, c->col, "%s",s);
@@ -705,6 +714,7 @@ WSLUA_METAMETHOD Columns__newindex(lua_State *L) {
}
WSLUA_ARG_ERROR(Columns__newindex,COLUMN,"the column name must be a valid column");
+ return 0;
}
WSLUA_METAMETHOD Columns__index(lua_State *L) {
@@ -811,7 +821,7 @@ static int PrivateTable__index(lua_State* L) {
const gchar* name = luaL_checkstring(L,2);
const gchar* string;
- string = (const gchar *)g_hash_table_lookup (priv->table, (gpointer) name);
+ string = (const gchar *)(g_hash_table_lookup (priv->table, (gpointer) name));
if (string) {
lua_pushstring(L, string);
@@ -842,7 +852,7 @@ static int PrivateTable__newindex(lua_State* L) {
if (string) {
g_hash_table_replace (priv->table, (gpointer) ep_strdup(name), (gpointer) ep_strdup(string));
} else {
- g_hash_table_remove (priv->table, (gpointer) name);
+ g_hash_table_remove (priv->table, (gconstpointer) name);
}
return 1;
diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c
index 573cd9740b..6b803b9f68 100644
--- a/epan/wslua/wslua_proto.c
+++ b/epan/wslua/wslua_proto.c
@@ -94,7 +94,7 @@ static enum_val_t* get_enum(lua_State *L, int idx)
g_array_append_val(es,last);
- ret = (enum_val_t*)es->data;
+ ret = (enum_val_t*)(void*)es->data;
g_array_free(es,FALSE);
@@ -120,7 +120,7 @@ static int new_pref(lua_State* L, pref_type_t type) {
break;
}
case PREF_UINT: {
- guint32 def = (guint32)luaL_optnumber(L,2,0);
+ guint32 def = wslua_optgint32(L,2,0);
pref->value.u = def;
break;
}
@@ -130,7 +130,7 @@ static int new_pref(lua_State* L, pref_type_t type) {
break;
}
case PREF_ENUM: {
- guint32 def = (guint32)luaL_optnumber(L,2,0);
+ guint32 def = wslua_optgint32(L,2,0);
enum_val_t *enum_val = get_enum(L,4);
gboolean radio = lua_toboolean(L,5);
pref->value.e = def;
@@ -140,7 +140,7 @@ static int new_pref(lua_State* L, pref_type_t type) {
}
case PREF_RANGE: {
range_t *range = get_range(L,2,4);
- guint32 max = (guint32)luaL_optnumber(L,4,0);
+ guint32 max = wslua_optgint32(L,4,0);
pref->value.r = range;
pref->info.max_value = max;
break;
@@ -212,23 +212,22 @@ WSLUA_CONSTRUCTOR Pref_statictext(lua_State* L) {
static range_t* get_range(lua_State *L, int idx_r, int idx_m)
{
static range_t *ret = NULL;
- gchar *pattern = g_strdup(luaL_checkstring(L, idx_r));
-
- switch (range_convert_str(&ret, pattern, (guint32)lua_tonumber(L, idx_m))) {
- case CVT_NO_ERROR:
- break;
- case CVT_SYNTAX_ERROR:
- WSLUA_ARG_ERROR(Pref_range,DEFAULT,"syntax error in default range");
- break;
- case CVT_NUMBER_TOO_BIG:
- WSLUA_ARG_ERROR(Pref_range,DEFAULT,"value too large in default range");
- break;
- default:
- WSLUA_ARG_ERROR(Pref_range,DEFAULT,"unknown error in default range");
- break;
+ const gchar *pattern = luaL_checkstring(L, idx_r);
+
+ switch (range_convert_str(&ret, pattern, wslua_togint32(L, idx_m))) {
+ case CVT_NO_ERROR:
+ break;
+ case CVT_SYNTAX_ERROR:
+ WSLUA_ARG_ERROR(Pref_range,DEFAULT,"syntax error in default range");
+ return 0;
+ case CVT_NUMBER_TOO_BIG:
+ WSLUA_ARG_ERROR(Pref_range,DEFAULT,"value too large in default range");
+ return 0;
+ default:
+ WSLUA_ARG_ERROR(Pref_range,DEFAULT,"unknown error in default range");
+ return 0;
}
- g_free (pattern);
return ret;
}
/* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
@@ -281,17 +280,25 @@ WSLUA_METAMETHOD Prefs__newindex(lua_State* L) {
if (! prefs_p ) return 0;
- if (! name )
+ if (! name ) {
WSLUA_ARG_ERROR(Prefs__newindex,NAME,"must be a string");
+ return 0;
+ }
- if (! pref )
+ if (! pref ) {
WSLUA_ARG_ERROR(Prefs__newindex,PREF,"must be a valid Pref");
+ return 0;
+ }
- if (pref->name)
+ if (pref->name) {
WSLUA_ARG_ERROR(Prefs__newindex,NAME,"cannot change existing preference");
+ return 0;
+ }
- if (pref->proto)
+ if (pref->proto) {
WSLUA_ARG_ERROR(Prefs__newindex,PREF,"cannot be added to more than one protocol");
+ return 0;
+ }
p = prefs_p;
@@ -345,7 +352,7 @@ WSLUA_METAMETHOD Prefs__newindex(lua_State* L) {
pref->name,
pref->label,
pref->desc,
- &(pref->value.s));
+ (const char **)(&(pref->value.s)));
break;
case PREF_ENUM:
prefs_register_enum_preference(prefs_p->proto->prefs_module,
@@ -372,6 +379,7 @@ WSLUA_METAMETHOD Prefs__newindex(lua_State* L) {
break;
default:
WSLUA_ERROR(Prefs__newindex,"Unknow Pref type");
+ break;
}
pref->proto = p->proto;
@@ -404,13 +412,14 @@ WSLUA_METAMETHOD Prefs__index(lua_State* L) {
case PREF_STRING: lua_pushstring(L,prefs_p->value.s); break;
case PREF_ENUM: lua_pushnumber(L,(lua_Number)prefs_p->value.e); break;
case PREF_RANGE: lua_pushstring(L,range_convert_range(prefs_p->value.r)); break;
- default: WSLUA_ERROR(Prefs__index,"Unknow Pref type");
+ default: WSLUA_ERROR(Prefs__index,"Unknow Pref type"); return 0;
}
WSLUA_RETURN(1); /* The current value of the preference */
}
} while (( prefs_p = prefs_p->next ));
WSLUA_ARG_ERROR(Prefs__index,NAME,"no preference named like this");
+ return 0;
}
/* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
@@ -556,7 +565,7 @@ static value_string* value_string_from_table(lua_State* L, int idx) {
return NULL;
}
- v.value = (guint32)lua_tonumber(L,-2);
+ v.value = wslua_toguint32(L,-2);
v.strptr = g_strdup(lua_tostring(L,-1));
g_array_append_val(vs,v);
@@ -564,7 +573,7 @@ static value_string* value_string_from_table(lua_State* L, int idx) {
lua_pop(L, 1);
}
- ret = (value_string*)vs->data;
+ ret = (value_string*)(void*)vs->data;
g_array_free(vs,FALSE);
@@ -600,7 +609,7 @@ static val64_string* val64_string_from_table(lua_State* L, int idx) {
return NULL;
}
- v.value = (guint64)lua_tonumber(L, -2);
+ v.value = wslua_toguint64(L, -2);
v.strptr = g_strdup(lua_tostring(L,-1));
g_array_append_val(vs,v);
@@ -608,7 +617,7 @@ static val64_string* val64_string_from_table(lua_State* L, int idx) {
lua_pop(L, 1);
}
- ret = (val64_string*)vs->data;
+ ret = (val64_string*)(void*)vs->data;
g_array_free(vs,FALSE);
@@ -645,10 +654,10 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) {
}
/* arrays in LUA start with index number 1 */
- if ((guint32)lua_tonumber(L,-2) == 1)
+ if (lua_tointeger(L,-2) == 1)
tf.true_string = g_strdup(lua_tostring(L,-1));
- if ((guint32)lua_tonumber(L,-2) == 2)
+ if (lua_tointeger(L,-2) == 2)
tf.false_string = g_strdup(lua_tostring(L,-1));
lua_pop(L, 1);
@@ -656,7 +665,7 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) {
g_array_append_val(tfs,tf);
- ret = (true_false_string*)tfs->data;
+ ret = (true_false_string*)(void*)tfs->data;
g_array_free(tfs,FALSE);
@@ -710,7 +719,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
val64_string *vs64 = NULL;
true_false_string *tfs = NULL;
unsigned base;
- guint32 mask = (guint32)luaL_optnumber(L, WSLUA_OPTARG_ProtoField_new_MASK, 0x0);
+ guint32 mask = wslua_optguint32(L, WSLUA_OPTARG_ProtoField_new_MASK, 0x0);
const gchar *blob = luaL_optstring(L,WSLUA_OPTARG_ProtoField_new_DESCR,NULL);
if (lua_isnumber(L,WSLUA_ARG_ProtoField_new_TYPE)) {
@@ -731,9 +740,11 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
case FT_FRAMENUM:
if (base != BASE_NONE) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"FRAMENUM must use base.NONE");
+ return 0;
}
if (mask) {
WSLUA_OPTARG_ERROR(ProtoField_new,MASK,"FRAMENUM can not have a bitmask");
+ return 0;
}
break;
case FT_UINT8:
@@ -751,11 +762,13 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
} else if (base < BASE_DEC || base > BASE_HEX_DEC) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either base.DEC, base.HEX, base.OCT,"
" base.DEC_HEX, base.DEC_HEX or base.HEX_DEC");
+ return 0;
}
if ((base == BASE_HEX || base == BASE_OCT) &&
(type == FT_INT8 || type == FT_INT16 || type == FT_INT24 || type == FT_INT32 || type == FT_INT64))
{
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"This type does not display as hexadecimal");
+ return 0;
}
if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING && !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) {
if (type == FT_UINT64 || type == FT_INT64) {
@@ -768,9 +781,11 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
case FT_BOOLEAN:
if (mask == 0x0 && base != BASE_NONE) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be base.NONE if bitmask is zero.");
+ return 0;
}
if (mask != 0x0 && (base < 1 || base > 64)) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be between 1 and 64 if bitmask is non-zero.");
+ return 0;
}
if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING && !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) {
tfs = true_false_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING);
@@ -781,9 +796,11 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
base = ABSOLUTE_TIME_LOCAL; /* Default base for FT_ABSOLUTE_TIME */
} else if (base < ABSOLUTE_TIME_LOCAL || base > ABSOLUTE_TIME_DOY_UTC) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either LOCAL, UTC, or DOY_UTC");
+ return 0;
}
if (mask) {
WSLUA_OPTARG_ERROR(ProtoField_new,MASK,"ABSOLUTE_TIME can not have a bitmask");
+ return 0;
}
break;
case FT_IPv4:
@@ -803,14 +820,17 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
case FT_REL_OID:
if (base != BASE_NONE) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be base.NONE");
+ return 0;
}
if (mask) {
WSLUA_OPTARG_ERROR(ProtoField_new,MASK,"This type can not have a bitmask");
+ return 0;
}
break;
case FT_NONE:
default:
WSLUA_ARG_ERROR(ProtoField_new,TYPE,"Invalid field type");
+ break;
}
f = g_new(wslua_field_t,1);
@@ -851,7 +871,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
unsigned base = luaL_optint(L, 3, BASE_DEC);
value_string* vs32 = NULL;
val64_string* vs64 = NULL;
- guint32 mask = (guint32)luaL_optnumber(L,5,0);
+ guint32 mask = wslua_optguint32(L,5,0);
const gchar* blob = luaL_optstring(L,6,NULL);
if (lua_gettop(L) > 3) {
@@ -1022,7 +1042,7 @@ static int ProtoField_boolean(lua_State* L, enum ftenum type) {
const gchar* name = luaL_optstring(L,2,abbr);
unsigned base = luaL_optint(L, 3, BASE_NONE);
true_false_string* tfs = NULL;
- guint32 mask = (guint32)luaL_optnumber(L,5,0);
+ guint32 mask = wslua_optguint32(L,5,0);
const gchar* blob = luaL_optstring(L,6,NULL);
if (mask == 0x0 && base != BASE_NONE) {
@@ -1351,6 +1371,7 @@ WSLUA_CONSTRUCTOR Proto_new(lua_State* L) {
g_free(loname_a);
if ( proto_id > 0 ) {
WSLUA_ARG_ERROR(Proto_new,NAME,"there cannot be two protocols with the same name");
+ return 0;
} else {
Proto proto = (wslua_proto_t *)g_malloc(sizeof(wslua_proto_t));
gchar* loname = g_ascii_strdown(name, -1);
@@ -1386,9 +1407,9 @@ WSLUA_CONSTRUCTOR Proto_new(lua_State* L) {
WSLUA_RETURN(1); /* The newly created protocol */
}
- } else
- WSLUA_ARG_ERROR(Proto_new,NAME,"must be a string");
+ }
+ WSLUA_ARG_ERROR(Proto_new,NAME,"must be a string");
return 0;
}
@@ -1642,9 +1663,18 @@ int Proto_commit(lua_State* L) {
for (lua_pushnil(L); lua_next(L, 4); lua_pop(L, 1)) {
ProtoField f = checkProtoField(L,6);
- hf_register_info hfri = { &(f->hfid), {f->name,f->abbr,f->type,f->base,VALS(f->vs),f->mask,f->blob,HFILL}};
+ hf_register_info hfri = { NULL, { NULL, NULL, 0, 0, NULL, 0, NULL, HFILL } };
gint* ettp = &(f->ett);
+ hfri.p_id = &(f->hfid);
+ hfri.hfinfo.name = f->name;
+ hfri.hfinfo.abbrev = f->abbr;
+ hfri.hfinfo.type = f->type;
+ hfri.hfinfo.display = f->base;
+ hfri.hfinfo.strings = VALS(f->vs);
+ hfri.hfinfo.bitmask = f->mask;
+ hfri.hfinfo.blurb = f->blob;
+
if (f->hfid != -2) {
return luaL_error(L,"fields can be registered only once");
}
@@ -1654,8 +1684,8 @@ int Proto_commit(lua_State* L) {
g_array_append_val(etta,ettp);
}
- proto_register_field_array(proto->hfid,(hf_register_info*)hfa->data,hfa->len);
- proto_register_subtree_array((gint**)etta->data,etta->len);
+ proto_register_field_array(proto->hfid,(hf_register_info*)(void*)hfa->data,hfa->len);
+ proto_register_subtree_array((gint**)(void*)etta->data,etta->len);
g_array_free(hfa,FALSE);
g_array_free(etta,FALSE);
@@ -1677,14 +1707,18 @@ WSLUA_CONSTRUCTOR Dissector_get (lua_State *L) {
const gchar* name = luaL_checkstring(L,WSLUA_ARG_Dissector_get_NAME);
Dissector d;
- if (!name)
+ if (!name) {
WSLUA_ARG_ERROR(Dissector_get,NAME,"must be a string");
+ return 0;
+ }
if ((d = find_dissector(name))) {
pushDissector(L, d);
WSLUA_RETURN(1); /* The Dissector reference */
- } else
- WSLUA_ARG_ERROR(Dissector_get,NAME,"No such dissector");
+ }
+
+ WSLUA_ARG_ERROR(Dissector_get,NAME,"No such dissector");
+ return 0;
}
/* Allow dissector key names to be sorted alphabetically */
@@ -1738,7 +1772,7 @@ WSLUA_METHOD Dissector_call(lua_State* L) {
error = "Malformed frame";
} ENDTRY;
- if (error) { WSLUA_ERROR(Dissector_call,error); }
+ if (error) { WSLUA_ERROR(Dissector_call,error); }
return 0;
}
@@ -1814,6 +1848,7 @@ WSLUA_CONSTRUCTOR DissectorTable_new (lua_State *L) {
WSLUA_RETURN(1); /* The newly created DissectorTable */
default:
WSLUA_OPTARG_ERROR(DissectorTable_new,TYPE,"must be ftypes.UINT{8,16,24,32} or ftypes.STRING");
+ break;
}
return 0;
}
@@ -1838,9 +1873,10 @@ WSLUA_CONSTRUCTOR DissectorTable_get (lua_State *L) {
pushDissectorTable(L, dt);
WSLUA_RETURN(1); /* The DissectorTable */
- } else
- WSLUA_ARG_ERROR(DissectorTable_get,TABLENAME,"no such dissector_table");
+ }
+ WSLUA_ARG_ERROR(DissectorTable_get,TABLENAME,"no such dissector_table");
+ return 0;
}
WSLUA_METHOD DissectorTable_add (lua_State *L) {
@@ -1861,13 +1897,17 @@ WSLUA_METHOD DissectorTable_add (lua_State *L) {
p = checkProto(L,WSLUA_ARG_DissectorTable_add_DISSECTOR);
handle = p->handle;
- if (! handle)
+ if (! handle) {
WSLUA_ARG_ERROR(DissectorTable_add,DISSECTOR,"a Protocol that does not have a dissector cannot be added to a table");
+ return 0;
+ }
} else if ( isDissector(L,WSLUA_ARG_DissectorTable_add_DISSECTOR) ) {
handle = toDissector(L,WSLUA_ARG_DissectorTable_add_DISSECTOR);
- } else
+ } else {
WSLUA_ARG_ERROR(DissectorTable_add,DISSECTOR,"must be either Proto or Dissector");
+ return 0;
+ }
type = get_dissector_table_selector_type(dt->name);
@@ -1881,13 +1921,16 @@ WSLUA_METHOD DissectorTable_add (lua_State *L) {
dissector_add_uint(dt->name, port, handle);
} else {
/* Not a number, try as range */
- gchar* pattern = g_strdup(luaL_checkstring(L,WSLUA_ARG_DissectorTable_add_PATTERN));
+ gchar* pattern = g_strdup(luaL_checkstring(L,WSLUA_ARG_DissectorTable_add_PATTERN));
range_t *range;
- if (range_convert_str(&range, pattern, G_MAXUINT32) == CVT_NO_ERROR)
- dissector_add_uint_range(dt->name, range, handle);
- else
- WSLUA_ARG_ERROR(DissectorTable_add,PATTERN,"invalid integer or range");
- g_free (pattern);
+ if (range_convert_str(&range, pattern, G_MAXUINT32) == CVT_NO_ERROR) {
+ dissector_add_uint_range(dt->name, range, handle);
+ } else {
+ g_free (pattern);
+ WSLUA_ARG_ERROR(DissectorTable_add,PATTERN,"invalid integer or range");
+ return 0;
+ }
+ g_free (pattern);
}
} else {
luaL_error(L,"Strange type %d for a DissectorTable",type);
@@ -1914,21 +1957,24 @@ WSLUA_METHOD DissectorTable_set (lua_State *L) {
p = checkProto(L,WSLUA_ARG_DissectorTable_set_DISSECTOR);
handle = p->handle;
- if (! handle)
+ if (! handle) {
WSLUA_ARG_ERROR(DissectorTable_set,DISSECTOR,"a Protocol that does not have a dissector cannot be set to a table");
+ return 0;
+ }
} else if ( isDissector(L,WSLUA_ARG_DissectorTable_set_DISSECTOR) ) {
handle = toDissector(L,WSLUA_ARG_DissectorTable_set_DISSECTOR);
- } else
+ } else {
WSLUA_ARG_ERROR(DissectorTable_set,DISSECTOR,"must be either Proto or Dissector");
+ return 0;
+ }
type = get_dissector_table_selector_type(dt->name);
if (type == FT_STRING) {
- gchar* pattern = g_strdup(luaL_checkstring(L,WSLUA_ARG_DissectorTable_set_PATTERN));
+ const gchar* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_set_PATTERN);
dissector_delete_all(dt->name, handle);
dissector_add_string(dt->name, pattern,handle);
- g_free (pattern);
} else if ( type == FT_UINT32 || type == FT_UINT16 || type == FT_UINT8 || type == FT_UINT24 ) {
if (lua_isnumber(L, WSLUA_ARG_DissectorTable_set_PATTERN)) {
int port = luaL_checkint(L, WSLUA_ARG_DissectorTable_set_PATTERN);
@@ -1936,15 +1982,15 @@ WSLUA_METHOD DissectorTable_set (lua_State *L) {
dissector_add_uint(dt->name, port, handle);
} else {
/* Not a number, try as range */
- gchar* pattern = g_strdup(luaL_checkstring(L,WSLUA_ARG_DissectorTable_set_PATTERN));
+ const gchar* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_set_PATTERN);
range_t *range;
if (range_convert_str(&range, pattern, G_MAXUINT32) == CVT_NO_ERROR) {
dissector_delete_all(dt->name, handle);
dissector_add_uint_range(dt->name, range, handle);
} else {
WSLUA_ARG_ERROR(DissectorTable_set,PATTERN,"invalid integer or range");
+ return 0;
}
- g_free (pattern);
}
} else {
luaL_error(L,"Strange type %d for a DissectorTable",type);
@@ -1972,8 +2018,10 @@ WSLUA_METHOD DissectorTable_remove (lua_State *L) {
} else if ( isDissector(L,WSLUA_ARG_DissectorTable_remove_DISSECTOR) ) {
handle = toDissector(L,WSLUA_ARG_DissectorTable_remove_DISSECTOR);
- } else
+ } else {
WSLUA_ARG_ERROR(DissectorTable_remove,DISSECTOR,"must be either Proto or Dissector");
+ return 0;
+ }
type = get_dissector_table_selector_type(dt->name);
@@ -1991,8 +2039,11 @@ WSLUA_METHOD DissectorTable_remove (lua_State *L) {
range_t *range;
if (range_convert_str(&range, pattern, G_MAXUINT32) == CVT_NO_ERROR)
dissector_delete_uint_range(dt->name, range, handle);
- else
+ else {
+ g_free (pattern);
WSLUA_ARG_ERROR(DissectorTable_remove,PATTERN,"invalid integer or range");
+ return 0;
+ }
g_free (pattern);
}
}
@@ -2017,8 +2068,10 @@ WSLUA_METHOD DissectorTable_remove_all (lua_State *L) {
} else if ( isDissector(L,WSLUA_ARG_DissectorTable_remove_all_DISSECTOR) ) {
handle = toDissector(L,WSLUA_ARG_DissectorTable_remove_all_DISSECTOR);
- } else
+ } else {
WSLUA_ARG_ERROR(DissectorTable_remove_all,DISSECTOR,"must be either Proto or Dissector");
+ return 0;
+ }
dissector_delete_all (dt->name, handle);
@@ -2097,7 +2150,10 @@ WSLUA_METHOD DissectorTable_get_dissector (lua_State *L) {
if (type == FT_STRING) {
const gchar* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_try_PATTERN);
- if (!pattern) WSLUA_ARG_ERROR(DissectorTable_try,PATTERN,"must be a string");
+ if (!pattern) {
+ WSLUA_ARG_ERROR(DissectorTable_try,PATTERN,"must be a string");
+ return 0;
+ }
handle = dissector_get_string_handle(dt->table,pattern);
} else if ( type == FT_UINT32 || type == FT_UINT16 || type == FT_UINT8 || type == FT_UINT24 ) {
diff --git a/epan/wslua/wslua_struct.c b/epan/wslua/wslua_struct.c
index 3ef76458e6..1789356610 100644
--- a/epan/wslua/wslua_struct.c
+++ b/epan/wslua/wslua_struct.c
@@ -450,7 +450,7 @@ WSLUA_CONSTRUCTOR Struct_unpack (lua_State *L) {
if (size == 0) {
if (!lua_isnumber(L, -1))
luaL_error(L, "format `c0' needs a previous size");
- size = (guint32)lua_tonumber(L, -1);
+ size = wslua_toguint32(L, -1);
lua_pop(L, 1);
luaL_argcheck(L, pos+size <= ld, 2, "data string too short");
}
@@ -515,8 +515,10 @@ WSLUA_CONSTRUCTOR Struct_tohex (lua_State *L) {
s = luaL_checklstring(L,WSLUA_ARG_Struct_tohex_BYTESTRING,&len);
- if (!s)
+ if (!s) {
WSLUA_ARG_ERROR(Struct_tohex,BYTESTRING,"must be a Lua string");
+ return 0;
+ }
lowercase = wslua_optbool(L,WSLUA_OPTARG_Struct_tohex_LOWERCASE,FALSE);
sep = luaL_optstring(L,WSLUA_OPTARG_Struct_tohex_SEPARATOR,NULL);
@@ -535,8 +537,10 @@ WSLUA_CONSTRUCTOR Struct_fromhex (lua_State *L) {
s = luaL_checklstring(L,WSLUA_ARG_Struct_fromhex_HEXBYTES,&len);
- if (!s)
+ if (!s) {
WSLUA_ARG_ERROR(Struct_tohex,BYTESTRING,"must be a Lua string");
+ return 0;
+ }
sep = luaL_optstring(L,WSLUA_OPTARG_Struct_fromhex_SEPARATOR,NULL);
diff --git a/epan/wslua/wslua_tree.c b/epan/wslua/wslua_tree.c
index e84ada62b5..8ed3c1e050 100644
--- a/epan/wslua/wslua_tree.c
+++ b/epan/wslua/wslua_tree.c
@@ -93,7 +93,7 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) {
tvbr->len = 0;
}
- encoding = (guint)luaL_checknumber(L,1);
+ encoding = wslua_checkguint(L,1);
lua_remove(L,1);
if (type == FT_STRINGZ) {
switch (encoding & ENC_CHARENCODING_MASK) {
@@ -176,20 +176,20 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) {
lua_insert(L,1);
break;
case FT_BOOLEAN:
- item = proto_tree_add_boolean(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(guint32)luaL_checknumber(L,1));
+ item = proto_tree_add_boolean(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,wslua_checkguint32(L,1));
break;
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
case FT_FRAMENUM:
- item = proto_tree_add_uint(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(guint32)luaL_checknumber(L,1));
+ item = proto_tree_add_uint(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,wslua_checkguint32(L,1));
break;
case FT_INT8:
case FT_INT16:
case FT_INT24:
case FT_INT32:
- item = proto_tree_add_int(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(gint32)luaL_checknumber(L,1));
+ item = proto_tree_add_int(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,wslua_checkguint32(L,1));
break;
case FT_FLOAT:
item = proto_tree_add_float(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(float)luaL_checknumber(L,1));
diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c
index 4549d7d5b5..19fcdd8640 100644
--- a/epan/wslua/wslua_tvb.c
+++ b/epan/wslua/wslua_tvb.c
@@ -51,8 +51,10 @@ WSLUA_CONSTRUCTOR ByteArray_new(lua_State* L) { /* Creates a ByteArray Object */
if (lua_gettop(L) >= 1) {
s = luaL_checklstring(L,WSLUA_OPTARG_ByteArray_new_HEXBYTES,&len);
- if (!s)
+ if (!s) {
WSLUA_OPTARG_ERROR(ByteArray_new,HEXBYTES,"must be a string");
+ return 0;
+ }
if (lua_gettop(L) >= 2) {
if (lua_type(L,2) == LUA_TBOOLEAN && lua_toboolean(L,2)) {
@@ -134,8 +136,10 @@ WSLUA_METHOD ByteArray_set_size(lua_State* L) {
int siz = luaL_checkint(L,WSLUA_ARG_ByteArray_set_size_SIZE);
guint8* padding;
- if (siz < 0)
+ if (siz < 0) {
WSLUA_ERROR(ByteArray_set_size,"ByteArray size must be non-negative");
+ return 0;
+ }
if (ba->len >= (guint)siz) { /* truncate */
g_byte_array_set_size(ba,siz);
@@ -256,8 +260,10 @@ WSLUA_METHOD ByteArray_raw(lua_State* L) {
int len;
if (!ba) return 0;
- if (offset > ba->len)
+ if (offset > ba->len) {
WSLUA_OPTARG_ERROR(ByteArray_raw,OFFSET,"offset beyond end of byte array");
+ return 0;
+ }
len = luaL_optint(L,WSLUA_OPTARG_ByteArray_raw_LENGTH, ba->len - offset);
if ((len < 0) || ((guint)len > (ba->len - offset)))
@@ -602,8 +608,10 @@ WSLUA_METHOD Tvb_raw(lua_State* L) {
return 0;
}
- if ((guint)offset > tvb_length(tvb->ws_tvb))
+ if ((guint)offset > tvb_length(tvb->ws_tvb)) {
WSLUA_OPTARG_ERROR(Tvb_raw,OFFSET,"offset beyond end of Tvb");
+ return 0;
+ }
if (len == -1) {
len = tvb_length_remaining(tvb->ws_tvb,offset);
@@ -696,7 +704,7 @@ WSLUA_METHOD TvbRange_le_uint(lua_State* L) {
switch (tvbr->len) {
case 1:
/* XXX unsigned anyway */
- lua_pushnumber(L,(lua_Number)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
+ lua_pushnumber(L,(lua_Number)(guint)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset));
return 1;
case 2:
lua_pushnumber(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset));
@@ -954,8 +962,10 @@ WSLUA_METHOD TvbRange_ipv4(lua_State* L) {
return 0;
}
- if (tvbr->len != 4)
+ if (tvbr->len != 4) {
WSLUA_ERROR(TvbRange_ipv4,"The range must be 4 octets long");
+ return 0;
+ }
addr = (address *)g_malloc(sizeof(address));
@@ -980,8 +990,10 @@ WSLUA_METHOD TvbRange_le_ipv4(lua_State* L) {
return 0;
}
- if (tvbr->len != 4)
+ if (tvbr->len != 4) {
WSLUA_ERROR(TvbRange_ipv4,"The range must be 4 octets long");
+ return 0;
+ }
addr = (address *)g_malloc(sizeof(address));
@@ -1007,8 +1019,10 @@ WSLUA_METHOD TvbRange_ether(lua_State* L) {
return 0;
}
- if (tvbr->len != 6)
+ if (tvbr->len != 6) {
WSLUA_ERROR(TvbRange_ether,"The range must be 6 bytes long");
+ return 0;
+ }
addr = g_new(address,1);
@@ -1291,7 +1305,7 @@ WSLUA_METHOD TvbRange_bitfield(lua_State* L) {
}
if (len <= 8) {
- lua_pushnumber(L,(lua_Number)tvb_get_bits8(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len));
+ lua_pushnumber(L,(lua_Number)(guint)tvb_get_bits8(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len));
return 1;
} else if (len <= 16) {
lua_pushnumber(L,tvb_get_bits16(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE));
@@ -1417,8 +1431,10 @@ WSLUA_METHOD TvbRange_raw(lua_State* L) {
return 0;
}
- if ((guint)offset > tvb_length(tvbr->tvb->ws_tvb))
+ if ((guint)offset > tvb_length(tvbr->tvb->ws_tvb)) {
WSLUA_OPTARG_ERROR(Tvb_raw,OFFSET,"offset beyond end of Tvb");
+ return 0;
+ }
if (len == -1) {
len = tvb_length_remaining(tvbr->tvb->ws_tvb,offset);
diff --git a/epan/wslua/wslua_util.c b/epan/wslua/wslua_util.c
index b8205daa32..f36e488113 100644
--- a/epan/wslua/wslua_util.c
+++ b/epan/wslua/wslua_util.c
@@ -45,7 +45,7 @@ WSLUA_FUNCTION wslua_format_date(lua_State* LS) { /* Formats an absolute timesta
nstime_t then;
gchar* str;
- then.secs = (guint32)floor(timestamp);
+ then.secs = (guint32)(floor(timestamp));
then.nsecs = (guint32) ( (timestamp-(double)(then.secs))*1000000000);
str = abs_time_to_ep_str(&then, ABSOLUTE_TIME_LOCAL, TRUE);
lua_pushstring(LS,str);
@@ -59,7 +59,7 @@ WSLUA_FUNCTION wslua_format_time(lua_State* LS) { /* Formats a relative timestam
nstime_t then;
gchar* str;
- then.secs = (guint32)floor(timestamp);
+ then.secs = (guint32)(floor(timestamp));
then.nsecs = (guint32) ( (timestamp-(double)(then.secs))*1000000000);
str = rel_time_to_ep_str(&then);
lua_pushstring(LS,str);
@@ -186,7 +186,10 @@ WSLUA_FUNCTION wslua_loadfile(lua_State* L) {
filename = wslua_get_actual_filename(given_fname);
- if (!filename) WSLUA_ARG_ERROR(loadfile,FILENAME,"file does not exist");
+ if (!filename) {
+ WSLUA_ARG_ERROR(loadfile,FILENAME,"file does not exist");
+ return 0;
+ }
if (luaL_loadfile(L, filename) == 0) {
g_free(filename);
@@ -207,11 +210,17 @@ WSLUA_FUNCTION wslua_dofile(lua_State* L) {
char* filename;
int n;
- if (!given_fname) WSLUA_ARG_ERROR(dofile,FILENAME,"must be a string");
+ if (!given_fname) {
+ WSLUA_ARG_ERROR(dofile,FILENAME,"must be a string");
+ return 0;
+ }
filename = wslua_get_actual_filename(given_fname);
- if (!filename) WSLUA_ARG_ERROR(dofile,FILENAME,"file does not exist");
+ if (!filename) {
+ WSLUA_ARG_ERROR(dofile,FILENAME,"file does not exist");
+ return 0;
+ }
n = lua_gettop(L);
if (luaL_loadfile(L, filename) != 0) lua_error(L);
@@ -262,14 +271,21 @@ WSLUA_CONSTRUCTOR Dir_open(lua_State* L) {
Dir dir;
char* dirname_clean;
- if (!dirname) WSLUA_ARG_ERROR(Dir_open,PATHNAME,"must be a string");
+ if (!dirname) {
+ WSLUA_ARG_ERROR(Dir_open,PATHNAME,"must be a string");
+ return 0;
+ }
dirname_clean = wslua_get_actual_filename(dirname);
- if (!dirname_clean) WSLUA_ARG_ERROR(Dir_open,PATHNAME,"directory does not exist");
+ if (!dirname_clean) {
+ WSLUA_ARG_ERROR(Dir_open,PATHNAME,"directory does not exist");
+ return 0;
+ }
if (!test_for_directory(dirname_clean)) {
g_free(dirname_clean);
WSLUA_ARG_ERROR(Dir_open,PATHNAME, "must be a directory");
+ return 0;
}
dir = (Dir)g_malloc(sizeof(struct _wslua_dir));
@@ -284,6 +300,7 @@ WSLUA_CONSTRUCTOR Dir_open(lua_State* L) {
g_free(dir);
WSLUA_ARG_ERROR(Dir_open,PATHNAME,"could not open directory");
+ return 0;
}
pushDir(L,dir);