Skip to content

Commit

Permalink
[loki] Simplify aggression checks
Browse files Browse the repository at this point in the history
  • Loading branch information
tysmith committed Jun 7, 2024
1 parent b97a150 commit e4745cb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions loki/loki.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ class Loki:
__slots__ = ("aggr", "byte_order")

def __init__(
self, aggression: Optional[float] = 0.0, byte_order: Optional[str] = None
self, aggression: float = 0.0, byte_order: Optional[str] = None
) -> None:
"""
Arguments:
aggression: Amount of fuzzing to perform. 0 for 0% up to 1.0 for 100%.
byte_order: Used to indicate big or little endian when mutating multiple
bytes at once.
"""
assert aggression is not None
assert aggression >= 0
assert aggression <= 1
assert 0 <= aggression <= 1
assert byte_order is None or byte_order in self.BYTE_ORDERS
self.aggr = min(max(aggression, 0.0), 1.0)
self.aggr = aggression
self.byte_order = byte_order

@staticmethod
Expand Down Expand Up @@ -100,7 +98,7 @@ def _fuzz(self, tgt_fp: IO[bytes]) -> None:
LOG.debug("cannot fuzz empty file")
return
# minimum number of mutations should be 1
max_mutations = max(int(round(length * self.aggr)), 1)
max_mutations = max(round(length * self.aggr), 1)
mutations = randint(1, max_mutations)
LOG.debug(
"%d of a possible %d mutations will be performed", mutations, max_mutations
Expand Down

0 comments on commit e4745cb

Please sign in to comment.