From 5eb85a7a5ef1b6e96ebcb2fac20f6ca2286026c8 Mon Sep 17 00:00:00 2001 From: Alexey Tourbin Date: Wed, 31 Jan 2018 01:52:43 +0300 Subject: [PATCH] signature.c: change file size fmt %d -> %zu Some of the preceding code is probably undefined or unspecified behavior, but there's no easy way to fix it other than rewriting, which I'm not going to do. Surprisingly enough, the code just happens to work, due to a series of mutual cancellations mod 2^32. As they say in Russian, the war will write off all. Likewise, mod 2^32 arithmetic can write off a multitude of sins (James 5:20). > static inline rpmRC checkSize(FD_t fd, int siglen, int pad, int datalen) [...] > int delta; [...] > delta = (sizeof(struct rpmlead) + siglen + pad + datalen) - st.st_size; Here, the expression in parentheses yields a different numeric value depending on whether datalen is signed or unsigned. However, when delta is finally truncated to 32 bits, the result turns out to be the same. > switch (delta) { > case -32: /* XXX rpm-4.0 packages */ > case 32: /* XXX Legacy headers have a HEADER_IMAGE tag added. */ > case 0: --- lib/signature.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/signature.c b/lib/signature.c index 9afe6f8..b1357b7 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -137,11 +137,11 @@ static inline rpmRC checkSize(FD_t fd, int siglen, int pad, int datalen) } rpmMessage((rc == RPMRC_OK ? RPMMESS_DEBUG : RPMMESS_WARNING), - _("Expected size: %12d = lead(%d)+sigs(%d)+pad(%d)+data(%d)\n"), - (int)sizeof(struct rpmlead)+siglen+pad+datalen, - (int)sizeof(struct rpmlead), siglen, pad, datalen); + _("Expected size: %12zu = lead(%zu)+sigs(%d)+pad(%d)+data(%u)\n"), + sizeof(struct rpmlead)+siglen+pad+datalen, + sizeof(struct rpmlead), siglen, pad, (unsigned)datalen); rpmMessage((rc == RPMRC_OK ? RPMMESS_DEBUG : RPMMESS_WARNING), - _(" Actual size: %12d\n"), (int)st.st_size); + _(" Actual size: %12zu\n"), (size_t)st.st_size); return rc; }