]> granicus.if.org Git - graphviz/commitdiff
cdt: squash -Wconversion warning
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 3 Nov 2022 04:41:33 +0000 (21:41 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 4 Nov 2022 04:18:04 +0000 (21:18 -0700)
This squashes the warning:

  dtstrhash.c: In function ‘dtstrhash’:
  dtstrhash.c:36:18: warning: conversion to ‘unsigned int’ from ‘int’ may change
    the sign of the result [-Wsign-conversion]
     36 |         return (h+n)*DT_PRIME;
        |                  ^

`n` is guaranteed non-negative by the logic preceding this.

lib/cdt/dtstrhash.c

index 39f7089e4bf518e17caaa5a8f13baba2aff4455c..2b65b11b9bbcf0affe385c0e228bfdb77550c2da 100644 (file)
@@ -33,5 +33,6 @@ uint dtstrhash(uint h, void* args, int n)
                if(s <= ends)
                        h = (h + ((unsigned)s[0] << 8u)) * DT_PRIME;
        }
-       return (h+n)*DT_PRIME;
+       assert(n >= 0);
+       return (h + (unsigned)n) * DT_PRIME;
 }