patch to fix bug 8246

Andrey Turkin andrey.turkin at gmail.com
Tue Mar 11 07:32:01 CDT 2008


This is not about embedded nulls, this is about possibly not null terminated
strings. If there is zero somewhere in the buffer then we should only
convert string up to that zero; if there isn't any nulls, then we have to
convert full string and null-terminate string. This can be coded prettier,
though:

if (l>0)
{
     void *eos = memchr(str, 0, l);
     if (eos)
         l = (LONG)(eos-str);
}

and always zero-pad afterwards

2008/3/11, Alexandre Julliard <julliard at winehq.org>:
>
> Hin-Tak Leung <htl10 at users.sourceforge.net> writes:
>
> > This is the fix to bug 8246 to get HtmlHelpW to work correctly.
> > It was first worked on by Andrey Turkin and updated later by me.
>
>
> Please add a proper log entry describing the change.
>
> > -static inline LPWSTR strdupAtoW(LPCSTR str)
> > +static inline LPWSTR strdupnAtoW(LPCSTR str, LONG l)
> >  {
> >      LPWSTR ret;
> >      DWORD len;
> > +    BOOL   zero_pad;
> >
> >      if(!str)
> >          return NULL;
> >
> > -    len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
> > +    if (l>0)
> > +    {
> > +        LONG i;
> > +        zero_pad = TRUE;
> > +        for (i=0;i<l;i++)
> > +        {
> > +            if (!str[i])
> > +            {
> > +                zero_pad = FALSE;
> > +                l = i+1;
> > +                break;
> > +            }
> > +        }
> > +    } else {
> > +        zero_pad = FALSE;
> > +    }
> > +
> > +    len = MultiByteToWideChar(CP_ACP, 0, str, l, NULL, 0);
> > +    if (zero_pad)
> > +        len++;
>
> This is ugly and unnecessary, MultiByteToWideChar handles embedded nulls
> just fine.
>
>
> --
> Alexandre Julliard
> julliard at winehq.org
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winehq.org/pipermail/wine-devel/attachments/20080311/ffa4a331/attachment.htm 


More information about the wine-devel mailing list