lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Tim:

On Thu, May 23, 2019 at 5:18 PM Tim Hill <drtimhill@gmail.com> wrote:
> On May 23, 2019, at 2:25 AM, Francisco Olarte <folarte@peoplecall.com> wrote:
>  if (sz>=sizeof(BOM) && memcmp(buff, p, sizeof(BOM))==0) {
>    buf+=sizeof(BOM);
>    sz+=sizeof(BOM);
>  }
>  if (sz
> Of course you mean:
> sz -= sizeof(BOM);

Yep, that's why I put the UNTESTED remark. And that's a good catch, no
compilation error ( and I doubt any compiler is smart engough to warn
on it ), and if your editor does not do illegal utf-8, and you skip
writing tests, it will probably go unnoticed for a while, and if you
have zero-padded buffers it can probably work on some files.

That's why I normally prefer [start,end) pointers. I've found you
normally only have to touch one of them and this kind of errors are
less common ( in my code ).

Francisco Olarte.