Dominique Pelle wrote:
> 2008/11/18 Danek Duvall <[EMAIL PROTECTED]>:
> >
> > In enc_locale(), there's a for loop that looks like this:
> >
> > for (i = 0; s[i] != NUL && s + i < buf + sizeof(buf) - 1; ++i)
> >
> > but I can't figure out what the purpose is for that second test. If I'm
> > reading it correctly, it's testing that the address of the character we're
> > copying from the source is less than the address of the final character in
> > the destination buffer, but that doesn't make much sense to me. I could
> > understand if we were checking the source against the beginning of the
> > destination -- a check for overlap, but it's not doing that.
> >
> > I ran into this because of a bug filed against the x86 build of vim for
> > Solaris, where 'encoding' always gets set to 'latin1', regardless of your
> > locale settings (unless, of course, you've set 'encoding' explicitly).
> > Oddly, it works just fine on SPARC, but it appears that it's just due to
> > the way the compiler's laid out memory on the two platforms.
> >
> > The problem is fixed if I simply remove the test. Is there any reason not
> > to do that in the base?
> >
> > Thanks,
> > Danek
>
>
> s and buf can be unrelated pointers so the comparison looks
> wrong indeed. I think the line...
>
> for (i = 0; s[i] != NUL && s + i < buf + sizeof(buf) - 1; ++i)
>
> ... should be...
>
> for (i = 0; s[i] != NUL && i < sizeof(buf) - 1; ++i)
>
> The test (i < sizeof(buf) - 1) prevents overflow in buf[...],
> I would not remove it.
Indeed. It's very strange that this code got here...
I'll make a patch out of this.
--
A KNIGHT rides into shot and hacks him to the ground. He rides off.
We stay for a moment on the glade. A MIDDLE-AGED LADY in a C. & A.
twin-set emerges from the trees and looks in horror at the body of her
HUSBAND.
MRS HISTORIAN: FRANK!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---