@@ -1366,8 +1366,6 @@ WCharArray_get_value(CDataObject *self, void *Py_UNUSED(ignored))
1366
1366
static int
1367
1367
WCharArray_set_value (CDataObject * self , PyObject * value , void * Py_UNUSED (ignored ))
1368
1368
{
1369
- Py_ssize_t result = 0 ;
1370
-
1371
1369
if (value == NULL ) {
1372
1370
PyErr_SetString (PyExc_TypeError ,
1373
1371
"can't delete attribute" );
@@ -1378,29 +1376,24 @@ WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored
1378
1376
"unicode string expected instead of %s instance" ,
1379
1377
Py_TYPE (value )-> tp_name );
1380
1378
return -1 ;
1381
- } else
1382
- Py_INCREF (value );
1379
+ }
1383
1380
1381
+ Py_ssize_t size = self -> b_size / sizeof (wchar_t );
1384
1382
Py_ssize_t len = PyUnicode_AsWideChar (value , NULL , 0 );
1385
1383
if (len < 0 ) {
1386
1384
return -1 ;
1387
1385
}
1388
1386
// PyUnicode_AsWideChar() returns number of wchars including trailing null byte,
1389
1387
// when it is called with NULL.
1390
- if (((size_t )len - 1 ) > self -> b_size /sizeof (wchar_t )) {
1388
+ assert (len > 0 );
1389
+ if (len - 1 > size ) {
1391
1390
PyErr_SetString (PyExc_ValueError , "string too long" );
1392
- result = -1 ;
1393
- goto done ;
1394
- }
1395
- result = PyUnicode_AsWideChar (value ,
1396
- (wchar_t * )self -> b_ptr ,
1397
- self -> b_size /sizeof (wchar_t ));
1398
- if (result >= 0 && (size_t )result < self -> b_size /sizeof (wchar_t ))
1399
- ((wchar_t * )self -> b_ptr )[result ] = (wchar_t )0 ;
1400
- done :
1401
- Py_DECREF (value );
1402
-
1403
- return result >= 0 ? 0 : -1 ;
1391
+ return -1 ;
1392
+ }
1393
+ if (PyUnicode_AsWideChar (value , (wchar_t * )self -> b_ptr , size ) < 0 ) {
1394
+ return -1 ;
1395
+ }
1396
+ return 0 ;
1404
1397
}
1405
1398
1406
1399
static PyGetSetDef WCharArray_getsets [] = {
@@ -3484,10 +3477,12 @@ _validate_paramflags(PyTypeObject *type, PyObject *paramflags)
3484
3477
for (i = 0 ; i < len ; ++ i ) {
3485
3478
PyObject * item = PyTuple_GET_ITEM (paramflags , i );
3486
3479
int flag ;
3487
- char * name ;
3480
+ PyObject * name = Py_None ;
3488
3481
PyObject * defval ;
3489
3482
PyObject * typ ;
3490
- if (!PyArg_ParseTuple (item , "i|ZO" , & flag , & name , & defval )) {
3483
+ if (!PyArg_ParseTuple (item , "i|OO" , & flag , & name , & defval ) ||
3484
+ !(name == Py_None || PyUnicode_Check (name )))
3485
+ {
3491
3486
PyErr_SetString (PyExc_TypeError ,
3492
3487
"paramflags must be a sequence of (int [,string [,value]]) tuples" );
3493
3488
return 0 ;
0 commit comments