[PATCH] Fix unsigned preserving in drw_text

From: Jochen Sprickerhof <jochen_AT_sprickerhof.de>
Date: Thu, 20 Jun 2013 22:33:21 +0200

tex.w, w and tex.h are all unsigned integer. If tex.h is bigger than w,
there is an integer overflow and the condition is met. Instead of
changing all variables to signed, let's test if the difference is
negative.
---
 drw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drw.c b/drw.c
index bc4ac41..b130405 100644
--- a/drw.c
+++ b/drw.c
_AT_@ -157,7 +157,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
 	ty = y + (h / 2) - (th / 2) + drw->font->ascent;
 	tx = x + (h / 2);
 	/* shorten text if necessary */
-	for(len = MIN(olen, sizeof buf); len && tex.w > w - tex.h; len--)
+	for(len = MIN(olen, sizeof buf); len && (tex.w > w - tex.h || w < tex.h); len--)
 		drw_font_getexts(drw->font, text, len, &tex);
 	if(!len)
 		return;
-- 
1.8.3.1
--C7zPtVaVf+AK4Oqc--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Fri Jun 21 2013 - 14:24:02 CEST