From 2ba71c805833c51d9490b3c8cf3bc43b7ad28ecd Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Wed, 2 Nov 2022 21:37:56 -0700 Subject: [PATCH] cdt: squash -Wconversion warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- lib/cdt/dtstrhash.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; -- 2.50.1