]> granicus.if.org Git - zziplib/commit
zzip: string: fix comparison with different signs
authorPatrick Steinhardt <ps@pks.im>
Tue, 21 May 2019 11:10:22 +0000 (13:10 +0200)
committerPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2019 06:33:34 +0000 (08:33 +0200)
commit0ef64059b1aecee0c670d3925a101da89be20a13
treea34d2367540ae7d2cf9a66df53cd10c49a2ecf62
parent102052089a94da95d7c8039f5cf030869aeba439
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.
zzip/__string.h