@@ -314,6 +314,7 @@ static inline void* _PyUnicode_COMPACT_DATA(PyObject *op) {
314
314
}
315
315
316
316
static inline void * _PyUnicode_NONCOMPACT_DATA (PyObject *op) {
317
+ assert (!PyUnicode_IS_COMPACT (op));
317
318
void *data = _PyUnicodeObject_CAST (op)->data .any ;
318
319
assert (data != NULL );
319
320
return data;
@@ -354,13 +355,16 @@ static inline void PyUnicode_WRITE(unsigned int kind, void *data,
354
355
Py_ssize_t index, Py_UCS4 value)
355
356
{
356
357
if (kind == PyUnicode_1BYTE_KIND) {
358
+ assert (value <= 0xffU );
357
359
((Py_UCS1 *)data)[index ] = (Py_UCS1)value;
358
360
}
359
361
else if (kind == PyUnicode_2BYTE_KIND) {
362
+ assert (value <= 0xffffU );
360
363
((Py_UCS2 *)data)[index ] = (Py_UCS2)value;
361
364
}
362
365
else {
363
366
assert (kind == PyUnicode_4BYTE_KIND);
367
+ assert (value <= 0x10ffffU );
364
368
((Py_UCS4 *)data)[index ] = value;
365
369
}
366
370
}
@@ -378,6 +382,7 @@ static inline Py_UCS4 PyUnicode_READ(unsigned int kind,
378
382
if (kind == PyUnicode_2BYTE_KIND) {
379
383
return ((const Py_UCS2 *)data)[index ];
380
384
}
385
+ assert (kind == PyUnicode_4BYTE_KIND);
381
386
return ((const Py_UCS4 *)data)[index ];
382
387
}
383
388
#define PyUnicode_READ (kind, data, index ) \
@@ -397,6 +402,7 @@ static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
397
402
if (kind == PyUnicode_2BYTE_KIND) {
398
403
return PyUnicode_2BYTE_DATA (unicode)[index ];
399
404
}
405
+ assert (kind == PyUnicode_4BYTE_KIND);
400
406
return PyUnicode_4BYTE_DATA (unicode)[index ];
401
407
}
402
408
#define PyUnicode_READ_CHAR (unicode, index ) \
@@ -419,6 +425,7 @@ static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
419
425
if (kind == PyUnicode_2BYTE_KIND) {
420
426
return 0xffffU ;
421
427
}
428
+ assert (kind == PyUnicode_4BYTE_KIND);
422
429
return 0x10ffffU ;
423
430
}
424
431
#define PyUnicode_MAX_CHAR_VALUE (op ) \
0 commit comments