| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-fdiagnostics-format=sarif-file" } */ |
| 3 |
/* { dg-excess-errors "The error is sent to the SARIF file, rather than stderr" } */ |
| 4 |
|
| 5 |
#include <stddef.h> |
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
/* Minimal reimplementation of cpython API. */ |
| 9 |
typedef struct PyObject {} PyObject; |
| 10 |
extern int PyArg_ParseTuple (PyObject *args, const char *fmt, ...); |
| 11 |
extern PyObject *PyList_New (int); |
| 12 |
extern PyObject *PyLong_FromLong(long); |
| 13 |
extern void PyList_Append(PyObject *list, PyObject *item); |
| 14 |
|
| 15 |
PyObject * |
| 16 |
make_a_list_of_random_ints_badly(PyObject *self, |
| 17 |
PyObject *args) |
| 18 |
{ |
| 19 |
PyObject *list, *item; |
| 20 |
long count, i; |
| 21 |
|
| 22 |
if (!PyArg_ParseTuple(args, "i", &count)) { |
| 23 |
return NULL; |
| 24 |
} |
| 25 |
|
| 26 |
list = PyList_New(0); |
| 27 |
|
| 28 |
for (i = 0; i < count; i++) { |
| 29 |
item = PyLong_FromLong(random()); |
| 30 |
PyList_Append(list, item); |
| 31 |
} |
| 32 |
|
| 33 |
return list; |
| 34 |
} |
| 35 |
|
| 36 |
/* |
| 37 |
{ dg-final { verify-sarif-file } } |
| 38 |
|
| 39 |
{ dg-final { scan-sarif-file "\"tool\": " } } |
| 40 |
|
| 41 |
We expect info about the plugin: |
| 42 |
{ dg-final { scan-sarif-file "\"extensions\": \\\[" } } |
| 43 |
{ dg-final { scan-sarif-file "\"name\": \"diagnostic_plugin_test_paths\"" } } |
| 44 |
{ dg-final { scan-sarif-file "\"fullName\": \"" } } |
| 45 |
|
| 46 |
{ dg-final { scan-sarif-file "\"results\": \\\[" } } |
| 47 |
{ dg-final { scan-sarif-file "\"level\": \"error\"" } } |
| 48 |
{ dg-final { scan-sarif-file "\"text\": \"passing NULL as argument 1 to 'PyList_Append' which requires a non-NULL parameter\"" } } |
| 49 |
|
| 50 |
We expect a path for the diagnostic: |
| 51 |
{ dg-final { scan-sarif-file "\"codeFlows\": \\\[" } } |
| 52 |
{ dg-final { scan-sarif-file "\"threadFlows\": \\\[" } } |
| 53 |
{ dg-final { scan-sarif-file "\"locations\": \\\[" } } |
| 54 |
{ dg-final { scan-sarif-file "\"text\": \"when 'PyList_New' fails, returning NULL\"" } } |
| 55 |
{ dg-final { scan-sarif-file "\"text\": \"when 'i < count'\"" } } |
| 56 |
{ dg-final { scan-sarif-file "\"text\": \"when calling 'PyList_Append', passing NULL from \\(1\\) as argument 1\"" } } |
| 57 |
|
| 58 |
*/ |