Skip to content
Snippets Groups Projects
Commit f44d7572 authored by Georgiy Lebedev's avatar Georgiy Lebedev Committed by Vladimir Davydov
Browse files

bitset: fix index size calculation

Bitset index size calculation uses the cardinality of the 'flag' bitset,
but when the bitset index is empty, i.e., uninitialized, the
'flag' bitset is not allocated, hence we should simply return 0.

Closes #5809

NO_DOC=bugfix

(cherry picked from commit d542a01a)
parent 2fb285ab
No related branches found
No related tags found
No related merge requests found
## bugfix/core
* Fixed empty bitset index crash on `len` call (gh-5809).
......@@ -294,7 +294,8 @@ tt_bitset_index_contains_value(struct tt_bitset_index *index, size_t value);
inline size_t
tt_bitset_index_size(const struct tt_bitset_index *index)
{
return tt_bitset_cardinality(index->bitsets[0]);
return index->capacity == 0 ? 0 :
tt_bitset_cardinality(index->bitsets[0]);
}
/**
......
local t = require('luatest')
local server = require('luatest.server')
local g = t.group('')
g.before_all(function(cg)
cg.server = server:new{alias = 'dflt'}
cg.server:start()
end)
g.after_all(function(cg)
cg.server:drop()
end)
-- Checks size of empty, i.e., uninitialized bitset index works correctly.
g.test_empty_uninit_bitset_index_len = function()
g.server:exec(function()
local t = require('luatest')
local s = box.schema.space.create('s')
s:create_index('pk')
s:create_index('bitset', {type = 'bitset'})
t.assert_equals(s.index.bitset:len(), 0)
end)
end
......@@ -45,6 +45,13 @@ void test_size_and_count(void)
struct tt_bitset_index index;
tt_bitset_index_create(&index, realloc);
/*
* Checks size of empty, i.e., uninitialized bitset index works
* correctly.
*/
fail_unless(tt_bitset_index_size(&index) == 0);
/* Checks bit number overflow works correctly. */
fail_unless(tt_bitset_index_count(&index, UINT64_MAX) == 0);
enum { P = 10, SIZE = (1 << P) + 1 };
for(size_t i = 0; i < SIZE; i++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment