Hi Dominique!

On Do, 28 Jul 2011, Dominique Pellé wrote:

> Christian Brabandt  wrote:
> 
> > Hi Bram!
> >
> > On Do, 28 Jul 2011, Bram Moolenaar wrote:
> >
> >>
> >> Christian Brabandt wrote:
> >>
> >> > Hi Bram,
> >> >
> >> > attached patch fixes this issue from the todo list:
> >> >
> >> > ,----
> >> > | Recognize and ignore BOM in error file. (Aleksey Baibarin)
> >> > `----
> >>
> >> The patch was empty...
> >
> > I wonder how that happened.
> > Anyway here is the patch again.
> >
> > regards
> > Christian
> 
> 
> Hi Christian
> 
> Looking at the patch, I see...
> 
> +     /* it should be safe to use the len variable */
> +     len = STRLEN(IObuff);
> +     if (check_bomb
> +         && STRLEN(IObuff) >= 3
> +         && enc_utf8
> +         && IObuff[0] == 0xef
> +         && IObuff[1] == 0xbb
> +         && IObuff[2] == 0xbf)
> +     /* remove utf-8 byte order mark from file */
> +     {
> +         mch_memmove(IObuff, IObuff+3, len - 3);
> +         IObuff[len-3] = NUL;
> +         check_bomb = FALSE;
> +     }
> 
> 
> It's calling STRLEN(IOBuff) twice.

Oh yes, I forgot to use len at the second time of STRLEN

> The check for STRLEN(IObuff) >= 3 is not
> needed anyway since checking for the 3 bytes
> 0xef, 0xbb, 0xbf will guarantee that STRLEN(IObuff) >= 3.

Thanks for your update. But wouldn't there a null pointer exception, if 
IObuff is less than 3 bytes long? That's why I included the check for 
the length, because if it would be shorter, the expression would 
evaluate to false and the last conditions wouldn't be checked anymore (I 
think)

> Also, you can call STRMOVE() instead of mch_memove()
> which will also avoid having to do IObuff[len - 3] = NUL;
> since STRMOVE() will copy the end of string.

Oh? Didn't see this macro yes. Thanks for pointing me to it.

> So to sum up, I would write it like this (not tested):
> 
> +     if (check_bomb
> +         && enc_utf8
> +         && IObuff[0] == 0xef
> +         && IObuff[1] == 0xbb
> +         && IObuff[2] == 0xbf)
> +     /* remove utf-8 byte order mark from file */
> +     {
> +         STRMOVE(IObuff, IObuff+3);
> +         check_bomb = FALSE;
> +     }

regards,
Christian

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

Raspunde prin e-mail lui