Dominique -
> On 8/6/07, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
>
> > Patch 7.1.055
> > Problem: Using strcpy() with arguments that overlap.
> > Solution: Use mch_memmove() instead.
>
>
> > *** ../vim-7.1.054/src/termlib.c Thu May 10 20:20:59 2007
> > --- src/termlib.c Sun Aug 5 21:52:41 2007
> > ***************
> > *** 191,197 ****
> > lbuf[0] == '\t' &&
> > lbuf[1] == ':')
> > {
> > ! strcpy(lbuf, lbuf+2);
> > llen -= 2;
> > }
> > if (lbuf[llen-2] == '\\') /* and continuations */
> > --- 191,197 ----
> > lbuf[0] == '\t' &&
> > lbuf[1] == ':')
> > {
> > ! mch_memmove(lbuf, lbuf + 2, strlen(lbuf + 2) + 1);
> > llen -= 2;
> > }
> > if (lbuf[llen-2] == '\\') /* and continuations */
>
>
> I've noticed that STRLEN() wrapper is used everywhere in
> this patch 55 (and in vim in general), except in the last chunk
> of the patch, where standard C strlen() is used. I assume it
> should be STRLEN().
"lbuf" is of type "char *". STRLEN() needs to be used for "char_u *".
> Also, regarding replacing STRCPY(p, p + 2); with
> mch_memmove(p, p + 2, STRLEN(p) - 1);
>
> I assume it's impossible to have p point to a buffer containing
> "\0\0\0" for example, or else it would crash (STRLEN(p) - 1
> being a negative number).
Can't happen, p is pointing to "\~".
> I think mch_memmove(p, p + 2, STRLEN(p + 2) + 1); is thus closer to
> the original behavior.
Yeah, I was just keeping the line short, and it's more like the similar
use of mch_memmove() above it.
> Also, if p is not an empty string, mch_memmove(p, p + 2, STRLEN(p + 2) + 1);
> seems slightly more efficient than mch_memmove(p, p + 2, STRLEN(p) - 1);
> since it saves 2 tests and 2 loop iterations inside STRLEN for only an
> additional +2 constant addition (better for pipeline)
These are really minor.
I thought of making a VIM_STRCPY() that hides all this, but didn't want
to change all the source code.
- Bram
--
The primary purpose of the DATA statement is to give names to constants;
instead of referring to pi as 3.141592653589793 at every appearance, the
variable PI can be given that value with a DATA statement and used instead
of the longer form of the constant. This also simplifies modifying the
program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
/// 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
-~----------~----~----~----~------~----~------~--~---