Skip to content

Commit 3a1a8b3

Browse files
author
MarcoGorelli
committed
wip
1 parent 8448d39 commit 3a1a8b3

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

pandas/_libs/src/parser/io.c

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ void *buffer_rd_bytes(void *source, size_t nbytes, size_t *bytes_read,
6666
args = Py_BuildValue("(i)", nbytes);
6767

6868
func = PyObject_GetAttrString(src->obj, "read");
69+
if (func == NULL) {
70+
return NULL;
71+
}
6972

7073
/* TODO: does this release the GIL? */
7174
result = PyObject_CallObject(func, args);

pandas/_libs/src/ujson/python/JSONtoObj.c

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ JSOBJ Object_npyNewArray(void *prv, void *_decoder) {
108108
if (decoder->curdim <= 0) {
109109
// start of array - initialise the context buffer
110110
npyarr = decoder->npyarr = PyObject_Malloc(sizeof(NpyArrContext));
111+
if (npyarr == NULL) {
112+
return NULL;
113+
}
111114
decoder->npyarr_addr = npyarr;
112115

113116
if (!npyarr) {
@@ -119,6 +122,9 @@ JSOBJ Object_npyNewArray(void *prv, void *_decoder) {
119122
npyarr->labels[0] = npyarr->labels[1] = NULL;
120123

121124
npyarr->shape.ptr = PyObject_Malloc(sizeof(npy_intp) * NPY_MAXDIMS);
125+
if (npyarr->shape.ptr == NULL) {
126+
return NULL;
127+
}
122128
npyarr->shape.len = 1;
123129
npyarr->ret = NULL;
124130

pandas/_libs/src/ujson/python/date_conversions.c

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ char *PyDateTimeToIso(PyObject *obj, NPY_DATETIMEUNIT base,
9090

9191
*len = (size_t)get_datetime_iso_8601_strlen(0, base);
9292
char *result = PyObject_Malloc(*len);
93+
if (result == NULL) {
94+
PyErr_NoMemory();
95+
return NULL;
96+
}
9397
// Check to see if PyDateTime has a timezone.
9498
// Don't convert to UTC if it doesn't.
9599
int is_tz_aware = 0;

pandas/_libs/src/ujson/python/objToJSON.c

+24
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ static TypeContext *createTypeContext(void) {
149149
TypeContext *pc;
150150

151151
pc = PyObject_Malloc(sizeof(TypeContext));
152+
if (pc == NULL) {
153+
return NULL;
154+
}
152155
if (!pc) {
153156
PyErr_NoMemory();
154157
return NULL;
@@ -183,11 +186,17 @@ static PyObject *get_values(PyObject *obj) {
183186
// without going through and object array of Timestamps.
184187
if (PyObject_HasAttrString(obj, "tz")) {
185188
PyObject *tz = PyObject_GetAttrString(obj, "tz");
189+
if (tz == NULL) {
190+
return NULL;
191+
}
186192
if (tz != Py_None) {
187193
// Go through object array if we have dt64tz, since tz info will
188194
// be lost if values is used directly.
189195
Py_DECREF(tz);
190196
values = PyObject_CallMethod(obj, "__array__", NULL);
197+
if (values == NULL) {
198+
return NULL;
199+
}
191200
return values;
192201
}
193202
Py_DECREF(tz);
@@ -211,10 +220,19 @@ static PyObject *get_values(PyObject *obj) {
211220

212221
if (values == NULL) {
213222
PyObject *typeRepr = PyObject_Repr((PyObject *)Py_TYPE(obj));
223+
if (typeRepr == NULL) {
224+
return NULL;
225+
}
214226
PyObject *repr;
215227
if (PyObject_HasAttrString(obj, "dtype")) {
216228
PyObject *dtype = PyObject_GetAttrString(obj, "dtype");
229+
if (dtype == NULL) {
230+
return NULL;
231+
}
217232
repr = PyObject_Repr(dtype);
233+
if (repr == NULL) {
234+
return NULL;
235+
}
218236
Py_DECREF(dtype);
219237
} else {
220238
repr = PyUnicode_FromString("<unknown dtype>");
@@ -233,12 +251,18 @@ static PyObject *get_values(PyObject *obj) {
233251

234252
static PyObject *get_sub_attr(PyObject *obj, char *attr, char *subAttr) {
235253
PyObject *tmp = PyObject_GetAttrString(obj, attr);
254+
if (tmp == NULL) {
255+
return NULL;
256+
}
236257
PyObject *ret;
237258

238259
if (tmp == 0) {
239260
return 0;
240261
}
241262
ret = PyObject_GetAttrString(tmp, subAttr);
263+
if (ret == NULL) {
264+
return ret;
265+
}
242266
Py_DECREF(tmp);
243267

244268
return ret;

0 commit comments

Comments
 (0)