aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-10-10 20:22:42 +0100
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2021-10-10 20:48:29 +0000
commit041aa24a3709a2e5556f80338bef6bc4603a0f06 (patch)
treeab0d7f393846529a89d7538bf8e5e889d43a8501
parent13e9e7199c64256370af1f27a57b11acdcd11caf (diff)
ftypes: Rewrite FT_PROTOCOL comparison operator
For efficiency do the comparison in a single function call instead of trying to preserving exactly the previous semantics. Still I tried not to deviate much.
-rw-r--r--epan/ftypes/ftype-protocol.c57
1 files changed, 13 insertions, 44 deletions
diff --git a/epan/ftypes/ftype-protocol.c b/epan/ftypes/ftype-protocol.c
index fd6c89cc2a..7a65b61d77 100644
--- a/epan/ftypes/ftype-protocol.c
+++ b/epan/ftypes/ftype-protocol.c
@@ -198,50 +198,29 @@ slice(fvalue_t *fv, GByteArray *bytes, guint offset, guint length)
}
}
-static gboolean
-cmp_eq(const fvalue_t *fv_a, const fvalue_t *fv_b)
+static int
+_tvbcmp(tvbuff_t *a, tvbuff_t *b)
{
- const protocol_value_t *a = (const protocol_value_t *)&fv_a->value.protocol;
- const protocol_value_t *b = (const protocol_value_t *)&fv_b->value.protocol;
- volatile gboolean eq = FALSE;
-
- TRY {
- if ((a->tvb != NULL) && (b->tvb != NULL)) {
- guint a_len = tvb_captured_length(a->tvb);
+ guint a_len = tvb_captured_length(a);
+ guint b_len = tvb_captured_length(b);
- if (a_len == tvb_captured_length(b->tvb))
- eq = (memcmp(tvb_get_ptr(a->tvb, 0, a_len), tvb_get_ptr(b->tvb, 0, a_len), a_len) == 0);
- } else {
- eq = (strcmp(a->proto_string, b->proto_string) == 0);
- }
- }
- CATCH_ALL {
- /* nothing */
- }
- ENDTRY;
-
- return eq;
+ if (a_len != b_len)
+ return a_len < b_len ? -1 : 1;
+ return memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len);
}
-static gboolean
-cmp_lt(const fvalue_t *fv_a, const fvalue_t *fv_b)
+static int
+cmp_order(const fvalue_t *fv_a, const fvalue_t *fv_b)
{
const protocol_value_t *a = (const protocol_value_t *)&fv_a->value.protocol;
const protocol_value_t *b = (const protocol_value_t *)&fv_b->value.protocol;
- volatile gboolean lt = FALSE;
+ volatile int c = 0;
TRY {
if ((a->tvb != NULL) && (b->tvb != NULL)) {
- guint a_len = tvb_captured_length(a->tvb);
- guint b_len = tvb_captured_length(b->tvb);
-
- if (a_len < b_len) {
- lt = TRUE;
- } else if (a_len == b_len) {
- lt = (memcmp(tvb_get_ptr(a->tvb, 0, a_len), tvb_get_ptr(b->tvb, 0, a_len), a_len) < 0);
- }
+ c = _tvbcmp(a->tvb, b->tvb);
} else {
- lt = (strcmp(a->proto_string, b->proto_string) < 0);
+ c = strcmp(a->proto_string, b->proto_string);
}
}
CATCH_ALL {
@@ -249,17 +228,7 @@ cmp_lt(const fvalue_t *fv_a, const fvalue_t *fv_b)
}
ENDTRY;
- return lt;
-}
-
-static int
-cmp_order(const fvalue_t *fv_a, const fvalue_t *fv_b)
-{
- if (cmp_lt(fv_a, fv_b))
- return -1;
- if (cmp_eq(fv_a, fv_b))
- return 0;
- return 1;
+ return c;
}
static gboolean