From e0982300cad9cf9873c28f69e025dd9a278934f0 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Tue, 28 Jun 2005 11:52:42 +0000 Subject: [PATCH] Prevent crash on empty string. --- ChangeLog | 5 +++++ src/cairo-atsui-font.c | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8472c04c7..eee3c31a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-06-28 T Rowley + + * src/cairo-atsui-font.c (_cairo_atsui_font_text_to_glyphs): + Prevent crash on empty string. + 2005-06-25 Keith Packard reviewed by: cworth diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c index 06b4ecb7d..bcb079150 100644 --- a/src/cairo-atsui-font.c +++ b/src/cairo-atsui-font.c @@ -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);