gvc: use 'int' when converting SVG units
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 11 Nov 2022 03:39:48 +0000 (19:39 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 11 Nov 2022 03:39:48 +0000 (19:39 -0800)
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

index 28d292682d41a19d6db1306402e24cf3f1608c54..4106a42d6daa71a4a2266a336a43debc69659f02 100644 (file)
@@ -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;