gdiplus: Prevent NULL StringFormat in gdip_format_string.

This commit is contained in:
Vincent Povirk 2014-04-14 11:44:20 -05:00 committed by Alexandre Julliard
parent 8df0479870
commit 4def66c11c

View File

@ -4392,12 +4392,24 @@ GpStatus gdip_format_string(HDC hdc,
INT hotkeyprefix_count=0; INT hotkeyprefix_count=0;
INT hotkeyprefix_pos=0, hotkeyprefix_end_pos=0; INT hotkeyprefix_pos=0, hotkeyprefix_end_pos=0;
BOOL seen_prefix = FALSE; BOOL seen_prefix = FALSE;
GpStringFormat *dyn_format=NULL;
if(length == -1) length = lstrlenW(string); if(length == -1) length = lstrlenW(string);
stringdup = GdipAlloc((length + 1) * sizeof(WCHAR)); stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
if(!stringdup) return OutOfMemory; if(!stringdup) return OutOfMemory;
if (!format)
{
stat = GdipStringFormatGetGenericDefault(&dyn_format);
if (stat != Ok)
{
GdipFree(stringdup);
return stat;
}
format = dyn_format;
}
nwidth = rect->Width; nwidth = rect->Width;
nheight = rect->Height; nheight = rect->Height;
if (ignore_empty_clip) if (ignore_empty_clip)
@ -4406,10 +4418,7 @@ GpStatus gdip_format_string(HDC hdc,
if (!nheight) nheight = INT_MAX; if (!nheight) nheight = INT_MAX;
} }
if (format)
hkprefix = format->hkprefix; hkprefix = format->hkprefix;
else
hkprefix = HotkeyPrefixNone;
if (hkprefix == HotkeyPrefixShow) if (hkprefix == HotkeyPrefixShow)
{ {
@ -4450,8 +4459,7 @@ GpStatus gdip_format_string(HDC hdc,
length = j; length = j;
if (format) halign = format->align; halign = format->align;
else halign = StringAlignmentNear;
while(sum < length){ while(sum < length){
GetTextExtentExPointW(hdc, stringdup + sum, length - sum, GetTextExtentExPointW(hdc, stringdup + sum, length - sum,
@ -4544,13 +4552,13 @@ GpStatus gdip_format_string(HDC hdc,
break; break;
/* Stop if this was a linewrap (but not if it was a linebreak). */ /* Stop if this was a linewrap (but not if it was a linebreak). */
if ((lret == fitcpy) && format && if ((lret == fitcpy) && (format->attr & StringFormatFlagsNoWrap))
(format->attr & StringFormatFlagsNoWrap))
break; break;
} }
GdipFree(stringdup); GdipFree(stringdup);
GdipFree(hotkeyprefix_offsets); GdipFree(hotkeyprefix_offsets);
GdipDeleteStringFormat(dyn_format);
return stat; return stat;
} }