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: "Eric Deutsch" <edeutsch AT systemsbiology.org>
  • To: "TDS Development Group" <freetds AT franklin.oit.unc.edu>
  • Subject: RE: Losing last character of TEXT fields
  • Date: Tue, 9 Jul 2002 10:00:54 -0700



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 = srclen > destlen ? (destlen-1) : srclen;
memcpy(dest, src, cplen);
dest[cplen] = '\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
>
> 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:
>
> mylen = dbdatlen(dbproc, colnum);
> mybuf = malloc(mylen);
> dbconvert(dbproc,..., mybuf, mylen);
>
> So by fixing dbdatlen() or whichever it turns out to be, we may get an
> extra char *and* no buffer problem.
>
> Brian
>
> > 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
>
> ---
> 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