diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-04-14 11:18:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-14 11:18:49 (GMT) |
commit | 6f1e8ccffa5b1272a36a35405d3c4e4bbba0c082 (patch) | |
tree | 59b420c5e232bd9d6f2050ba0c7e1fb5754f0272 /Modules/_sqlite/cursor.c | |
parent | 333d10cbb53dd5f28d76f659a49bf0735f8509d8 (diff) | |
download | cpython-6f1e8ccffa5b1272a36a35405d3c4e4bbba0c082.zip cpython-6f1e8ccffa5b1272a36a35405d3c4e4bbba0c082.tar.gz cpython-6f1e8ccffa5b1272a36a35405d3c4e4bbba0c082.tar.bz2 |
bpo-43752: Fix sqlite3 regression for zero-sized blobs with converters (GH-25228)
Diffstat (limited to 'Modules/_sqlite/cursor.c')
-rw-r--r-- | Modules/_sqlite/cursor.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index dfaa557..09c9a8c 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -240,7 +240,6 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) { int i, numcols; PyObject* row; - PyObject* item = NULL; int coltype; PyObject* converter; PyObject* converted; @@ -282,18 +281,22 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) */ if (converter != Py_None) { const void *blob = sqlite3_column_blob(self->statement->st, i); - if (blob == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) { - PyErr_NoMemory(); - goto error; + if (blob == NULL) { + if (sqlite3_errcode(db) == SQLITE_NOMEM) { + PyErr_NoMemory(); + goto error; + } + converted = Py_NewRef(Py_None); } - - nbytes = sqlite3_column_bytes(self->statement->st, i); - item = PyBytes_FromStringAndSize(blob, nbytes); - if (item == NULL) { - goto error; + else { + nbytes = sqlite3_column_bytes(self->statement->st, i); + PyObject *item = PyBytes_FromStringAndSize(blob, nbytes); + if (item == NULL) { + goto error; + } + converted = PyObject_CallOneArg(converter, item); + Py_DECREF(item); } - converted = PyObject_CallOneArg(converter, item); - Py_DECREF(item); } else { Py_BEGIN_ALLOW_THREADS coltype = sqlite3_column_type(self->statement->st, i); |