From 020126f9f295dfcb7a6b0ad86f4b0b687a26d02b Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 10 Nov 2022 19:39:48 -0800 Subject: [PATCH] gvc: use 'int' when converting SVG units MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit These values are eventually stored in `int` fields, so going through `unsigned int` is unproductive. This squashes a number of warnings: In file included from ../../lib/common/geom.h:19, from ../../lib/common/types.h:37, from gvusershape.c:28: gvusershape.c: In function ‘svg_units_convert’: ../../lib/common/arith.h:59:46: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion] 59 | #define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5)) | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ gvusershape.c:149:16: note: in expansion of macro ‘ROUND’ 149 | return ROUND(n * POINTS_PER_INCH); | ^~~~~ ../../lib/common/arith.h:59:46: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion] 59 | #define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5)) | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ gvusershape.c:151:16: note: in expansion of macro ‘ROUND’ 151 | return ROUND(n * POINTS_PER_INCH / 96); | ^~~~~ ../../lib/common/arith.h:59:46: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion] 59 | #define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5)) | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ gvusershape.c:153:16: note: in expansion of macro ‘ROUND’ 153 | return ROUND(n * POINTS_PER_INCH / 6); | ^~~~~ ../../lib/common/arith.h:59:46: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion] 59 | #define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5)) | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ gvusershape.c:155:16: note: in expansion of macro ‘ROUND’ 155 | return ROUND(n); | ^~~~~ ../../lib/common/arith.h:59:46: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion] 59 | #define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5)) | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ gvusershape.c:157:16: note: in expansion of macro ‘ROUND’ 157 | return ROUND(n * POINTS_PER_CM); | ^~~~~ ../../lib/common/arith.h:59:46: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion] 59 | #define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5)) | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ gvusershape.c:159:16: note: in expansion of macro ‘ROUND’ 159 | return ROUND(n * POINTS_PER_MM); | ^~~~~ gvusershape.c:261:13: warning: conversion to ‘int’ from ‘unsigned int’ may change the sign of the result [-Wsign-conversion] 261 | us->w = w; | ^ gvusershape.c:262:13: warning: conversion to ‘int’ from ‘unsigned int’ may change the sign of the result [-Wsign-conversion] 262 | us->h = h; | ^ --- lib/gvc/gvusershape.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/gvc/gvusershape.c b/lib/gvc/gvusershape.c index 28d292682..4106a42d6 100644 --- a/lib/gvc/gvusershape.c +++ b/lib/gvc/gvusershape.c @@ -143,8 +143,7 @@ static bool get_int_msb_first(FILE *f, size_t sz, unsigned int *val) { return true; } -static unsigned int svg_units_convert(double n, char *u) -{ +static int svg_units_convert(double n, char *u) { if (strcmp(u, "in") == 0) return ROUND(n * POINTS_PER_INCH); if (strcmp(u, "px") == 0) @@ -203,7 +202,7 @@ static int find_attribute(const char *s, match_t *result) { static void svg_size (usershape_t *us) { - unsigned int w = 0, h = 0; + int w = 0, h = 0; double n, x0, y0, x1, y1; char u[10]; char *attribute, *value, *re_string; -- 2.40.0