From 255541383806724ea874ebed1f42fbf195a06925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Wed, 19 Jun 2019 21:11:00 +0200 Subject: [PATCH] wruler.c Remove format-truncation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch removes the format-truncation error. The warning is because c has size of 3, but using "%d" is not possible to store the value. wruler.c: In function ‘paintRuler.part.0’: wruler.c:184:28: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 3 [-Wformat-truncation=] snprintf(c, sizeof(c), "%d", ++j); ^~ wruler.c:184:27: note: directive argument in the range [1, 2147483647] snprintf(c, sizeof(c), "%d", ++j); ^~~~ wruler.c:184:4: note: ‘snprintf’ output between 2 and 11 bytes into a destination of size 3 snprintf(c, sizeof(c), "%d", ++j); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The value "j" is the result of "m < w". w is the result of rPtr->view->size.width - rPtr->margins.left;, and both variables are unsigned int. So the value for w is an unsigned int and m is related to i. m cannot be greater of unsigned int. i = j = m = 0; w = rPtr->view->size.width - rPtr->margins.left; while (m < w) { XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer, rPtr->fgGC, rPtr->margins.left + m, 23, rPtr->margins.left + m, marks[i % 8] + 23); if (i != 0 && i % 8 == 0) { snprintf(c, sizeof(c), "%hu", ++j); WMDrawString(rPtr->view->screen, rPtr->drawBuffer, rPtr->fg, rPtr->font, rPtr->margins.left + 2 + m, 26, c, 2); } m = (++i) * 10; } The printf modifier should be unsigned int. Signed-off-by: Rodolfo García Peñas (kix) --- WINGs/wruler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WINGs/wruler.c b/WINGs/wruler.c index f1ff8626..541b4a68 100644 --- a/WINGs/wruler.c +++ b/WINGs/wruler.c @@ -181,7 +181,7 @@ static void drawRulerOnPixmap(Ruler * rPtr) XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer, rPtr->fgGC, rPtr->margins.left + m, 23, rPtr->margins.left + m, marks[i % 8] + 23); if (i != 0 && i % 8 == 0) { - snprintf(c, sizeof(c), "%d", ++j); + snprintf(c, sizeof(c), "%hu", ++j); WMDrawString(rPtr->view->screen, rPtr->drawBuffer, rPtr->fg, rPtr->font, rPtr->margins.left + 2 + m, 26, c, 2); }