The revert of zlib.h r1.7 led to one or two compiler warnings in
ctfdump, depending on the architecture:

/usr/src/usr.bin/ctfdump/ctfdump.c:704:7: warning: format specifies type 
'unsigned long long' but the argument has type 'uLong' (aka 'unsigned long') 
[-Wformat]
                    stream.total_out, len);
                    ^~~~~~~~~~~~~~~~

This one has an obvious fix. The format specifier for len is also wrong,
but -Wformat doesn't care.

/usr/src/usr.bin/ctfdump/ctfdump.c:702:23: warning: comparison of integers of 
different signs: 'uLong' (aka 'unsigned long') and 'off_t' (aka 'long long') 
[-Wsign-compare]
        if (stream.total_out != len) {
            ~~~~~~~~~~~~~~~~ ^  ~~~

This one a bit less so.

z_off_t (aka 'long long') was changed to uLong (aka 'unsigned long'), so
it changed from signed to unsigned.

uLong will have to be converted to off_t due to the integer conversion
rank of 'long long' being higher than the one of long. This conversion
is possible on our ILP32 architectures. On our LP64 architectures, the
conversion of values > LONG_MAX is a priori implementation-defined.

So I think the correct fix is to cast them both to an unsigned type
wider than both of them. I chose uintmax_t since that cast is already
used in this file. The len < 0 check is only there for stylistic
reasons. As a sum of two uint32_t, len can't be < 0.

A similar fix will be needed in db_ctf_decompress() in sys/ddb/db_ctf.c
once we revert zlib.h r1.7 in the kernel.

Index: ctfdump.c
===================================================================
RCS file: /cvs/src/usr.bin/ctfdump/ctfdump.c,v
retrieving revision 1.25
diff -u -p -r1.25 ctfdump.c
--- ctfdump.c   10 Feb 2022 23:40:09 -0000      1.25
+++ ctfdump.c   9 Aug 2022 17:55:43 -0000
@@ -699,8 +699,8 @@ decompress(const char *buf, size_t size,
                goto exit;
        }
 
-       if (stream.total_out != len) {
-               warnx("decompression failed: %llu != %llu",
+       if (len < 0 || (uintmax_t)stream.total_out != (uintmax_t)len) {
+               warnx("decompression failed: %lu != %lld",
                    stream.total_out, len);
                goto exit;
        }

Reply via email to