Skip to content

Commit 4671b31

Browse files
authored
Apply batched suggestions from code review
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 5d535c4 commit 4671b31

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎Lib/test/test_ctypes/test_python_api.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ def test_PyOS_snprintf(self):
6868
PyOS_snprintf(buf, sizeof(buf), b"Hello from %s (%d, %d, %d)", b"ctypes", 1, 2, 3)
6969
self.assertEqual(buf.value, b"Hello from ctypes (1, 2, 3)")
7070

71-
# truncated output: C99 return value and trailing NUL
72-
small = create_string_buffer(b"x" * 8, 8)
71+
# Test truncated output
72+
small = create_string_buffer(14)
7373
rv = PyOS_snprintf(small, sizeof(small), b"Hello from %s", b"ctypes")
7474
self.assertEqual(rv, len(b"Hello from ctypes"))
75-
self.assertEqual(small.raw, b"Hello f\0")
75+
self.assertEqual(small.raw, b"Hello from ct\0")
76+
77+
# Test invalid format string
78+
buf = create_string_buffer(14)
79+
rv = PyOS_snprintf(buf, sizeof(buf), b"Hello from %Z", 123)
80+
self.assertEqual(rv, -1)
7681

7782
# not enough arguments
7883
self.assertRaises(TypeError, PyOS_snprintf, buf)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:c:func:`PyOS_vsnprintf` now calls :c:func:`!vsnprintf` on Windows, instead of
1+
:c:func:`PyOS_vsnprintf` now calls the standard C11 :c:func:`!vsnprintf` on Windows, instead of
22
the non-standard :c:func:`!_vsnprintf`. When the output is truncated, it now
3-
returns the number of characters that would have been written, as on other
3+
returns the number of bytes that would have been written (excluding the null byte), as on other
44
platforms, instead of a negative value.

0 commit comments

Comments
 (0)