[Bf-blender-cvs] [8e94d36] master: Interface: avoid setting \0 to drawstr in widget_draw_text

Campbell Barton noreply at git.blender.org
Wed Dec 11 10:35:41 CET 2013


Commit: 8e94d3685a7a421282f031725b8d8ae39a10a30b
Author: Campbell Barton
Date:   Wed Dec 11 20:33:17 2013 +1100
http://developer.blender.org/rB8e94d3685a7a421282f031725b8d8ae39a10a30b

Interface: avoid setting \0 to drawstr in widget_draw_text

===================================================================

M	source/blender/editors/interface/interface_style.c
M	source/blender/editors/interface/interface_widgets.c

===================================================================

diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index 67a686d..f9595ed 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -179,7 +179,7 @@ void uiStyleFontDrawExt(uiFontStyle *fs, const rcti *rect, const char *str,
 	if (fs->kerning == 1)
 		BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
 
-	BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
+	BLF_draw(fs->uifont_id, str, len);
 	BLF_disable(fs->uifont_id, BLF_CLIPPING);
 	if (fs->shadow)
 		BLF_disable(fs->uifont_id, BLF_SHADOW);
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 8debc40..d353983 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1122,8 +1122,8 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti
 
 static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
 {
-	//int transopts;  // UNUSED
-	char *cpoin = NULL;
+	int drawstr_left_len = UI_MAX_DRAW_STR;
+	char *drawstr_right = NULL;
 	
 	/* for underline drawing */
 	float font_xofs, font_yofs;
@@ -1190,21 +1190,24 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
 	/* cut string in 2 parts - only for menu entries */
 	if ((but->block->flag & UI_BLOCK_LOOP)) {
 		if (ELEM3(but->type, NUM, TEX, NUMSLI) == 0) {
-			cpoin = strchr(but->drawstr, UI_SEP_CHAR);
-			if (cpoin) *cpoin = 0;
+			drawstr_right = strchr(but->drawstr, UI_SEP_CHAR);
+			if (drawstr_right) {
+				drawstr_left_len = (drawstr_right - but->drawstr);
+				drawstr_right++;
+			}
 		}
 	}
 	
 	glColor4ubv((unsigned char *)wcol->text);
 
 	uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs,
-	                   sizeof(but->drawstr) - but->ofs, &font_xofs, &font_yofs);
+	                   drawstr_left_len - but->ofs, &font_xofs, &font_yofs);
 
 	if (but->menu_key != '\0') {
 		char fixedbuf[128];
 		char *str;
 
-		BLI_strncpy(fixedbuf, but->drawstr + but->ofs, sizeof(fixedbuf));
+		BLI_strncpy(fixedbuf, but->drawstr + but->ofs, min_ii(sizeof(fixedbuf), drawstr_left_len));
 
 		str = strchr(fixedbuf, but->menu_key - 32); /* upper case */
 		if (str == NULL)
@@ -1233,11 +1236,10 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
 	}
 
 	/* part text right aligned */
-	if (cpoin) {
+	if (drawstr_right) {
 		fstyle->align = UI_STYLE_TEXT_RIGHT;
 		rect->xmax -= ui_but_draw_menu_icon(but) ? UI_DPI_ICON_SIZE : 0.25f * U.widget_unit;
-		uiStyleFontDraw(fstyle, rect, cpoin + 1);
-		*cpoin = UI_SEP_CHAR;
+		uiStyleFontDraw(fstyle, rect, drawstr_right);
 	}
 }




More information about the Bf-blender-cvs mailing list