[ctypes-commit] ctypes/source cfield.c,1.70,1.71
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-01-20 21:06:06
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30900 Modified Files: cfield.c Log Message: c_char array structure fields did accept one character less than allowed. Also clarify the error message for c_char and c_wchar array fields. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** cfield.c 30 Nov 2004 16:40:25 -0000 1.70 --- cfield.c 20 Jan 2005 21:05:56 -0000 1.71 *************** *** 825,834 **** if (size > length) { PyErr_Format(PyExc_ValueError, ! "too long (%d chars instead of less than %d)", size, length); Py_DECREF(value); return NULL; } else if (size < length-1) ! /* copy terminating NUL character */ size += 1; PyUnicode_AsWideChar((PyUnicodeObject *)value, (wchar_t *)ptr, size); --- 825,834 ---- if (size > length) { PyErr_Format(PyExc_ValueError, ! "string too long (%d, maximum length %d)", size, length); Py_DECREF(value); return NULL; } else if (size < length-1) ! /* copy terminating NUL character if there is space */ size += 1; PyUnicode_AsWideChar((PyUnicodeObject *)value, (wchar_t *)ptr, size); *************** *** 874,884 **** */ ++size; ! } else if (size >= length) { PyErr_Format(PyExc_ValueError, ! "string too long (%d instead of less than %d)", size, length); return NULL; } ! /* Also copy the terminating NUL character */ memcpy((char *)ptr, data, size); _RET(value); --- 874,884 ---- */ ++size; ! } else if (size > length) { PyErr_Format(PyExc_ValueError, ! "string too long (%d, maximum length %d)", size, length); return NULL; } ! /* Also copy the terminating NUL character if there is space */ memcpy((char *)ptr, data, size); _RET(value); |