summaryrefslogtreecommitdiff
path: root/psycopg/pqpath.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-09-04 12:27:16 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-09-04 12:30:18 +0100
commit80df0553a6450df25fa96ee4dbb6acf63efb8ffc (patch)
treef6eed1aea6492155cbc2a33e8c164b42f1780290 /psycopg/pqpath.c
parent4d10f1235fed1c0aa5958cc4a9248688c3345aad (diff)
downloadpsycopg2-fix-961.tar.gz
Fixed handling large Oid valuesfix-961
Oid is defined as unsigned 32. On some Python implementations (probably the ones where maxint = 2 ** 31) this can cause int overflow for large values (see #961). On my 64 box it doesn't seem the case. Oid handling was sloppy here and there (messages, casts...): trying to use uint everywhere, and added a couple of helper macros to treat Oid consistently. Close #961.
Diffstat (limited to 'psycopg/pqpath.c')
-rw-r--r--psycopg/pqpath.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c
index b21f397..414c2d7 100644
--- a/psycopg/pqpath.c
+++ b/psycopg/pqpath.c
@@ -995,9 +995,9 @@ _get_cast(cursorObject *curs, PGresult *pgres, int i)
PyObject *rv = NULL;
Oid ftype = PQftype(pgres, i);
- if (!(type = PyInt_FromLong(ftype))) { goto exit; }
+ if (!(type = PyLong_FromOid(ftype))) { goto exit; }
- Dprintf("_pq_fetch_tuples: looking for cast %d:", ftype);
+ Dprintf("_pq_fetch_tuples: looking for cast %u:", ftype);
if (!(cast = curs_get_cast(curs, type))) { goto exit; }
/* else if we got binary tuples and if we got a field that
@@ -1006,11 +1006,11 @@ _get_cast(cursorObject *curs, PGresult *pgres, int i)
*/
if (cast == psyco_default_binary_cast && PQbinaryTuples(pgres)) {
Dprintf("_pq_fetch_tuples: Binary cursor and "
- "binary field: %i using default cast", ftype);
+ "binary field: %u using default cast", ftype);
cast = psyco_default_cast;
}
- Dprintf("_pq_fetch_tuples: using cast at %p for type %d", cast, ftype);
+ Dprintf("_pq_fetch_tuples: using cast at %p for type %u", cast, ftype);
/* success */
Py_INCREF(cast);
@@ -1041,7 +1041,7 @@ _make_column(connectionObject *conn, PGresult *pgres, int i)
/* fill the type and name fields */
{
PyObject *tmp;
- if (!(tmp = PyInt_FromLong(ftype))) {
+ if (!(tmp = PyLong_FromOid(ftype))) {
goto exit;
}
column->type_code = tmp;
@@ -1099,7 +1099,7 @@ _make_column(connectionObject *conn, PGresult *pgres, int i)
/* table_oid, table_column */
if (ftable != InvalidOid) {
PyObject *tmp;
- if (!(tmp = PyInt_FromLong((long)ftable))) { goto exit; }
+ if (!(tmp = PyLong_FromOid(ftable))) { goto exit; }
column->table_oid = tmp;
}