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. -- Dominique --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
