Skip to Content.
Sympa Menu

freetds - Re: [freetds] Strange assert

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddyz77 AT tin.it>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Strange assert
  • Date: 17 Mar 2003 20:55:27 +0100

Il lun, 2003-03-17 alle 20:21, Rusty Wright ha scritto:
> > What do you say?
> >
> > --jkl
>
> I find the style of the "for" loop odd with the space test, and it's
> wasteful of cpu cycles with it continually assigning to len. The
> typical way I'd do this is
>
> for (i = len; i > 0; i--) {
> if (dres.c[i] != ' ')
> break;
> }
> len = i - 1;
>
> I don't think I've got the initial value of "i" correct; you had it
> set to len-1, but you get the idea; move the test for the space into
> the body of the loop and only assign to len after the loop finishes.

In first iteration you test dres.c[len] != ' '... read buffer overflow
and possible core. If len == 0 after assign len == -1...

Perhaps better is

for(i = len; --i >= 0; )
if (dres.c[i] != ' ')
break;
len = i + 1;

freddy77





Archive powered by MHonArc 2.6.24.

Top of Page