summaryrefslogtreecommitdiff
path: root/src/test/modules
diff options
context:
space:
mode:
authorHeikki Linnakangas2019-03-25 09:39:51 +0000
committerHeikki Linnakangas2019-03-25 09:39:51 +0000
commitd303122eab616ccbcfb0bab0fc674bf625d17a7b (patch)
tree64569a591981fac71568bdc118493c8d34ea4f06 /src/test/modules
parent148cf5f462e53f374a2085b2fa8dcde944539b03 (diff)
Clean up the Simple-8b encoder code.
Coverity complained that simple8b_encode() might read beyond the end of the 'diffs' array, in the loop to encode the integers. That was a false positive, because we never get into the loop in modes 0 or 1, and the array is large enough for all the other modes. But I admit it's very subtle, so it's not surprising that Coverity didn't see it, and it's not very obvious to humans either. Refactor it, so that the second loop re-computes the differences, instead of carrying them over from the first loop in the 'diffs' array. This way, the 'diffs' array is not needed anymore. It makes no measurable difference in performance, and seems more straightforward this way. Also, improve the comments in simple8b_encode(): fix the comment about its return value that was flat-out wrong, and explain the condition when it returns EMPTY_CODEWORD better. In the passing, move the 'selector' from the codeword's low bits to the high bits. It doesn't matter much, but looking at the original paper, and googling around for other Simple-8b implementations, that's how it's usually done. Per Coverity, and Tom Lane's report off-list.
Diffstat (limited to 'src/test/modules')
-rw-r--r--src/test/modules/test_integerset/test_integerset.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/test/modules/test_integerset/test_integerset.c b/src/test/modules/test_integerset/test_integerset.c
index 32713f4baa1..eec9e7d0ce9 100644
--- a/src/test/modules/test_integerset/test_integerset.c
+++ b/src/test/modules/test_integerset/test_integerset.c
@@ -539,6 +539,7 @@ test_huge_distances(void)
val = 0;
values[num_values++] = val;
+ /* Test differences on both sides of the 2^60 boundary. */
val += UINT64CONST(1152921504606846976) - 1; /* 2^60 - 1 */
values[num_values++] = val;
@@ -563,16 +564,19 @@ test_huge_distances(void)
val += UINT64CONST(1152921504606846976) + 1; /* 2^60 + 1 */
values[num_values++] = val;
- val += UINT64CONST(1152921504606846976); /* 2^60 */
+ val += UINT64CONST(1152921504606846976) + 2; /* 2^60 + 2 */
values[num_values++] = val;
- /* we're now very close to 2^64, so can't add large values anymore */
+ val += UINT64CONST(1152921504606846976) + 2; /* 2^60 + 2 */
+ values[num_values++] = val;
- intset = intset_create();
+ val += UINT64CONST(1152921504606846976); /* 2^60 */
+ values[num_values++] = val;
/*
- * Add many more values to the end, to make sure that all the above values
- * get flushed and packed into the tree structure.
+ * We're now very close to 2^64, so can't add large values anymore. But
+ * add more smaller values to the end, to make sure that all the above
+ * values get flushed and packed into the tree structure.
*/
while (num_values < 1000)
{
@@ -580,7 +584,8 @@ test_huge_distances(void)
values[num_values++] = val;
}
- /* Add these numbers to the set */
+ /* Create an IntegerSet using these values */
+ intset = intset_create();
for (int i = 0; i < num_values; i++)
intset_add_member(intset, values[i]);