]> git.ipfire.org Git - thirdparty/git.git/commit
pkt-line: fix -Wsign-compare warning on 32 bit platform
authorPatrick Steinhardt <ps@pks.im>
Fri, 6 Dec 2024 10:27:23 +0000 (11:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Dec 2024 11:20:03 +0000 (20:20 +0900)
commit25435e4ad87aa484ce0d9d2adf3aa407f0241704
tree409e01b59503d135bd25b772561f39ba376962c4
parentba8f6018b5bed4fc58f8dfe2f9714d22398b06fe
pkt-line: fix -Wsign-compare warning on 32 bit platform

Similar to the preceding commit, we get a warning in `get_packet_data()`
on 32 bit platforms due to our lenient use of `ssize_t`. This function
is kind of curious though: we accept an `unsigned size` of bytes to
read, then store the actual number of bytes read in an `ssize_t` and
return it as an `int`. This is a whole lot of integer conversions, and
in theory these can cause us to overflow when the passed-in size is
larger than `ssize_t`, which on 32 bit platforms is implemented as an
`int`.

None of the callers of that function even care about the number of bytes
we have read, so returning that number is moot anyway. Refactor the
function such that it only returns an error code, which plugs the
potential overflow. While at it, convert the passed-in size parameter to
be of type `size_t`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pkt-line.c