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().

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).

I think mch_memmove(p, p + 2, STRLEN(p + 2) + 1); is thus closer to
the original behavior.

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)

Cheers
-- Dominique

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui