]> granicus.if.org Git - graphviz/commitdiff
cgraph storeFileName: squash warnings when dealing with buffer lengths
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 16 Oct 2022 03:46:03 +0000 (20:46 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 19 Oct 2022 14:44:37 +0000 (07:44 -0700)
This removes the following compiler warnings which were particularly problematic
as they were pointing to the wrong source lines. It is unclear whether this is
due to a Flex bug or the way we are calling Flex.

  ../../lib/cgraph/scan.l: In function ‘storeFileName’:
  ../../lib/cgraph/scan.l:98:28: warning: conversion to ‘size_t’ {aka ‘long
    unsigned int’} from ‘int’ may change the sign of the result
    [-Wsign-conversion]
     98 |     static char* buf;
        |                            ^
  ../../lib/cgraph/scan.l:98:37: warning: conversion to ‘size_t’ {aka ‘long
    unsigned int’} from ‘int’ may change the sign of the result
    [-Wsign-conversion]
     98 |     static char* buf;
        |                                     ^
  ../../lib/cgraph/scan.l: In function ‘ppDirective’:
  ../../lib/cgraph/scan.l:125:29: warning: conversion from ‘long int’ to ‘int’
    may change value [-Wconversion]
    125 |             while (*e && *e != '"') e++;
        |                            ~^~

lib/cgraph/scan.l

index 32c394befb35148a031925ac53e6a041f991b6de..ee8e60f0c7f1a4d5f66ab413052dd0e97645d147 100644 (file)
@@ -91,10 +91,8 @@ static void endstr_html(void) {
   aaglval.str = agstrdup_html(Ag_G_global, agxbuse(&Sbuf));
 }
 
-static void
-storeFileName (char* fname, int len)
-{
-    static int cnt;
+static void storeFileName(char* fname, size_t len) {
+    static size_t cnt;
     static char* buf;
 
     if (len > cnt) {
@@ -125,7 +123,7 @@ static void ppDirective (void)
            while (*e && *e != '"') e++;
            if (e != p && *e == '"') {
                *e = '\0';
-               storeFileName (p, e-p);
+               storeFileName(p, (size_t)(e - p));
            }
        }
     }