summaryrefslogtreecommitdiff
path: root/c/test_c.py
diff options
context:
space:
mode:
Diffstat (limited to 'c/test_c.py')
-rw-r--r--c/test_c.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/c/test_c.py b/c/test_c.py
index 906eb07..9dda28b 100644
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -3498,6 +3498,18 @@ def test_bitfield_as_ppc_gcc():
_test_bitfield_details(flag=SF_GCC_X86_BITFIELDS|SF_GCC_BIG_ENDIAN)
+def buffer_warning(cdata):
+ import warnings
+ buf = buffer(cdata)
+ bytes = len(buf)
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ buffer(cdata, bytes)
+ assert len(w) == 0
+ buffer(cdata, bytes + 1)
+ assert len(w) <= 1
+ return len(w) == 1
+
def test_struct_array_no_length():
BInt = new_primitive_type("int")
BIntP = new_pointer_type(BInt)
@@ -3612,6 +3624,7 @@ def test_struct_array_no_length():
assert p.a[1] == 20
assert p.a[2] == 30
assert p.a[3] == 0
+ assert buffer_warning(p)
#
# struct of struct of varsized array
BStruct2 = new_struct_type("bar")
@@ -3620,6 +3633,20 @@ def test_struct_array_no_length():
for i in range(2): # try to detect heap overwrites
p = newp(new_pointer_type(BStruct2), [100, [200, list(range(50))]])
assert p.tail.y[49] == 49
+ assert buffer_warning(p)
+ assert not buffer_warning(cast(new_pointer_type(BStruct2), p))
+ assert not buffer_warning(cast(BIntP, p))
+
+def test_more_buffer_warning():
+ BChar = new_primitive_type("char")
+ BCharP = new_pointer_type(BChar)
+ BArray = new_array_type(BCharP, 10) # char[10]
+ p = newp(BArray)
+ assert buffer_warning(p)
+ assert not buffer_warning(cast(BCharP, p))
+ p = newp(BCharP)
+ assert buffer_warning(p)
+ assert not buffer_warning(cast(BCharP, p))
def test_struct_array_no_length_explicit_position():