Skip to content

Commit

Permalink
Deduplicate code between BV.get_bytes and BV.get_byte (#501)
Browse files Browse the repository at this point in the history
* Deduplicate code between BV.get_bytes and BV.get_byte

* Improve lint
  • Loading branch information
twizmwazin authored Sep 20, 2024
1 parent 6ffd15e commit d9764ea
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions claripy/ast/bv.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def cleanup():

atexit.register(cleanup)

# pylint: disable=too-many-positional-arguments


class BV(Bits):
"""
Expand Down Expand Up @@ -92,15 +94,7 @@ def get_byte(self, index):
:param index: the byte to extract
:return: An 8-bit BV
"""
pos = (self.size() + 7) // 8 - 1 - index
if pos < 0:
raise ValueError(
"Incorrect index %d. Your index must be between %d and %d." % (index, 0, self.size() // 8 - 1)
)
r = self[min(pos * 8 + 7, self.size() - 1) : pos * 8]
if r.size() % 8 != 0: # pylint:disable=no-member
r = r.zero_extend(8 - r.size() % 8) # pylint:disable=no-member
return r
return self.get_bytes(index, 1)

def get_bytes(self, index, size):
"""
Expand Down

0 comments on commit d9764ea

Please sign in to comment.