This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: python3 and ctypes, script causes crash
Type: crash Stage:
Components: ctypes Versions: Python 3.0
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: theller Nosy List: ggenellina, loewis, pooryorick, theller
Priority: normal Keywords:

Created on 2009-01-27 03:02 by pooryorick, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg80611 - (view) Author: Poor Yorick (pooryorick) * Date: 2009-01-27 03:02
the following script causes python3 to crash on my Windows XP Pro  Machine:

import ctypes

b = ctypes.windll.Kernel32
var1 = 'TEMP'
out = ctypes.create_string_buffer(40) 
c = b.GetEnvironmentVariableW(var1,out,40)
print('ones', c, out, out.raw)
print('two: ', dir(out))
msg80628 - (view) Author: Gabriel Genellina (ggenellina) Date: 2009-01-27 07:01
3rd argument to GetEnvironmentVariableW is the buffer size in 
*characters*, not bytes. Your buffer has room for 20 characters only, 
not 40. You should use create_unicode_buffer instead.

Probably the names create_unicode_buffer/create_string_buffer should be 
revised in 3.x
msg80629 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-01-27 07:19
Why do you think this is a bug in ctypes? *Of course* it is possible to
crash Python by using ctypes incorrectly.
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49324
2009-01-27 07:19:54loewissetstatus: open -> closed
nosy: + loewis
resolution: not a bug
messages: + msg80629
2009-01-27 07:01:48ggenellinasetnosy: + ggenellina
messages: + msg80628
2009-01-27 03:02:24pooryorickcreate