diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:33 +0000 |
commit | 9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9 (patch) | |
tree | 2784370cda9bbf2da9114d70f05399c0b229d28c /epan/tvbtest.c | |
parent | Adding debian version 4.2.6-1. (diff) | |
download | wireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.tar.xz wireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.zip |
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'epan/tvbtest.c')
-rw-r--r-- | epan/tvbtest.c | 313 |
1 files changed, 157 insertions, 156 deletions
diff --git a/epan/tvbtest.c b/epan/tvbtest.c index e7dd74af..add2380a 100644 --- a/epan/tvbtest.c +++ b/epan/tvbtest.c @@ -18,74 +18,75 @@ #include "tvbuff.h" #include "proto.h" #include "exceptions.h" +#include "wsutil/array.h" #include "wsutil/pint.h" #include <ws_diag_control.h> -gboolean failed = FALSE; +bool failed; typedef struct { struct { - guint8 needle; - gint offset; + uint8_t needle; + int offset; } g8; struct { - gboolean test; - guint16 needle; - gint offset; + bool test; + uint16_t needle; + int offset; } g16; struct { - gboolean test; + bool test; ws_mempbrk_pattern pattern; - gint offset; - guchar found_needle; + int offset; + unsigned char found_needle; } mempbrk; } search_test_params; -static gboolean -test_searches(tvbuff_t *tvb, gint offset, search_test_params *sp) +static bool +test_searches(tvbuff_t *tvb, int offset, search_test_params *sp) { - volatile gboolean ex_thrown = FALSE; + volatile bool ex_thrown = false; TRY { - sp->g8.offset = tvb_find_guint8(tvb, offset, -1, sp->g8.needle); + sp->g8.offset = tvb_find_uint8(tvb, offset, -1, sp->g8.needle); if (sp->g16.test) { - sp->g16.offset = tvb_find_guint16(tvb, offset, -1, sp->g16.needle); + sp->g16.offset = tvb_find_uint16(tvb, offset, -1, sp->g16.needle); } if (sp->mempbrk.test) { sp->mempbrk.offset = - tvb_ws_mempbrk_pattern_guint8(tvb, offset, -1, + tvb_ws_mempbrk_pattern_uint8(tvb, offset, -1, &sp->mempbrk.pattern, &sp->mempbrk.found_needle); } } CATCH_ALL { - ex_thrown = TRUE; + ex_thrown = true; } ENDTRY; return ex_thrown; } /* Tests a tvbuff against the expected pattern/length. - * Returns TRUE if all tests succeeed, FALSE if any test fails */ -static gboolean -test(tvbuff_t *tvb, const gchar* name, - guint8* expected_data, guint expected_length, guint expected_reported_length) + * Returns true if all tests succeeed, false if any test fails */ +static bool +test(tvbuff_t *tvb, const char* name, + uint8_t* expected_data, unsigned expected_length, unsigned expected_reported_length) { - guint length; - guint reported_length; - guint8 *ptr; - volatile gboolean ex_thrown; - volatile guint32 val32; - guint32 expected32; - guint incr, i; + unsigned length; + unsigned reported_length; + uint8_t *ptr; + volatile bool ex_thrown; + volatile uint32_t val32; + uint32_t expected32; + unsigned incr, i; length = tvb_captured_length(tvb); if (length != expected_length) { printf("01: Failed TVB=%s Length of tvb=%u while expected length=%u\n", name, length, expected_length); - failed = TRUE; - return FALSE; + failed = true; + return false; } reported_length = tvb_reported_length(tvb); @@ -93,17 +94,17 @@ test(tvbuff_t *tvb, const gchar* name, if (reported_length != expected_reported_length) { printf("01: Failed TVB=%s Reported length of tvb=%u while expected reported length=%u\n", name, reported_length, expected_reported_length); - failed = TRUE; - return FALSE; + failed = true; + return false; } /* Test boundary case. A BoundsError exception should be thrown. */ - ex_thrown = FALSE; + ex_thrown = false; TRY { tvb_get_ptr(tvb, 0, length + 1); } CATCH(BoundsError) { - ex_thrown = TRUE; + ex_thrown = true; } CATCH(FragmentBoundsError) { printf("02: Caught wrong exception: FragmentBoundsError\n"); @@ -119,13 +120,13 @@ test(tvbuff_t *tvb, const gchar* name, if (!ex_thrown) { printf("02: Failed TVB=%s No BoundsError when retrieving %u bytes\n", name, length + 1); - failed = TRUE; - return FALSE; + failed = true; + return false; } /* Test boundary case with reported_length+1. A ReportedBoundsError exception should be thrown. */ - ex_thrown = FALSE; + ex_thrown = false; TRY { tvb_get_ptr(tvb, 0, reported_length + 1); } @@ -136,7 +137,7 @@ test(tvbuff_t *tvb, const gchar* name, printf("03: Caught wrong exception: FragmentBoundsError\n"); } CATCH(ReportedBoundsError) { - ex_thrown = TRUE; + ex_thrown = true; } CATCH_ALL { printf("03: Caught wrong exception: %lu\n", exc->except_id.except_code); @@ -146,17 +147,17 @@ test(tvbuff_t *tvb, const gchar* name, if (!ex_thrown) { printf("03: Failed TVB=%s No ReportedBoundsError when retrieving %u bytes\n", name, reported_length + 1); - failed = TRUE; - return FALSE; + failed = true; + return false; } /* Test boundary case. A BoundsError exception should be thrown. */ - ex_thrown = FALSE; + ex_thrown = false; TRY { tvb_get_ptr(tvb, -1, 2); } CATCH(BoundsError) { - ex_thrown = TRUE; + ex_thrown = true; } CATCH(FragmentBoundsError) { printf("04: Caught wrong exception: FragmentBoundsError\n"); @@ -172,17 +173,17 @@ test(tvbuff_t *tvb, const gchar* name, if (!ex_thrown) { printf("04: Failed TVB=%s No BoundsError when retrieving 2 bytes from" " offset -1\n", name); - failed = TRUE; - return FALSE; + failed = true; + return false; } /* Test boundary case. A BoundsError exception should not be thrown. */ - ex_thrown = FALSE; + ex_thrown = false; TRY { tvb_get_ptr(tvb, 0, length ? 1 : 0); } CATCH(BoundsError) { - ex_thrown = TRUE; + ex_thrown = true; } CATCH(FragmentBoundsError) { printf("05: Caught wrong exception: FragmentBoundsError\n"); @@ -198,17 +199,17 @@ test(tvbuff_t *tvb, const gchar* name, if (ex_thrown) { printf("05: Failed TVB=%s BoundsError when retrieving 1 bytes from" " offset 0\n", name); - failed = TRUE; - return FALSE; + failed = true; + return false; } /* Test boundary case. A BoundsError exception should not be thrown. */ - ex_thrown = FALSE; + ex_thrown = false; TRY { tvb_get_ptr(tvb, -1, length ? 1 : 0); } CATCH(BoundsError) { - ex_thrown = TRUE; + ex_thrown = true; } CATCH(FragmentBoundsError) { printf("06: Caught wrong exception: FragmentBoundsError\n"); @@ -224,62 +225,62 @@ test(tvbuff_t *tvb, const gchar* name, if (ex_thrown) { printf("06: Failed TVB=%s BoundsError when retrieving 1 bytes from" " offset -1\n", name); - failed = TRUE; - return FALSE; + failed = true; + return false; } /* Check data at boundary. An exception should not be thrown. */ if (length >= 4) { - ex_thrown = FALSE; + ex_thrown = false; TRY { val32 = tvb_get_ntohl(tvb, 0); } CATCH_ALL { - ex_thrown = TRUE; + ex_thrown = true; } ENDTRY; if (ex_thrown) { printf("07: Failed TVB=%s Exception when retrieving " - "guint32 from offset 0\n", name); - failed = TRUE; - return FALSE; + "uint32_t from offset 0\n", name); + failed = true; + return false; } expected32 = pntoh32(expected_data); if (val32 != expected32) { - printf("08: Failed TVB=%s guint32 @ 0 %u != expected %u\n", + printf("08: Failed TVB=%s uint32_t @ 0 %u != expected %u\n", name, val32, expected32); - failed = TRUE; - return FALSE; + failed = true; + return false; } } /* Check data at boundary. An exception should not be thrown. */ if (length >= 4) { - ex_thrown = FALSE; + ex_thrown = false; TRY { val32 = tvb_get_ntohl(tvb, -4); } CATCH_ALL { - ex_thrown = TRUE; + ex_thrown = true; } ENDTRY; if (ex_thrown) { printf("09: Failed TVB=%s Exception when retrieving " - "guint32 from offset 0\n", name); - failed = TRUE; - return FALSE; + "uint32_t from offset 0\n", name); + failed = true; + return false; } expected32 = pntoh32(&expected_data[length-4]); if (val32 != expected32) { - printf("10: Failed TVB=%s guint32 @ -4 %u != expected %u\n", + printf("10: Failed TVB=%s uint32_t @ -4 %u != expected %u\n", name, val32, expected32); - failed = TRUE; - return FALSE; + failed = true; + return false; } } @@ -287,28 +288,28 @@ test(tvbuff_t *tvb, const gchar* name, * tvb_memdup() */ for (incr = 1; incr < length; incr++) { for (i = 0; i < length - incr; i += incr) { - ptr = (guint8*)tvb_memdup(NULL, tvb, i, incr); + ptr = (uint8_t*)tvb_memdup(NULL, tvb, i, incr); if (memcmp(ptr, &expected_data[i], incr) != 0) { printf("11: Failed TVB=%s Offset=%u Length=%u " "Bad memdup\n", name, i, incr); - failed = TRUE; + failed = true; wmem_free(NULL, ptr); - return FALSE; + return false; } wmem_free(NULL, ptr); } } /* One big memdup */ - ptr = (guint8*)tvb_memdup(NULL, tvb, 0, -1); + ptr = (uint8_t*)tvb_memdup(NULL, tvb, 0, -1); if ((length != 0 && memcmp(ptr, expected_data, length) != 0) || (length == 0 && ptr != NULL)) { printf("12: Failed TVB=%s Offset=0 Length=-1 " "Bad memdup\n", name); - failed = TRUE; + failed = true; wmem_free(NULL, ptr); - return FALSE; + return false; } wmem_free(NULL, ptr); @@ -322,21 +323,21 @@ test(tvbuff_t *tvb, const gchar* name, memset(&sp, 0, sizeof sp); - /* Search for the guint8 at this offset. */ + /* Search for the uint8_t at this offset. */ sp.g8.needle = expected_data[i]; - /* If at least two bytes left, search for the guint16 at this offset. */ + /* If at least two bytes left, search for the uint16_t at this offset. */ sp.g16.test = length - i > 1; if (sp.g16.test) { sp.g16.needle = (expected_data[i] << 8) | expected_data[i + 1]; } - /* If the guint8 at this offset is nonzero, try - * tvb_ws_mempbrk_pattern_guint8 as well. + /* If the uint8_t at this offset is nonzero, try + * tvb_ws_mempbrk_pattern_uint8 as well. * ws_mempbrk_compile("\0") is not effective... */ sp.mempbrk.test = expected_data[i] != 0; if (sp.mempbrk.test) { - gchar pattern_string[2] = {expected_data[i], '\0'}; + char pattern_string[2] = {expected_data[i], '\0'}; ws_mempbrk_compile(&sp.mempbrk.pattern, pattern_string); } @@ -345,43 +346,43 @@ test(tvbuff_t *tvb, const gchar* name, if (ex_thrown) { printf("13: Failed TVB=%s Exception when searching, offset %d\n", name, i); - failed = TRUE; - return FALSE; + failed = true; + return false; } - if ((guint)sp.g8.offset != i) { - printf("13: Failed TVB=%s Wrong offset for guint8:%02x," + if ((unsigned)sp.g8.offset != i) { + printf("13: Failed TVB=%s Wrong offset for uint8_t:%02x," " got %d, expected %d\n", name, sp.g8.needle, sp.g8.offset, i); - failed = TRUE; - return FALSE; + failed = true; + return false; } - if (sp.g16.test && (guint)sp.g16.offset != i) { - printf("13: Failed TVB=%s Wrong offset for guint16:%04x," + if (sp.g16.test && (unsigned)sp.g16.offset != i) { + printf("13: Failed TVB=%s Wrong offset for uint16_t:%04x," " got %d, expected %d\n", name, sp.g16.needle, sp.g16.offset, i); - failed = TRUE; - return FALSE; + failed = true; + return false; } - if (sp.mempbrk.test && (guint)sp.mempbrk.offset != i) { + if (sp.mempbrk.test && (unsigned)sp.mempbrk.offset != i) { printf("13: Failed TVB=%s Wrong offset for mempbrk:%02x," " got %d, expected %d\n", name, expected_data[i], sp.mempbrk.offset, i); - failed = TRUE; - return FALSE; + failed = true; + return false; } if (sp.mempbrk.test && sp.mempbrk.found_needle != expected_data[i]) { printf("13: Failed TVB=%s Wrong needle found for mempbrk:%02x," " got %02x, expected %02x\n", name, expected_data[i], sp.mempbrk.found_needle, expected_data[i]); - failed = TRUE; - return FALSE; + failed = true; + return false; } } printf("Passed TVB=%s\n", name); - return TRUE; + return true; } static void @@ -395,29 +396,29 @@ run_tests(void) tvbuff_t *tvb_large[3]; tvbuff_t *tvb_subset[6]; tvbuff_t *tvb_empty_subset; - guint8 *small[3]; - guint small_length[3]; - guint small_reported_length[3]; - guint8 *large[3]; - guint large_length[3]; - guint large_reported_length[3]; - guint8 *subset[6]; - guint subset_length[6]; - guint subset_reported_length[6]; - guint8 temp; - guint8 *comp[6]; + uint8_t *small[3]; + unsigned small_length[3]; + unsigned small_reported_length[3]; + uint8_t *large[3]; + unsigned large_length[3]; + unsigned large_reported_length[3]; + uint8_t *subset[6]; + unsigned subset_length[6]; + unsigned subset_reported_length[6]; + uint8_t temp; + uint8_t *comp[6]; tvbuff_t *tvb_comp[6]; - guint comp_length[6]; - guint comp_reported_length[6]; + unsigned comp_length[6]; + unsigned comp_reported_length[6]; tvbuff_t *tvb_comp_subset; - guint comp_subset_length; - guint comp_subset_reported_length; - guint8 *comp_subset; + unsigned comp_subset_length; + unsigned comp_subset_reported_length; + uint8_t *comp_subset; int len; - tvb_parent = tvb_new_real_data((const guint8*)"", 0, 0); + tvb_parent = tvb_new_real_data((const uint8_t*)"", 0, 0); for (i = 0; i < 3; i++) { - small[i] = g_new(guint8, 16); + small[i] = g_new(uint8_t, 16); temp = 16 * i; for (j = 0; j < 16; j++) { @@ -430,7 +431,7 @@ run_tests(void) } for (i = 0; i < 3; i++) { - large[i] = g_new(guint8, 19); + large[i] = g_new(uint8_t, 19); temp = 19 * i; for (j = 0; j < 19; j++) { @@ -512,7 +513,7 @@ run_tests(void) tvb_comp[1] = tvb_new_composite(); comp_length[1] = small_length[0] + small_length[1]; comp_reported_length[1] = small_reported_length[0] + small_reported_length[1]; - comp[1] = (guint8*)g_malloc(comp_length[1]); + comp[1] = (uint8_t*)g_malloc(comp_length[1]); memcpy(comp[1], small[0], small_length[0]); memcpy(&comp[1][small_length[0]], small[1], small_length[1]); tvb_composite_append(tvb_comp[1], tvb_small[0]); @@ -533,7 +534,7 @@ run_tests(void) tvb_comp[3] = tvb_new_composite(); comp_length[3] = subset_length[4] + subset_length[5]; comp_reported_length[3] = subset_reported_length[4] + subset_reported_length[5]; - comp[3] = (guint8*)g_malloc(comp_length[3]); + comp[3] = (uint8_t*)g_malloc(comp_length[3]); memcpy(comp[3], subset[4], subset_length[4]); memcpy(&comp[3][subset_length[4]], subset[5], subset_length[5]); tvb_composite_append(tvb_comp[3], tvb_subset[4]); @@ -545,7 +546,7 @@ run_tests(void) tvb_comp[4] = tvb_new_composite(); comp_length[4] = small_length[0] + subset_length[1]; comp_reported_length[4] = small_reported_length[0] + subset_reported_length[1]; - comp[4] = (guint8*)g_malloc(comp_length[4]); + comp[4] = (uint8_t*)g_malloc(comp_length[4]); memcpy(&comp[4][0], small[0], small_length[0]); memcpy(&comp[4][small_length[0]], subset[1], subset_length[1]); tvb_composite_append(tvb_comp[4], tvb_small[0]); @@ -563,7 +564,7 @@ run_tests(void) comp_reported_length[1] + comp_reported_length[2] + comp_reported_length[3]; - comp[5] = (guint8*)g_malloc(comp_length[5]); + comp[5] = (uint8_t*)g_malloc(comp_length[5]); len = 0; memcpy(&comp[5][len], comp[0], comp_length[0]); @@ -611,44 +612,44 @@ run_tests(void) typedef struct { // Raw bytes - gint enc_len; - const guint8 *enc; + int enc_len; + const uint8_t *enc; // Varint parameters int encoding; int maxlen; // Results unsigned long expect_except; - guint64 expect_val; - guint expect_len; + uint64_t expect_val; + unsigned expect_len; } varint_test_s; DIAG_OFF_PEDANTIC varint_test_s varint[] = { - {0, (const guint8 *)"", 0, FT_VARINT_MAX_LEN, DissectorError, 0, 0}, // no encoding specified + {0, (const uint8_t *)"", 0, FT_VARINT_MAX_LEN, DissectorError, 0, 0}, // no encoding specified // ENC_VARINT_PROTOBUF - {0, (const guint8 *)"", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, ReportedBoundsError, 0, 0}, - {1, (const guint8 *)"\x00", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 0, 1}, - {1, (const guint8 *)"\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 1, 1}, - {1, (const guint8 *)"\x7f", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 0x7f, 1}, - {2, (const guint8 *)"\x80\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, G_GUINT64_CONSTANT(1)<<7, 2}, - {1, (const guint8 *)"\x80", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, ReportedBoundsError, 0, 0}, // truncated data - {2, (const guint8 *)"\x80\x01", ENC_VARINT_PROTOBUF, 1, 0, 0, 0}, // truncated read - {5, (const guint8 *)"\x80\x80\x80\x80\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, G_GUINT64_CONSTANT(1)<<28, 5}, - {10, (const guint8 *)"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, G_GUINT64_CONSTANT(1)<<63, 10}, - {10, (const guint8 *)"\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 0xffffffffffffffff, 10}, - {10, (const guint8 *)"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x02", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 0, 10}, // overflow + {0, (const uint8_t *)"", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, ReportedBoundsError, 0, 0}, + {1, (const uint8_t *)"\x00", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 0, 1}, + {1, (const uint8_t *)"\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 1, 1}, + {1, (const uint8_t *)"\x7f", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 0x7f, 1}, + {2, (const uint8_t *)"\x80\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, UINT64_C(1)<<7, 2}, + {1, (const uint8_t *)"\x80", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, ReportedBoundsError, 0, 0}, // truncated data + {2, (const uint8_t *)"\x80\x01", ENC_VARINT_PROTOBUF, 1, 0, 0, 0}, // truncated read + {5, (const uint8_t *)"\x80\x80\x80\x80\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, UINT64_C(1)<<28, 5}, + {10, (const uint8_t *)"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, UINT64_C(1)<<63, 10}, + {10, (const uint8_t *)"\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 0xffffffffffffffff, 10}, + {10, (const uint8_t *)"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x02", ENC_VARINT_PROTOBUF, FT_VARINT_MAX_LEN, 0, 0, 10}, // overflow // ENC_VARINT_SDNV - {0, (const guint8 *)"", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, ReportedBoundsError, 0, 0}, - {1, (const guint8 *)"\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, 0, 1}, - {1, (const guint8 *)"\x01", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, 1, 1}, - {1, (const guint8 *)"\x7f", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, 0x7f, 1}, - {2, (const guint8 *)"\x81\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, G_GUINT64_CONSTANT(1)<<7, 2}, - {1, (const guint8 *)"\x81", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, ReportedBoundsError, 1, 0}, // truncated data - {2, (const guint8 *)"\x81\x00", ENC_VARINT_SDNV, 1, 0, 1, 0}, // truncated read - {5, (const guint8 *)"\x81\x80\x80\x80\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, G_GUINT64_CONSTANT(1)<<28, 5}, - {10, (const guint8 *)"\x81\x80\x80\x80\x80\x80\x80\x80\x80\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, G_GUINT64_CONSTANT(1)<<63, 10}, - {10, (const guint8 *)"\x81\xff\xff\xff\xff\xff\xff\xff\xff\x7f", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, 0xffffffffffffffff, 10}, - {10, (const guint8 *)"\x82\x80\x80\x80\x80\x80\x80\x80\x80\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, G_GUINT64_CONSTANT(1)<<57, 0}, // overflow + {0, (const uint8_t *)"", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, ReportedBoundsError, 0, 0}, + {1, (const uint8_t *)"\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, 0, 1}, + {1, (const uint8_t *)"\x01", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, 1, 1}, + {1, (const uint8_t *)"\x7f", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, 0x7f, 1}, + {2, (const uint8_t *)"\x81\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, UINT64_C(1)<<7, 2}, + {1, (const uint8_t *)"\x81", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, ReportedBoundsError, 1, 0}, // truncated data + {2, (const uint8_t *)"\x81\x00", ENC_VARINT_SDNV, 1, 0, 1, 0}, // truncated read + {5, (const uint8_t *)"\x81\x80\x80\x80\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, UINT64_C(1)<<28, 5}, + {10, (const uint8_t *)"\x81\x80\x80\x80\x80\x80\x80\x80\x80\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, UINT64_C(1)<<63, 10}, + {10, (const uint8_t *)"\x81\xff\xff\xff\xff\xff\xff\xff\xff\x7f", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, 0xffffffffffffffff, 10}, + {10, (const uint8_t *)"\x82\x80\x80\x80\x80\x80\x80\x80\x80\x00", ENC_VARINT_SDNV, FT_VARINT_MAX_LEN, 0, UINT64_C(1)<<57, 0}, // overflow }; DIAG_ON_PEDANTIC @@ -657,12 +658,12 @@ varint_tests(void) { tvbuff_t *tvb_parent, *tvb; volatile unsigned long got_ex; - guint64 got_val; - volatile guint got_len; + uint64_t got_val; + volatile unsigned got_len; - tvb_parent = tvb_new_real_data((const guint8*)"", 0, 0); + tvb_parent = tvb_new_real_data((const uint8_t*)"", 0, 0); - for (size_t ix = 0; ix < (sizeof(varint) / sizeof(varint_test_s)); ++ix) { + for (size_t ix = 0; ix < array_length(varint); ++ix) { const varint_test_s *vit = &varint[ix]; tvb = tvb_new_child_real_data(tvb_parent, vit->enc, vit->enc_len, vit->enc_len); @@ -679,19 +680,19 @@ varint_tests(void) if (got_ex != vit->expect_except) { printf("Failed varint #%zu with exception=%lu while expected exception=%lu\n", ix, got_ex, vit->expect_except); - failed = TRUE; + failed = true; continue; } if (got_val != vit->expect_val) { printf("Failed varint #%zu value=%" PRIu64 " while expected value=%" PRIu64 "\n", ix, got_val, vit->expect_val); - failed = TRUE; + failed = true; continue; } if (got_len != vit->expect_len) { printf("Failed varint #%zu length=%u while expected length=%u\n", ix, got_len, vit->expect_len); - failed = TRUE; + failed = true; continue; } printf("Passed varint #%zu\n", ix); @@ -766,29 +767,29 @@ zstd_tests (void) { }; - for (size_t i = 0; i < sizeof tests / sizeof tests[0]; i++) { + for (size_t i = 0; i < array_length(tests); i++) { zstd_testcase *t = tests + i; printf ("ZSTD test: %s ... begin\n", t->desc); - tvbuff_t *tvb = tvb_new_real_data (t->data, (const guint) t->len, (const guint) t->len); + tvbuff_t *tvb = tvb_new_real_data (t->data, (const unsigned) t->len, (const unsigned) t->len); tvbuff_t *got = tvb_uncompress_zstd (tvb, 0, (int) t->len); if (!t->expect) { if (got) { fprintf (stderr, "ZSTD test: %s ... FAIL: Expected error, but got non-NULL from uncompress\n", t->desc); - failed = TRUE; + failed = true; return; } } else { if (!got) { printf ("ZSTD test: %s ... FAIL: Expected success, but got NULL from uncompress.\n", t->desc); - failed = TRUE; + failed = true; return; } char * got_str = tvb_get_string_enc (NULL, got, 0, tvb_reported_length (got), ENC_ASCII); if (0 != strcmp (got_str, t->expect)) { printf ("ZSTD test: %s ... FAIL: Expected \"%s\", got \"%s\".\n", t->desc, t->expect, got_str); - failed = TRUE; + failed = true; return; } wmem_free (NULL, got_str); |