A modern, user friendly, generic, type-safe and fast C99 container library: String, Vector, Sorted and Unordered Map and Set, Deque, Forward List, Smart Pointers, Bitset and Random numbers.
MIT License
1.35k
stars
73
forks
source link
cbits_resize resets the contents of existing element when shrinking #93
I have noticed what appears to be undesired behavior in the cbits_resize() function. When resizing a cbits object from a size aligned with a buffer entry (such as 64) down to one not aligned to a buffer entry (such as 50), the masking logic will overwrite all bits in the entry to the new default value. This does not occur when cbits size is, for instance, 63 instead of 64. I have created a small test program that illustrates the problem, and I am planning to open a merge request with a proposed fix soon.
In the following program, resizing a cbits object from 64 bits to 53 results in all bits being set to 1, whereas resizing from 63 to 53 appears to behave correctly. The same behavior is also observed when resizing from 128 to 100, except that only bits 65 through 100 are set to the default value of 1 instead of the entire buffer.
I have noticed what appears to be undesired behavior in the
cbits_resize()
function. When resizing a cbits object from a size aligned with a buffer entry (such as 64) down to one not aligned to a buffer entry (such as 50), the masking logic will overwrite all bits in the entry to the new default value. This does not occur when cbits size is, for instance, 63 instead of 64. I have created a small test program that illustrates the problem, and I am planning to open a merge request with a proposed fix soon.In the following program, resizing a cbits object from 64 bits to 53 results in all bits being set to 1, whereas resizing from 63 to 53 appears to behave correctly. The same behavior is also observed when resizing from 128 to 100, except that only bits 65 through 100 are set to the default value of 1 instead of the entire buffer.
Program output: