Skip to content

Conversation

@chinggg
Copy link
Contributor

@chinggg chinggg commented Aug 12, 2023

When reviewing update_bitmap_score, I get confused about the logic of comparing fav_factor and top_rated_fav_factor then skip the loop. top_rated_fav_factor was actually calculated twice, but only one calculation and comparison is needed. The replacement shown below should not change the semantic of this code.

-        if (unlikely(afl->schedule >= RARE) || unlikely(afl->fixed_seed)) {
-
-          if (fav_factor > afl->top_rated[i]->len << 2) { continue; }
-
-        } else {
-
-          if (fav_factor >
-              afl->top_rated[i]->exec_us * afl->top_rated[i]->len) {
-
-            continue;
-
-          }
-
-        }
+        if (fav_factor > top_rated_fav_factor) continue;

Since now fav_factor > top_rated_fav_factor in the loop will always cause skip of current iteration, else if (fuzz_p2 == top_rated_fuzz_p2) is also redundant.

         if (fuzz_p2 > top_rated_fuzz_p2) {
 
           continue;
 
-        } else if (fuzz_p2 == top_rated_fuzz_p2) {
-
-          if (fav_factor > top_rated_fav_factor) { continue; }
-
         }
 
         if (fav_factor > top_rated_fav_factor) continue;

Finally we get two simple condition that skip current iteration.

        if (fuzz_p2 > top_rated_fuzz_p2) continue;

        if (fav_factor > top_rated_fav_factor) continue;

`top_rated_fav_factor` was actually calculated twice,
but only one calculation and comparison is needed.

Since `fav_factor` > `top_rated_fav_factor` will always cause skip of current
iteration, `else if (fuzz_p2 == top_rated_fuzz_p2)` is also redundant.
@vanhauser-thc
Copy link
Member

you are right, thank you!

@vanhauser-thc vanhauser-thc merged commit f838509 into AFLplusplus:dev Aug 13, 2023
@chinggg chinggg deleted the fix-fav_factor branch August 15, 2023 07:22
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.

2 participants