Prevent crash on empty string.

This commit is contained in:
Tor Lillqvist 2005-06-28 11:52:42 +00:00
parent f3b7d3dfd8
commit e0982300ca
2 changed files with 15 additions and 7 deletions

View file

@ -1,3 +1,8 @@
2005-06-28 T Rowley <tim.rowley@gmail.com>
* src/cairo-atsui-font.c (_cairo_atsui_font_text_to_glyphs):
Prevent crash on empty string.
2005-06-25 Keith Packard <keithp@keithp.com>
reviewed by: cworth

View file

@ -252,29 +252,32 @@ _cairo_atsui_font_text_to_glyphs(void *abstract_font,
ItemCount glyphCount, charCount;
UniChar *theText;
err = ATSUCreateTextLayout(&textLayout);
#if 1
// liberal estimate of size
charCount = strlen(utf8);
if (charCount == 0) {
*glyphs = NULL;
*num_glyphs = 0;
return CAIRO_STATUS_SUCCESS;
}
// Set the text in the text layout object, so we can measure it
theText = (UniChar *) malloc(charCount * sizeof(UniChar));
#if 1
for (i = 0; i < charCount; i++) {
theText[i] = utf8[i];
}
#endif
#if 0
// Set the text in the text layout object, so we can measure it
charCount = strlen(utf8);
theText = (UniChar *) malloc(charCount * sizeof(UniChar));
size_t inBytes = charCount, outBytes = charCount;
iconv_t converter = iconv_open("UTF-8", "UTF-16");
charCount = iconv(converter, utf8, &inBytes, theText, &outBytes);
#endif
err = ATSUCreateTextLayout(&textLayout);
err = ATSUSetTextPointerLocation(textLayout,
theText, 0, charCount, charCount);