From: Matthew Fernandez Date: Thu, 3 Nov 2022 04:37:56 +0000 (-0700) Subject: cdt: squash -Wconversion warning X-Git-Tag: 7.0.1~4^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ba71c805833c51d9490b3c8cf3bc43b7ad28ecd;p=graphviz cdt: squash -Wconversion warning This squashes the warning: dtstrhash.c:23:21: warning: conversion from ‘long int’ to ‘int’ may change value [-Wconversion] 23 | n = s - (unsigned char*)args; | ^ This cast is mostly guaranteed safe by the inability to practically pass a >INT_MAX length string into this function. --- diff --git a/lib/cdt/dtstrhash.c b/lib/cdt/dtstrhash.c index 41c99d3db..39f7089e4 100644 --- a/lib/cdt/dtstrhash.c +++ b/lib/cdt/dtstrhash.c @@ -1,4 +1,7 @@ +#include #include +#include +#include /* Hashing a string into an unsigned integer. ** The basic method is to continuingly accumulate bytes and multiply @@ -20,7 +23,8 @@ uint dtstrhash(uint h, void* args, int n) if(n <= 0) { for(; *s != 0; s += s[1] ? 2 : 1) h = (h + ((unsigned)s[0] << 8u) + (unsigned)s[1]) * DT_PRIME; - n = s - (unsigned char*)args; + assert(strlen(args) <= INT_MAX); + n = (int)(s - (unsigned char*)args); } else { unsigned char* ends;