]> granicus.if.org Git - graphviz/commitdiff
cdt: make intent to coerce to unsigned clearer in 'dtstrhash'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 3 Nov 2022 04:25:47 +0000 (21:25 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 4 Nov 2022 04:18:04 +0000 (21:18 -0700)
This squashes some compiler warnings on CentOS 7:

  dtstrhash.c: In function 'dtstrhash':
  dtstrhash.c:22:18: warning: conversion to 'unsigned int' from 'int' may change
    the sign of the result [-Wsign-conversion]
      h = (h + (s[0]<<8) + s[1])*DT_PRIME;
                    ^
  dtstrhash.c:28:18: warning: conversion to 'unsigned int' from 'int' may change
    the sign of the result [-Wsign-conversion]
      h = (h + (s[0]<<8) + s[1])*DT_PRIME;
                    ^
  dtstrhash.c:30:18: warning: conversion to 'unsigned int' from 'int' may change
    the sign of the result [-Wsign-conversion]
      h = (h + (s[0]<<8))*DT_PRIME;

lib/cdt/dtstrhash.c

index f003940385f4456ca014078a743ef08ba0c87a24..41c99d3dbe616b4988b0382523a849948ba7ed73 100644 (file)
@@ -19,15 +19,15 @@ uint dtstrhash(uint h, void* args, int n)
 
        if(n <= 0)
        {       for(; *s != 0; s += s[1] ? 2 : 1)
-                       h = (h + (s[0]<<8) + s[1])*DT_PRIME;
+                       h = (h + ((unsigned)s[0] << 8u) + (unsigned)s[1]) * DT_PRIME;
                n = s - (unsigned char*)args;
        }
        else
        {       unsigned char*  ends;
                for(ends = s+n-1; s < ends; s += 2)
-                       h = (h + (s[0]<<8) + s[1])*DT_PRIME;
+                       h = (h + ((unsigned)s[0] << 8u) + (unsigned)s[1]) * DT_PRIME;
                if(s <= ends)
-                       h = (h + (s[0]<<8))*DT_PRIME;
+                       h = (h + ((unsigned)s[0] << 8u)) * DT_PRIME;
        }
        return (h+n)*DT_PRIME;
 }