Skip to content

Commit

Permalink
Lua: FieldInfo '==' check isn't really equality
Browse files Browse the repository at this point in the history
The FieldInfo metamethod for equality (letting you use the '==' operator)
doesn't check for equality, but rather if the left-hand side is within
the right-hand side. It should be equality instead. Also, all of the
FieldInfo operate overloads should push a boolean even if they're false
result.

Bug: 10820
Change-Id: Ibddaab29713f26d22ddb4d5804b9edb15e93fd79
Reviewed-on: https://code.wireshark.org/review/6186
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
  • Loading branch information
hadrielk authored and mmann78 committed Jan 1, 2015
1 parent 6d6ba64 commit 445ddc8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions epan/wslua/wslua_field.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,15 @@ 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) {
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 + l->ws_fi->length) {
/* it is not an error if their ds_tvb are different... they're just not equal */
if (l->ws_fi->ds_tvb == r->ws_fi->ds_tvb &&
l->ws_fi->start == r->ws_fi->start &&
r->ws_fi->length == l->ws_fi->length) {
lua_pushboolean(L,1);
return 1;
} else {
return 0;
lua_pushboolean(L,0);
}
return 1;
}

WSLUA_METAMETHOD FieldInfo__le(lua_State* L) {
Expand All @@ -331,10 +329,10 @@ WSLUA_METAMETHOD FieldInfo__le(lua_State* L) {

if (r->ws_fi->start + r->ws_fi->length <= l->ws_fi->start + l->ws_fi->length) {
lua_pushboolean(L,1);
return 1;
} else {
return 0;
lua_pushboolean(L,0);
}
return 1;
}

WSLUA_METAMETHOD FieldInfo__lt(lua_State* L) {
Expand All @@ -349,10 +347,10 @@ WSLUA_METAMETHOD FieldInfo__lt(lua_State* L) {

if (r->ws_fi->start + r->ws_fi->length < l->ws_fi->start) {
lua_pushboolean(L,1);
return 1;
} else {
return 0;
lua_pushboolean(L,0);
}
return 1;
}

/* Gets registered as metamethod automatically by WSLUA_REGISTER_META */
Expand Down

0 comments on commit 445ddc8

Please sign in to comment.