Skip to Content.
Sympa Menu

freetds - RE: Losing last character of TEXT fields

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Brian Bruns" <camber AT ais.org>
  • To: freetds AT franklin.oit.unc.edu
  • Subject: RE: Losing last character of TEXT fields
  • Date: Tue, 9 Jul 2002 13:23:27 -0400


I guess I don't have a good grasp of the problem either. Someone want to
put a small test case together that demonstrates it?

Brian

> My grasp of what's really going on here is tenuous, but I've got the
> feeling that my change may not be the proper one, it just happens to fix
> my problem.
>
> As a side note, while mucking around with ODBC (using the 2002-04-06
> version of FreeTDS) I found that TEXT fields returned with one *extra*
> character at the end! But I can't test the latest version of code, so
> I'm not ready to make a claim about that yet.
>
> I don't understand the deeper issues being discussed, but how about this
> instead?
>
> cplen =3D srclen > destlen ? (destlen-1) : srclen;
> memcpy(dest, src, cplen);
> dest[cplen] =3D '\0';
> return cplen;
>
> This is at least safe from buffer overruns, fixes my problem, and seems
> right, regardless of the deeper issues (which may still need to be
> addressed, but not by my small brain). If we assume that srclen is the
> number of data characters without a terminator, this ought to be right,
> I think. ?
>
> Eric
>
>
> > -----Original Message-----
> > From: Brian Bruns [mailto:camber AT ais.org]
> > Sent: Tuesday, July 09, 2002 8:47 AM
> > To: TDS Development Group
> > Subject: [freetds] RE: Losing last character of TEXT fields
> >=20
> > It think the root cause may be deeper. Why is a short destlen being
> asked
> > for? This may have something to do with the return value of
> dbdatlen() or
> > similar calls... ie the application code may be:
> >=20
> > mylen =3D dbdatlen(dbproc, colnum);
> > mybuf =3D malloc(mylen);
> > dbconvert(dbproc,..., mybuf, mylen);
> >=20
> > So by fixing dbdatlen() or whichever it turns out to be, we may get an
> > extra char *and* no buffer problem.
> >=20
> > Brian
> >=20
> > > I think you're right, Frediano; the code is still broken.
> > >
> > > We shouldn't null-terminate unless destlen is -1. If the
> destination
> > buffer
> > > is too small, we should call the error handler and return -1. So
> say
> > the
> > > docs. Eric?
> > >
> > > --jkl
> >=20
> > ---
> > You are currently subscribed to freetds as:
> [edeutsch AT systemsbiology.org]
> > To unsubscribe, forward this message to leave-freetds-
> > 127899P AT franklin.oit.unc.edu




Archive powered by MHonArc 2.6.24.

Top of Page