Skip to content

Fix Miscasting [API-2378] [HZ-5417]#1433

Open
emreyigit wants to merge 4 commits into
hazelcast:masterfrom
emreyigit:fix-twos-complement
Open

Fix Miscasting [API-2378] [HZ-5417]#1433
emreyigit wants to merge 4 commits into
hazelcast:masterfrom
emreyigit:fix-twos-complement

Conversation

@emreyigit
Copy link
Copy Markdown
Member

Refactored the casting.

closes #1432

@emreyigit emreyigit requested a review from ihsandemir as a code owner April 7, 2026 13:25
@emreyigit emreyigit added this to the 5.7.0 milestone Apr 7, 2026
@emreyigit emreyigit self-assigned this Apr 7, 2026
@emreyigit emreyigit enabled auto-merge (squash) April 7, 2026 13:25
@emreyigit emreyigit changed the title Fix Miscasting Fix Miscasting [API-2378] Apr 7, 2026
@emreyigit emreyigit changed the title Fix Miscasting [API-2378] Fix Miscasting [API-2378] [HZ-5417] Apr 7, 2026
Copy link
Copy Markdown
Collaborator

@ihsandemir ihsandemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test to verify it was actually a problem?

@emreyigit emreyigit requested a review from ihsandemir April 20, 2026 10:32
Copy link
Copy Markdown
Collaborator

@ihsandemir ihsandemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a non-trivial array which causes infinite loop without this fix but works after this fix? This will validate the fix.


TEST_F(DecimalTest, twos_complement_multi_byte_full_carry)
{
// carry propagates out of every byte; a size_t loop index would wrap to
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this comment mean? you changed size_t usage to int int he loop at this PR.

Copy link
Copy Markdown
Member Author

@emreyigit emreyigit Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only way to test it is calling the function and verifying its result. I just explained the situation what was it before. Also, I couldn't find any test on twos_complement, so I added single and multiple vector size test which verifies both loop and the function.

Copy link
Copy Markdown
Collaborator

@ihsandemir ihsandemir Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there were existing tests for the complement (see DecimalTest::.... test cases above your added test. e.g. TEST_F(DecimalTest, carry_bit_test)) but not for this exact scenario. you need a specific value to actually see the index goes all the way to 0. Your added tests are OK but they do not catch the infinite loop problem, right? Does you test catch the failure without the fix?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should verify the loop as well since it was discarding the carry bit before due to unsigned int casting.

@emreyigit emreyigit requested a review from ihsandemir April 29, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite loop in twos_complement [API-2378] [HZ-5417]

2 participants