Skip to Content.
Sympa Menu

freetds - buglets in the bcp code

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Steve Langasek <vorlon AT netexpress.net>
  • To: TDS Development Group <freetds AT franklin.metalab.unc.edu>
  • Subject: buglets in the bcp code
  • Date: Sun, 22 Sep 2002 00:45:37 -0500

So now that 0.60[.1] is out the door, I've started taking a look at the
log of building CVS HEAD with -Wall turned on. I've already committed a
number of straightforward fixes for uninitialized variables, missing
#includes, and unused variables; in fact, everything's straightforward
except for src/dblib/bcp.c.

The attached patch addresses a number of warnings related to
uninitialized variables. Innocuous in and of itself, but unlike
elsewhere, I haven't been able to work out at first glance why these
functions are structured the way they are. There's an initial for loop,
within which the pointers in question are modified with each iteration;
and then below there's a second for loop, where only the final value is
used? Given that no one's hit the initialization bug yet, it seems the
code does a good job of making sure the top loop is processed at least
once, but the program flow seemed odd enough to me that I figured it
might be better if someone had a look at this code before I made the
compiler warnings go away.

Cheers,
Steve Langasek
postmodern programmer
Index: bcp.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/dblib/bcp.c,v
retrieving revision 1.18
diff -u -r1.18 bcp.c
--- bcp.c 20 Sep 2002 14:53:37 -0000 1.18
+++ bcp.c 22 Sep 2002 05:19:13 -0000
@@ -400,12 +400,12 @@

TDSSOCKET *tds = dbproc->tds_socket;
TDSRESULTINFO *resinfo;
-BCP_COLINFO *bcpcol;
-TDSCOLINFO *curcol;
+BCP_COLINFO *bcpcol = NULL;
+TDSCOLINFO *curcol = NULL;
BCP_HOSTCOLINFO *hostcol;
-BYTE *src;
+BYTE *src = NULL;
int srctype;
-long len;
+long len = 0;
int buflen;
int destlen;
BYTE *outbuf;
@@ -517,7 +517,12 @@
return FAIL;
}
}
-
+
+ /* Not sure if this is correct, but avoids a segfault. -srl */
+ if (bcpcol == NULL) {
+ continue;
+ }
+
if (hostcol->datatype == 0)
hostcol->datatype = bcpcol->db_type;

@@ -617,7 +622,7 @@

/* The data */

- if (is_blob_type(curcol->column_type)) {
+ if (curcol && is_blob_type(curcol->column_type)) {
fwrite(src,len,1,hostfile);
} else {
if (hostcol->column_len != -1) {
@@ -666,7 +671,7 @@

RETCODE _bcp_read_hostfile(DBPROCESS *dbproc, FILE *hostfile)
{
-BCP_COLINFO *bcpcol;
+BCP_COLINFO *bcpcol = NULL;
BCP_HOSTCOLINFO *hostcol;

int i;
@@ -1512,7 +1517,7 @@
RETCODE bcp_exec(DBPROCESS *dbproc, DBINT *rows_copied)
{

-RETCODE ret;
+RETCODE ret = FAIL;

if (dbproc->bcp_direction == 0)
{
@@ -2243,7 +2248,7 @@

RETCODE _bcp_get_prog_data(DBPROCESS *dbproc)
{
-BCP_COLINFO *bcpcol;
+BCP_COLINFO *bcpcol = NULL;
BCP_HOSTCOLINFO *hostcol;

int i;

Attachment: pgpSCRwoHScgO.pgp
Description: PGP signature




Archive powered by MHonArc 2.6.24.

Top of Page