| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-fdiagnostics-format=json" } */ |
| 3 |
|
| 4 |
#include <stddef.h> |
| 5 |
#include <stdlib.h> |
| 6 |
|
| 7 |
/* Minimal reimplementation of cpython API. */ |
| 8 |
typedef struct PyObject {} PyObject; |
| 9 |
extern int PyArg_ParseTuple (PyObject *args, const char *fmt, ...); |
| 10 |
extern PyObject *PyList_New (int); |
| 11 |
extern PyObject *PyLong_FromLong(long); |
| 12 |
extern void PyList_Append(PyObject *list, PyObject *item); |
| 13 |
|
| 14 |
PyObject * |
| 15 |
make_a_list_of_random_ints_badly(PyObject *self, |
| 16 |
PyObject *args) |
| 17 |
{ |
| 18 |
PyObject *list, *item; |
| 19 |
long count, i; |
| 20 |
|
| 21 |
if (!PyArg_ParseTuple(args, "i", &count)) { |
| 22 |
return NULL; |
| 23 |
} |
| 24 |
|
| 25 |
list = PyList_New(0); |
| 26 |
|
| 27 |
for (i = 0; i < count; i++) { |
| 28 |
item = PyLong_FromLong(random()); |
| 29 |
PyList_Append(list, item); |
| 30 |
} |
| 31 |
|
| 32 |
return list; |
| 33 |
} |
| 34 |
|
| 35 |
/* { dg-begin-multiline-output "" } |
| 36 |
[{"kind": "error", |
| 37 |
"message": "passing NULL as argument 1 to 'PyList_Append' which requires a non-NULL parameter", |
| 38 |
"children": [], |
| 39 |
"column-origin": 1, |
| 40 |
"locations": [{"caret": {"file": " |
| 41 |
"line": 29, |
| 42 |
"display-column": 5, |
| 43 |
"byte-column": 5, |
| 44 |
"column": 5}, |
| 45 |
"finish": {"file": " |
| 46 |
"line": 29, |
| 47 |
"display-column": 29, |
| 48 |
"byte-column": 29, |
| 49 |
"column": 29}}], |
| 50 |
"path": [{"location": {"file": " |
| 51 |
"line": 25, |
| 52 |
"display-column": 10, |
| 53 |
"byte-column": 10, |
| 54 |
"column": 10}, |
| 55 |
"description": "when 'PyList_New' fails, returning NULL", |
| 56 |
"function": "make_a_list_of_random_ints_badly", |
| 57 |
"depth": 0}, |
| 58 |
{"location": {"file": " |
| 59 |
"line": 27, |
| 60 |
"display-column": 17, |
| 61 |
"byte-column": 17, |
| 62 |
"column": 17}, |
| 63 |
"description": "when 'i < count'", |
| 64 |
"function": "make_a_list_of_random_ints_badly", |
| 65 |
"depth": 0}, |
| 66 |
{"location": {"file": " |
| 67 |
"line": 29, |
| 68 |
"display-column": 5, |
| 69 |
"byte-column": 5, |
| 70 |
"column": 5}, |
| 71 |
"description": "when calling 'PyList_Append', passing NULL from (1) as argument 1", |
| 72 |
"function": "make_a_list_of_random_ints_badly", |
| 73 |
"depth": 0}], |
| 74 |
"escape-source": false}] |
| 75 |
{ dg-end-multiline-output "" } */ |