[Python-checkins] r55081 - python/branches/release25-maint/Modules/_ctypes python/branches/release25-maint/Modules/_ctypes/cfield.c

thomas.heller python-checkins at python.org
Wed May 2 21:41:21 CEST 2007


Author: thomas.heller
Date: Wed May  2 21:41:16 2007
New Revision: 55081

Modified:
   python/branches/release25-maint/Modules/_ctypes/   (props changed)
   python/branches/release25-maint/Modules/_ctypes/cfield.c
Log:
Merged revisions 55027 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk/Modules/_ctypes

........
  r55027 | thomas.heller | 2007-04-30 18:04:57 +0200 (Mo, 30 Apr 2007) | 8 lines
  
  When accessing the .value attribute of a c_wchar_p instance, and the
  instance does not point to a valid wchar_t zero-terminated string,
  raise a ValueError.  c_char_p does this already.
  
  The ValueError message now contains the correct pointer address.
  
  Will backport to release25-maint.
........


Modified: python/branches/release25-maint/Modules/_ctypes/cfield.c
==============================================================================
--- python/branches/release25-maint/Modules/_ctypes/cfield.c	(original)
+++ python/branches/release25-maint/Modules/_ctypes/cfield.c	Wed May  2 21:41:16 2007
@@ -1333,7 +1333,7 @@
 		if (IsBadStringPtrA(*(char **)ptr, -1)) {
 			PyErr_Format(PyExc_ValueError,
 				     "invalid string pointer %p",
-				     ptr);
+				     *(char **)ptr);
 			return NULL;
 		}
 #endif
@@ -1414,9 +1414,17 @@
 {
 	wchar_t *p;
 	p = *(wchar_t **)ptr;
-	if (p)
+	if (p) {
+#if defined(MS_WIN32) && !defined(_WIN32_WCE)
+		if (IsBadStringPtrW(*(wchar_t **)ptr, -1)) {
+			PyErr_Format(PyExc_ValueError,
+				     "invalid string pointer %p",
+				     *(wchar_t **)ptr);
+			return NULL;
+		}
+#endif
 		return PyUnicode_FromWideChar(p, wcslen(p));
-	else {
+	} else {
 		Py_INCREF(Py_None);
 		return Py_None;
 	}


More information about the Python-checkins mailing list