From: Matthew Fernandez Date: Thu, 3 Nov 2022 04:25:47 +0000 (-0700) Subject: cdt: make intent to coerce to unsigned clearer in 'dtstrhash' X-Git-Tag: 7.0.1~4^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f938136270a4bf89d4871bcff675e319e48a9b5;p=graphviz cdt: make intent to coerce to unsigned clearer in 'dtstrhash' 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; --- diff --git a/lib/cdt/dtstrhash.c b/lib/cdt/dtstrhash.c index f00394038..41c99d3db 100644 --- a/lib/cdt/dtstrhash.c +++ b/lib/cdt/dtstrhash.c @@ -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; }