From 4f050ebab997782461d7c6b65dea7b535916329f Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 29 Nov 2014 16:06:42 +0100 Subject: [PATCH] WINGs: fix infinite loop when using Pango on string that have to be split As reported by Charles Philip Chan, WPrefs would get into infinite loop when the support for Pango is enabled. The problem is due to long strings that are broken into multiple lines by WINGs. This is done in an iterative process in the internal function 'fitText'. In order to avoid the cost of duplicating many times the sub-strings, the functions involved do not place a NUL at the string-splitting position, but they rely instead on giving the length of the string as a parameter. The code that checks the Pango text (to avoid re-submitting the string when not needed) did not use that length, so it would always keep the original string that is too long, so the fitText function would always receive the same result and loop forever trying to find where to split the string. This patch adds the check on the length, so Pango is given the appropriate string for its pixel size calculation. Signed-off-by: Christophe CURIS --- WINGs/wfont.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WINGs/wfont.c b/WINGs/wfont.c index a5cff072..b3d399cf 100644 --- a/WINGs/wfont.c +++ b/WINGs/wfont.c @@ -295,7 +295,7 @@ int WMWidthOfString(WMFont * font, const char *text, int length) wassertrv(font != NULL && text != NULL, 0); #ifdef USE_PANGO previous_text = pango_layout_get_text(font->layout); - if ((previous_text == NULL) || (strcmp(text, previous_text) != 0)) + if ((previous_text == NULL) || (strncmp(text, previous_text, length) != 0) || previous_text[length] != '\0') pango_layout_set_text(font->layout, text, length); pango_layout_get_pixel_size(font->layout, &width, NULL);