diff -r 2c8062da7250 Lib/ctypes/__init__.py --- a/Lib/ctypes/__init__.py Sat Jan 09 12:22:13 2016 -0500 +++ b/Lib/ctypes/__init__.py Sat Jan 09 23:01:30 2016 +0200 @@ -52,6 +52,8 @@ if isinstance(init, bytes): if size is None: size = len(init)+1 + elif len(init) >= size and init[size - 1] != 0: + raise ValueError("Buffer size is too small to contain initial value and NULL char.") buftype = c_char * size buf = buftype() buf.value = init