]> granicus.if.org Git - graphviz/commitdiff
gvc: read LSB data as 'int' values
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 11 Nov 2022 03:59:02 +0000 (19:59 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 11 Nov 2022 03:59:02 +0000 (19:59 -0800)
Similar to the previous commit, these are dealt with as `int` internally, so
better to use `int` the whole way through. Note that this rejects values that do
not fit in an `int` which would silently overflow before. This squashes:

  gvusershape.c: In function ‘webp_size’:
  gvusershape.c:301:21: warning: conversion to ‘int’ from ‘unsigned int’ may
    change the sign of the result [-Wsign-conversion]
    301 |             us->w = w;
        |                     ^
  gvusershape.c:302:21: warning: conversion to ‘int’ from ‘unsigned int’ may
    change the sign of the result [-Wsign-conversion]
    302 |             us->h = h;
        |                     ^
  gvusershape.c:308:21: warning: conversion to ‘int’ from ‘unsigned int’ may
    change the sign of the result [-Wsign-conversion]
    308 |             us->w = w;
        |                     ^
  gvusershape.c:309:21: warning: conversion to ‘int’ from ‘unsigned int’ may
    change the sign of the result [-Wsign-conversion]
    309 |             us->h = h;
        |                     ^
  gvusershape.c: In function ‘gif_size’:
  gvusershape.c:321:17: warning: conversion to ‘int’ from ‘unsigned int’ may
    change the sign of the result [-Wsign-conversion]
    321 |         us->w = w;
        |                 ^
  gvusershape.c:322:17: warning: conversion to ‘int’ from ‘unsigned int’ may
    change the sign of the result [-Wsign-conversion]
    322 |         us->h = h;
        |                 ^
  gvusershape.c: In function ‘bmp_size’:
  gvusershape.c:335:17: warning: conversion to ‘int’ from ‘unsigned int’ may
    change the sign of the result [-Wsign-conversion]
    335 |         us->w = size_x_msw << 16 | size_x_lsw;
        |                 ^~~~~~~~~~
  gvusershape.c:336:17: warning: conversion to ‘int’ from ‘unsigned int’ may
    change the sign of the result [-Wsign-conversion]
    336 |         us->h = size_y_msw << 16 | size_y_lsw;
        |                 ^~~~~~~~~~

lib/gvc/gvusershape.c

index 3c7ce98f81c8861fe4e18f200f7162058071fa44..176015e95fa2417d5e54893fe331468d9b29deae 100644 (file)
@@ -116,16 +116,20 @@ static int imagetype (usershape_t *us)
     return FT_NULL;
 }
     
-static bool get_int_lsb_first(FILE *f, size_t sz, unsigned int *val) {
+static bool get_int_lsb_first(FILE *f, size_t sz, int *val) {
     int ch;
 
-    *val = 0;
+    unsigned value = 0;
     for (size_t i = 0; i < sz; i++) {
        ch = fgetc(f);
        if (feof(f))
            return false;
-       *val |= (unsigned)ch << 8 * i;
+       value |= (unsigned)ch << 8 * i;
+    }
+    if (value > INT_MAX) {
+       return false;
     }
+    *val = (int)value;
     return true;
 }
        
@@ -291,7 +295,7 @@ static void ico_size (usershape_t *us)
 
 static void webp_size (usershape_t *us)
 {
-    unsigned int w, h;
+    int w, h;
 
     us->dpi = 0;
     fseek(us->f, 15, SEEK_SET);
@@ -313,7 +317,7 @@ static void webp_size (usershape_t *us)
 
 static void gif_size (usershape_t *us)
 {
-    unsigned int w, h;
+    int w, h;
 
     us->dpi = 0;
     fseek(us->f, 6, SEEK_SET);
@@ -324,7 +328,7 @@ static void gif_size (usershape_t *us)
 }
 
 static void bmp_size (usershape_t *us) {
-    unsigned int size_x_msw, size_x_lsw, size_y_msw, size_y_lsw;
+    int size_x_msw, size_x_lsw, size_y_msw, size_y_lsw;
 
     us->dpi = 0;
     fseek (us->f, 16, SEEK_SET);