[PATCH] pass correct buffersize to LCMapStringW

Rob Shearman robertshearman at gmail.com
Tue Sep 16 06:00:18 CDT 2008


2008/9/16 Dmitry Timoshkov <dmitry at codeweavers.com>:
> "Rob Shearman" <robertshearman at gmail.com> wrote:
>
>>>>> > -    ret = LCMapStringW(LOCALE_USER_DEFAULT, 0, upper_case, 0, buf,
>>>>> > sizeof(buf));
>>>>> > +    ret = LCMapStringW(LOCALE_USER_DEFAULT, 0, upper_case, 0, buf,
>>>>> > sizeof(buf)/sizeof(WCHAR));
>>>>> >     ok(!ret, "LCMapStringW should fail with srclen = 0\n");
>>>>> The size of the target buffer doesn't matter at all in this case, since
>>>>> the API is supposed to fail due to source length being 0.
>>>>
>>>> Even if the size doesn't matter, this line should get fixed, as the Wine
>>>> tests are a kind of of Win32 API reference by example. IMHO you
>>>> shouldn't include such misleading parameters as the size in the wrong
>>>> unit into API usage examples.
>>>
>>> This particular test doesn't depend on the size of the target buffer,
>>> be it 0, -1, or whatever.
>>
>> Why not
>> just pass in a correct length as the destination length or just pass
>> in 0?
>
> Because that wouldn't change anything IMO.

It's a bug lurking. Someone could copy and paste that code, changing
the source length and the source string but forget to change the
destination length, because at first glance it looks correct.

Furthermore, it will flag up as a warning in static analysis tools
that detect this and result in noise where it's hard to find the real
bugs.

-- 
Rob Shearman



More information about the wine-devel mailing list