From 770e7c34d3a36484d09755649a9587908e53e041 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Mon, 7 Nov 2005 14:26:41 +0000 Subject: [PATCH] Fixed problem with unitialized value in dsize. --- ChangeLog | 5 +++++ psycopg/pqpath.c | 22 ++++++++++------------ setup.cfg | 4 ++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index dac04fe3..08d5ba30 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-11-07 Federico Di Gregorio + + * psycopg/pqpath.c: fixed problem with uninitialized value (all this was + started by replacing calloc() calls with PyMem_Malloc().) + 2005-11-04 Federico Di Gregorio * psycopg/typecast.c: a lot of changes: diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index f304816e..111069f5 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -462,17 +462,14 @@ _pq_fetch_tuples(cursorObject *curs) #ifdef PSYCOPG_DISPLAY_SIZE dsize = (int *)PyMem_Malloc(pgnfields * sizeof(int)); if (dsize != NULL) { - if (curs->rowcount == 0) { - for (i=0; i < pgnfields; i++) - dsize[i] = -1; + int j, len; + for (i=0; i < pgnfields; i++) { + dsize[i] = -1; } - else { - int j, len; - for (j = 0; j < curs->rowcount; j++) { - for (i = 0; i < pgnfields; i++) { - len = PQgetlength(curs->pgres, j, i); - if (len > dsize[i]) dsize[i] = len; - } + for (j = 0; j < curs->rowcount; j++) { + for (i = 0; i < pgnfields; i++) { + len = PQgetlength(curs->pgres, j, i); + if (len > dsize[i]) dsize[i] = len; } } } @@ -486,7 +483,7 @@ _pq_fetch_tuples(cursorObject *curs) PyObject *dtitem = PyTuple_New(7); PyObject *type = PyInt_FromLong(ftype); - PyObject *cast; + PyObject *cast = NULL; PyTuple_SET_ITEM(curs->description, i, dtitem); @@ -502,7 +499,8 @@ _pq_fetch_tuples(cursorObject *curs) } } /* else if we got binary tuples and if we got a field that - is binary use the default cast. + is binary use the default cast + FIXME: what the hell am I trying to do here? This just can't work.. */ else if (pgbintuples && cast == psyco_default_binary_cast) { Dprintf("_pq_fetch_tuples: Binary cursor and " diff --git a/setup.cfg b/setup.cfg index 4759da1b..f278e998 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,9 @@ [build_ext] define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3 +# PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this) +# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower) +# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4 +# HAVE_PQPROTOCOL3 should be defined on PostgreSQL >= 8.0 # PSYCOPG_DEBUG can be added to enable verbose debug information # PSYCOPG_OWN_QUOTING can be added above but it is deprecated