New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in validation for BitVector32 #31410
Comments
It appears that my suggested code is wrong :( The test should be > 32, not >= 32. |
@eiriktsarpalis @layomia, would this fall under The issue does look like a bug: var section1 = BitVector32.CreateSection(short.MaxValue); // 0x0FFF, 0x00 0b0000_0000_0000_0000_0000_1111_1111_1111 Bits 00 to 11
var section2 = BitVector32.CreateSection(short.MaxValue, section1); // 0x0FFF, 0x0C 0b0000_0000_1111_1111_1111_0000_0000_0000 Bits 12 to 23
var section3 = BitVector32.CreateSection(short.MaxValue, section2); // 0x0FFF, 0x18 0b1111_1111_0000_0000_0000_0000_0000_0000 Bits 24 to 35! |
Yes, looks like it. Relabeling.. |
There is a test expecting highest section to be truncated: runtime/src/libraries/System.Collections.Specialized/tests/BitVector32Tests.cs Lines 388 to 405 in a822d39
And the exception documentation implies that:
What should we do here? @eiriktsarpalis |
I suppose we could close the issue as by-design, but the behavior as-is still bothers me. |
... I tried to fix this a long time ago, dotnet/corefx#2920 , but was told not to bother since it was a legacy type, so wrote the test as documentation of as-current behavior (although I left the existing validation alone, for some reason). |
Thanks for the context. In that case I'm going to close this issue as by-design. |
It appears that there is an error in the code for the validation of a new Section in BitVector32.
The code:
creates a new section, given the previous section and the maxValue for the new section.
However, the lines:
test for the previous section being invalid, not the new one being created.
It would seem like the code should be:
Obviously, there is better ways to actually write the code. I am just demonstrating the issue.
The documentation states that the InvalidOperationException should be thrown if "maxValue is greater than the highest value that can be represented by the number of bits after previous."
The text was updated successfully, but these errors were encountered: