Skip to Content.
Sympa Menu

freetds - Re: [freetds] FW: dblib patch

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] FW: dblib patch
  • Date: Fri, 1 Jul 2005 17:09:41 +0200

> >
> > static int rtrim(char *istr, int ilen) {
> > char *t; int olen = ilen;
> >
> > for (t = istr + (ilen - 1); *t == ' '; t--) {
> > *t = '\0'; olen--;
> > } return olen;
> > }
> >
> > this contain a buffer underflow...
> >
> > Perhaps it would better to rewrite like
> >
> > static int rtrim(char *istr, int ilen) {
> > char *t;
> >
> > for (t = istr + ilen; --t > istr && *t == ' '; ) {
> > *t = '\0'; --ilen;
> > } return ilen;
> > }
> >
> > (it solve also '' problem)
>
> I like this better:
>
> static int
> rtrim(char *str, int len)
> {
> char *t;
>
> for (t = str + --len; t > str && *t == ' '; t--) {
> *t = '\0';
> }
> return t - str;
> }
>
> Thanks for the patch Bill. We distinguish, don't we, between char and
> varchar? char columns shouldn't be trimmed. At least,
> Microsoft's bcp
> doesn't trim them.
>

last line should be

return t - str + 1;

a mix of the two

for (t = istr + ilen; --t > istr && *t == ' '; )
*t = '\0';
return t - str + 1;

About char/varchar is the same, server fill needed spaces if necessary.

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page