freebsd-dev/usr.bin/gzip
Pedro F. Giffuni 3fcbc83d04 gzip: fix for undefined behavior.
Unportable left shift reported with MKSANITIZER=yes
USE_SANITIZER=undefined:

# progress -zf ./games.tgz  tar -xp -C "./" -f -
/public/src.git/usr.bin/gzip/gzip.c:2126:33: runtime error: left shift of
251 by 24 places cannot be represented in type 'int'
100%
|****************************************************************************************************************|
44500 KiB  119.69 MiB/s    00:00 ETA

Refactor the following code into something that is more clear
and fix signed integer shift, by casting all buf[] elements to
(unsigned int):

unsigned char buf[8];
uint32_t usize;
[...]
else {
    usize = buf[4] | buf[5] << 8 |
            buf[6] << 16 | buf[7] << 24;
[...]

New version:

    usize = buf[4];
    usize |= (unsigned int)buf[5] << 8;
    usize |= (unsigned int)buf[6] << 16;
    usize |= (unsigned int)buf[7] << 24;

Only the "<< 24" part needs explicit cast, but for consistency make the
integer promotion explicit and clear to a code reader.

Sponsored by <The NetBSD Foundation>

Obtained from:	NetBSD (CVS rev. 1.113)
MFC after:	1 week
2018-07-08 22:39:33 +00:00
..
tests Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installed 2016-05-04 23:20:53 +00:00
gzexe
gzexe.1
gzip.1 Support SIGINFO. 2017-11-21 08:14:30 +00:00
gzip.c gzip: fix for undefined behavior. 2018-07-08 22:39:33 +00:00
Makefile Create links for xzdiff. 2017-12-05 07:01:10 +00:00
Makefile.depend DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
unbzip2.c various: general adoption of SPDX licensing ID tags. 2017-11-27 15:37:16 +00:00
unpack.c Remove "All rights reserved" from my files. 2018-05-10 06:41:08 +00:00
unxz.c various: general adoption of SPDX licensing ID tags. 2017-11-27 15:37:16 +00:00
zdiff
zdiff.1
zforce
zforce.1
zmore Sync with NetBSD. 2014-10-23 01:22:29 +00:00
zmore.1 Sync with NetBSD. 2014-10-23 01:22:29 +00:00
znew
znew.1
zuncompress.c Set errno to EFTYPE instead of EINVAL to be more consistent with the 2017-11-25 09:03:38 +00:00