Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate code between BV.get_bytes and BV.get_byte #501

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading