[ python-Bugs-1646630 ] ctypes.string_at(buf, 0) is seen as zero-terminated-string

SourceForge.net noreply at sourceforge.net
Sun Jan 28 23:18:20 CET 2007


Bugs item #1646630, was opened at 2007-01-28 22:18
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1646630&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Extension Modules
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Johannes Hölzl (johannes)
Assigned to: Nobody/Anonymous (nobody)
Summary: ctypes.string_at(buf, 0) is seen as zero-terminated-string

Initial Comment:
ctypes.string_at() interprets size=0 wrong.

When the size argument is 0, ctypes.string_at (and probably wstring_at too) string_at tries to read an zero-terminated string instead of an empty string.

Python 2.5 (r25:51908, Oct  6 2006, 15:22:41) 
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> bytes = (c_char*3)("1", "2", "\0")
>>> string_at(pointer(bytes))
'12'
>>> string_at(pointer(bytes), 0)
'12'
>>> string_at(pointer(bytes), 1)
'1'

instead of:

>>> string_at(pointer(bytes), 0)
''



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1646630&group_id=5470


More information about the Python-bugs-list mailing list