Skip to content

Commit

Permalink
add comment to oob check in slice
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberthirst committed Mar 16, 2024
1 parent abd3725 commit a78ba17
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def build_IR(self, expr, context):

ADHOC_SLICE_NODE_MACROS = ["~calldata", "~selfcode", "~extcode"]


# make sure we don't overrun the source buffer, checking for
# overflow:
# valid inputs satisfy: `assert start+length <= src_len && start+length > start`
def _make_slice_bounds_check(start, length, src_len):
return [
"with",
Expand Down Expand Up @@ -444,17 +448,6 @@ def build_IR(self, expr, args, kwargs, context):

do_copy = copy_bytes(copy_dst, copy_src, copy_len, copy_maxlen)

# make sure we don't overrun the source buffer, checking for
# overflow:
# valid inputs satisfy: `assert start+length <= src_len && start+length > start`

bounds_check = [
"with",
"end",
["add", start, length],
["assert", ["iszero", ["or", ["gt", "end", src_len], ["lt", "end", start]]]],
]

ret = [
"seq",
_make_slice_bounds_check(start, length, src_len),
Expand Down

0 comments on commit a78ba17

Please sign in to comment.