Skip to content

Comments

Fix infinite loop in ApproximateSetCover at bucket 0 due to unsigned underflow#91

Open
alanSquirrelyz wants to merge 1 commit intoParAlg:masterfrom
alanSquirrelyz:master
Open

Fix infinite loop in ApproximateSetCover at bucket 0 due to unsigned underflow#91
alanSquirrelyz wants to merge 1 commit intoParAlg:masterfrom
alanSquirrelyz:master

Conversation

@alanSquirrelyz
Copy link

cur_bkt is size_t, so when cur_bkt == 0, cur_bkt - 1 wraps to SIZE_MAX. This makes pow(1.0 + epsilon, SIZE_MAX) evaluate to infinity, and size_t(infinity) is UB that yields a huge low_threshold. No vertex can satisfy numWon >= low_threshold, causing an infinite loop at bucket 0 for any graph with degree-1 vertices.

----------------------------------------ORIGINAL-----------------------------------------

    const size_t low_threshold =
        std::max((size_t)ceil(pow(1.0 + sc::epsilon, cur_bkt - 1)), (size_t)1);

------------------------------------------FIXED--------------------------------------------

    const size_t low_threshold =
        (cur_bkt == 0) ? (size_t)1
                       : std::max((size_t)ceil(pow(1.0 + sc::epsilon, cur_bkt - 1)), (size_t)1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant