Skip to content

Commit 971b8b9

Browse files
committed
Improved error handling using SWIG_fail.
The SWIG_fail expands to `goto fail`, which is a code section that returns `NULL` and frees the memory if applicable.
1 parent 9895db2 commit 971b8b9

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

swig/src/openscap.i

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
$1 = (time_t) PyFloat_AsDouble($input);
5252
else {
5353
PyErr_SetString(PyExc_TypeError,"Expected a large number");
54-
return NULL;
54+
SWIG_fail;
5555
}
5656
}
5757

@@ -88,7 +88,7 @@
8888
$1[i] = 0;
8989
} else {
9090
PyErr_SetString(PyExc_TypeError,"not a list");
91-
return NULL;
91+
SWIG_fail;
9292
}
9393
}
9494

@@ -105,11 +105,11 @@
105105

106106
if (!PySequence_Check($input)) {
107107
PyErr_SetString(PyExc_ValueError,"Expected a sequence");
108-
return NULL;
108+
SWIG_fail;
109109
}
110110
if (a_size <= 0) {
111111
PyErr_SetString(PyExc_ValueError,"Expected not empty sequence");
112-
return NULL;
112+
SWIG_fail;
113113
}
114114

115115
$1 = (struct cpe_name **) malloc(a_size*sizeof(struct cpe_name *));
@@ -118,12 +118,12 @@
118118
PyObject *obj = PySequence_GetItem($input,i);
119119
if (obj == NULL) {
120120
SWIG_exception_fail(SWIG_ArgError(res_o), "in argument '" "cpe_name" "' substitution '" "', can't access sequence");
121-
return NULL; /*5956*/
121+
SWIG_fail; /*5956*/
122122
}
123123
res_o = SWIG_ConvertPtr(obj, &arg, SWIGTYPE_p_cpe_name, 0 );
124124
if (!SWIG_IsOK(res_o)) {
125125
SWIG_exception_fail(SWIG_ArgError(res_o), "in argument '" "cpe_name" "' substitution invalid types");
126-
return NULL;
126+
SWIG_fail;
127127
}
128128
$1[i] = (struct cpe_name *) arg;
129129
}
@@ -137,11 +137,11 @@
137137

138138
if (!PySequence_Check($input)) {
139139
PyErr_SetString(PyExc_ValueError,"Expected a sequence");
140-
return NULL;
140+
SWIG_fail;
141141
}
142142
if (a_size <= 0) {
143143
PyErr_SetString(PyExc_ValueError,"Expected not empty sequence");
144-
return NULL;
144+
SWIG_fail;
145145
}
146146

147147
$1 = (struct oval_syschar_model **) malloc(a_size*sizeof(struct oval_syschar_model *));
@@ -150,12 +150,12 @@
150150
PyObject *obj = PySequence_GetItem($input,i);
151151
if (obj == NULL) {
152152
SWIG_exception_fail(SWIG_ArgError(res_o), "in argument '" "oval_syschar_model" "' substitution '" "', can't access sequence");
153-
return NULL;
153+
SWIG_fail;
154154
}
155155
res_o = SWIG_ConvertPtr(obj, &arg, SWIGTYPE_p_oval_syschar_model, 0 );
156156
if (!SWIG_IsOK(res_o)) {
157157
SWIG_exception_fail(SWIG_ArgError(res_o), "in argument '" "oval_syschar_model" "' substitution invalid types");
158-
return NULL;
158+
SWIG_fail;
159159
}
160160
$1[i] = (struct oval_syschar_model *) arg;
161161
}

0 commit comments

Comments
 (0)