Dominique wrote:

> When running test32 with vim-7.4.22, I see this valgrind error:
> 
> ==17589== Memcheck, a memory error detector
> ==17589== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
> ==17589== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
> ==17589== Command: ../vim -u unix.vim -U NONE -c set\ maxmem=256
> --noplugin -s dotest.in test32.in
> ==17589== Parent PID: 16711
> ==17589==
> ==17589== Invalid read of size 1
> ==17589==    at 0x4BCE96: utf_head_off (mbyte.c:3434)
> ==17589==    by 0x424339: ins_complete (edit.c:5191)
> ==17589==    by 0x42A7C1: edit (edit.c:1410)
> ==17589==    by 0x4C10F7: invoke_edit (normal.c:9232)
> ==17589==    by 0x4C3721: nv_edit (normal.c:9205)
> ==17589==    by 0x4C9014: normal_cmd (normal.c:1200)
> ==17589==    by 0x576AE9: main_loop (main.c:1329)
> ==17589==    by 0x579C1B: main (main.c:1020)
> ==17589==  Address 0xc3daa4f is 1 bytes before a block of size 8 alloc'd
> ==17589==    at 0x4C2B3F8: malloc (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==17589==    by 0x4B5DE6: lalloc (misc2.c:929)
> ==17589==    by 0x4B5E8B: alloc_check (misc2.c:862)
> ==17589==    by 0x4A975E: ins_str (misc1.c:2347)
> ==17589==    by 0x42703D: insertchar (edit.c:6043)
> ==17589==    by 0x4279DB: insert_special (edit.c:5806)
> ==17589==    by 0x42AC3C: edit (edit.c:1491)
> ==17589==    by 0x4C10F7: invoke_edit (normal.c:9232)
> ==17589==    by 0x4C3721: nv_edit (normal.c:9205)
> ==17589==    by 0x4C9014: normal_cmd (normal.c:1200)
> ==17589==    by 0x576AE9: main_loop (main.c:1329)
> ==17589==    by 0x579C1B: main (main.c:1020)
> 
> 
> Line edit.c:5191 was recently modified in this patch:
> 
> changeset:   5332:d5eb32dc231c
> tag:         v7-4-019
> user:        Bram Moolenaar <[email protected]>
> date:        Thu Sep 05 13:50:53 2013 +0200
> files:       src/edit.c src/version.c
> description:
> updated for version 7.4.019
> Problem:    MS-Windows: File name completion doesn't work properly with
>             Chinese characters. (Yue Wu)
> Solution:   Take care of multi-byte characters when looking for the start of
>             the file name. (Ken Takata)
> 
> $ hg annotate edit.c:
> 
>  5184 vimboss    7: else if (ctrl_x_mode == CTRL_X_FILES)
>  5185 vimboss    7: {
>  5186    bram 5332:     char_u      *p = line + startcol;
>  5187    bram 5332:
>  5188    bram 5332:     /* Go back to just before the first filename
> character. */
>  5189    bram 5332:     mb_ptr_back(line, p);
>  5190    bram 5332:     while (vim_isfilec(PTR2CHAR(p)) && p >= line)
> !5191    bram 5332:         mb_ptr_back(line, p);
>  5192    bram 5332:     startcol = p - line;
>  5193    bram 5332:
>  5194 vimboss  449:     compl_col += ++startcol;
>  5195 vimboss  449:     compl_length = (int)curs_col - startcol;
>  5196 vimboss  449:     compl_pattern = addstar(line + compl_col, 
> compl_length,
>  5197 vimboss  449:                                            EXPAND_FILES);
>  5198 vimboss  449:     if (compl_pattern == NULL)
>  5199 vimboss    7:         return FAIL;
>  5200 vimboss    7: }
> 
> Attached patch fixed it but please verify it.

Thanks for the patch!

Theoretically it might still be invalid to have a pointer just before a
string.  I never encountered a machine with that problem, but it's nicer
to have starcol not become negative and then increment it.  Thus I'll
change it slightly:

            mb_ptr_back(line, p);
            while (p > line && vim_isfilec(PTR2CHAR(p)))
                mb_ptr_back(line, p);
            startcol = (int)(p - line) + 1;
            if (p == line && vim_isfilec(PTR2CHAR(p)))
                startcol = 0;

            compl_col += startcol;


-- 
hundred-and-one symptoms of being an internet addict:
187. You promise yourself that you'll only stay online for another
     15 minutes...at least once every hour.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Raspunde prin e-mail lui