incorrect bytes() constructor usage in buf_filled_with (#3077)

This commit is contained in:
Mike Hunhoff
2026-05-16 05:14:24 -06:00
committed by GitHub
parent bbe050437b
commit db0e1536ce
3 changed files with 8 additions and 1 deletions
+1
View File
@@ -113,6 +113,7 @@
- fix: replace assert with isinstance guard in get_callee for invalid MethodSpec tokens @williballenthin
- fix: assign ConfigDict to model_config in ConciseModel so extra="ignore" is actually applied @williballenthin (SURF-42)
- fix: replace assert with isinstance guard in get_callee for invalid MethodSpec tokens @williballenthin (SURF-41)
- fix: incorrect bytes() constructor usage in buf_filled_with @mike-hunhoff #3077
- fix: remove redundant code related to cli loading @mike-hunhoff #3076
### capa Explorer Web
+1 -1
View File
@@ -57,7 +57,7 @@ def buf_filled_with(buf: bytes, character: int) -> bool:
return all(b == character for b in buf)
# single big allocation, re-used each loop
dupe_chunk = bytes(character) * SLICE_SIZE
dupe_chunk = bytes([character]) * SLICE_SIZE
for offset in range(0, len(buf), SLICE_SIZE):
# bytes objects are immutable, so the slices share the underlying array,
+6
View File
@@ -34,6 +34,12 @@ def test_buf_filled_with():
assert buf_filled_with(b"", 0x00) is False # Empty buffer
assert buf_filled_with(b"\x00", 0x00) is True # Single byte
# Large buffers (exercise chunked processing)
assert buf_filled_with(b"A" * 5000, ord("A")) is True
assert buf_filled_with(b"A" * 5000 + b"B", ord("A")) is False
assert buf_filled_with(b"\xff" * 5000, 0xFF) is True
assert buf_filled_with(b"\x00" * 5000, 0x00) is True
def test_extract_ascii_strings():
# test empty buffer