From: Patrick Steinhardt Date: Tue, 21 May 2019 11:10:22 +0000 (+0200) Subject: zzip: string: fix comparison with different signs X-Git-Tag: v0.13.70~2^2~11^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ef64059b1aecee0c670d3925a101da89be20a13;p=zziplib zzip: string: fix comparison with different signs When subtracting two pointers, the result is signed as the subtrahend may point at a position after the minuend, in which case it is bigger and the result would be negative. This causes a warning in `_zzip_strnlen`, which is supposed to return an unsigned `size_t`. As the minuend is computed by using `memchr` on the subtrahend, we know that it is always either `NULL` or bigger than the subtrahend. And due to the subtraction only being performed when it is non-`NULL`, we may simply cast the result to `size_t` to fix the issue, fixing the warning. --- diff --git a/zzip/__string.h b/zzip/__string.h index 4424348..e62fb06 100644 --- a/zzip/__string.h +++ b/zzip/__string.h @@ -23,7 +23,7 @@ static size_t _zzip_strnlen(const char *p, size_t maxlen) { const char * stop = (char *)memchr(p, '\0', maxlen); - return stop ? stop - p : maxlen; + return stop ? (size_t)(stop - p) : maxlen; } #endif