void test_value(int64_t val) { const uint8_t *cp; uint8_t buf[10], *p; int64_t sinput, soutput; uint64_t uinput, uoutput; size_t used_len; sinput = val; p = buf; assert(__wt_vpack_int(&p, sizeof(buf), sinput) == 0); used_len = (size_t)(p - buf); cp = buf; assert(__wt_vunpack_int(&cp, used_len, &soutput) == 0); /* Ensure we got the correct value back */ if (sinput != soutput) { fprintf(stderr, "mismatch %" PRIu64 ", %" PRIu64 "\n", sinput, soutput); abort(); } /* Ensure that decoding used the correct amount of buffer */ if (cp != p) { fprintf(stderr, "Unpack consumed wrong size for %" PRId64 ", expected %" WT_SIZET_FMT ", got %" WT_SIZET_FMT "\n", sinput, used_len, cp > p ? used_len + (size_t)(cp - p) : /* More than buf used */ used_len - (size_t)(p - cp)); /* Less than buf used */ abort(); } /* Test unsigned, convert negative into bigger positive values */ uinput = (uint64_t)val; p = buf; assert(__wt_vpack_uint(&p, sizeof(buf), uinput) == 0); cp = buf; assert(__wt_vunpack_uint( &cp, sizeof(buf), &uoutput) == 0); /* Ensure we got the correct value back */ if (sinput != soutput) { fprintf(stderr, "mismatch %" PRIu64 ", %" PRIu64 "\n", sinput, soutput); abort(); } /* Ensure that decoding used the correct amount of buffer */ if (cp != p) { fprintf(stderr, "Unpack consumed wrong size for %" PRId64 ", expected %" WT_SIZET_FMT ", got %" WT_SIZET_FMT "\n", sinput, used_len, cp > p ? used_len + (size_t)(cp - p) : used_len - (size_t)(p - cp)); abort(); } }
void test_value(int64_t val) { const uint8_t *cp; uint8_t buf[WT_INTPACK64_MAXSIZE + 8]; /* -Werror=array-bounds */ uint8_t *p; int64_t sinput, soutput; uint64_t uinput, uoutput; size_t used_len; memset(buf, 0xff, sizeof(buf)); /* -Werror=maybe-uninitialized */ sinput = val; soutput = 0; /* -Werror=maybe-uninitialized */ /* * Required on some systems to pull in parts of the library * for which we have data references. */ testutil_check(__wt_library_init()); p = buf; testutil_check(__wt_vpack_int(&p, sizeof(buf), sinput)); used_len = (size_t)(p - buf); testutil_assert(used_len <= WT_INTPACK64_MAXSIZE); cp = buf; testutil_check(__wt_vunpack_int(&cp, used_len, &soutput)); /* Ensure we got the correct value back */ if (sinput != soutput) { fprintf(stderr, "mismatch %" PRId64 ", %" PRId64 "\n", sinput, soutput); abort(); } /* Ensure that decoding used the correct amount of buffer */ if (cp != p) { fprintf(stderr, "Unpack consumed wrong size for %" PRId64 ", expected %" WT_SIZET_FMT ", got %" WT_SIZET_FMT "\n", sinput, used_len, cp > p ? used_len + (size_t)(cp - p) : /* More than buf used */ used_len - (size_t)(p - cp)); /* Less than buf used */ abort(); } /* Test unsigned, convert negative into bigger positive values */ uinput = (uint64_t)val; p = buf; testutil_check(__wt_vpack_uint(&p, sizeof(buf), uinput)); used_len = (size_t)(p - buf); testutil_assert(used_len <= WT_INTPACK64_MAXSIZE); cp = buf; testutil_check(__wt_vunpack_uint(&cp, sizeof(buf), &uoutput)); /* Ensure we got the correct value back */ if (sinput != soutput) { fprintf(stderr, "mismatch %" PRId64 ", %" PRId64 "\n", sinput, soutput); abort(); } /* Ensure that decoding used the correct amount of buffer */ if (cp != p) { fprintf(stderr, "Unpack consumed wrong size for %" PRId64 ", expected %" WT_SIZET_FMT ", got %" WT_SIZET_FMT "\n", sinput, used_len, cp > p ? used_len + (size_t)(cp - p) : used_len - (size_t)(p - cp)); abort(); } }