New GitHub issue #122148 from aotto1968:<br>
<hr>
<pre>
# Bug report
### Bug description:
I use the C api from python and due to a programming error a new list was created with
```
PyObject* argsO = PyList_New(num+wrong_something);
```
which was explicitly partially *not* initialized. The funny thing about the error is that an output in python with
```
print("callback2", vals, file=sys.stderr)
```
produced an output where the NOT initialized values were marked with "\<NULL>":
```
callback2 ['0', 'main', '', <NULL>, <NULL>, <NULL>, <NULL>, <NULL>]
```
but the further processing in C with:
```
iterator = PyObject_GetIter(argsO);
while ((item = PyIter_Next(iterator))) {
LngErrorCheckN (strO = PyObject_Str(item))
MkBufferListAppendSTR(args, PyUnicode_AsUTF8(strO));
Py_CLEAR(strO);
Py_CLEAR(item);
}
```
then ended up in a core dump of my extension:
```
: BackTrace {
: [ library : filename : lineno ] function
: [ ------- : -------- : ------ ] --------
: [ theLink : c/sys_mq.c : 708 ] MqDisasterSignal
: [ unknown : unknown : 0 ] unknown
: [ system : ./Include/object.h : 502 ] Py_INCREF
: [ system : Objects/listobject.c : 3254 ] listiter_next
: [ system : Objects/abstract.c : 2864 ] PyIter_Next
...
: [ theKernel : py/LibMkKernel_py.c : 208 ] py_mkkernel_LngListToMkBufferListS
: [ theKernel : c/tmpl/mk_misc_check_lng.h : 240 ] py_mkkernel_CheckBAC
: [ theKernel : py/MkBufferListC_py.c : 195 ] py_mkkernel_MkBufferListC_AppendLA
```
where it is clearly visible that `PyIter_Next` *cannot* handle `NULL`.
### CPython versions tested on:
3.11
### Operating systems tested on:
Linux
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/122148">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>