Skip to content

Clean up some warnings#4950

Merged
ethomson merged 20 commits intomasterfrom
ethomson/warnings
Jan 26, 2019
Merged

Clean up some warnings#4950
ethomson merged 20 commits intomasterfrom
ethomson/warnings

Conversation

@ethomson
Copy link
Member

@ethomson ethomson commented Jan 20, 2019

This cleans up some warnings encountered building on Win32 with MSVC. This PR attacks all the x86 warnings. (Some remain on amd64.)

git_index_entry entry;

if (!git__is_sizet(size)) {
giterr_set(GITERR_NOMEMORY, "file size overflow (for 32-bits) on '%s'", path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I'd say that this error message sucks. But you're just going with what we had previously, so I'm okay to stick with it


error = git_stream_write(s->io, request.ptr, request.size, 0);
write_size = min(request.size, INT_MAX);
error = (int)git_stream_write(s->io, request.ptr, write_size, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, right? We silently drop everything that's after the first INT_MAX bytes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

int abbreviated_size)
unsigned int abbreviated_size)
{
size_t size = abbreviated_size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One might wonder whether this is the right thing to do. Previously, passing -1 was underflowing to a huge size, essentially saying "Do not abbreviate but print all digits". But the only callsite show_suffix gets called with git_describe_format_options.abbreviated_size, which is an unsigned int itself.

Quiet down a warning from MSVC about how we're potentially losing data.
Quiet down a warning from MSVC about how we're potentially losing data.
This cast is safe since we've explicitly tested that `strip_len` <=
`last_len`.
Quiet down a warning from MSVC about how we're potentially losing data.
This is safe since we've explicitly tested that it's within the range of
0-100.
Quiet down a warning from MSVC about how we're potentially losing data.
This is safe since we've explicitly tested that it's positive and less
than SIZE_MAX.
Quiet down a warning from MSVC about how we're potentially losing data.
Ensure that we're within a uint16_t before we do.
Our blob size is a `git_off_t`, which is a signed 64 bit int.  This may
be erroneously negative or larger than `SIZE_MAX`.  Ensure that the blob
size fits into a `size_t` before casting.
The filesystem iterator takes `stat` data from disk and puts them into
index entries, which use 32 bit ints for time (the seconds portion) and
filesize.  However, on most systems these are not 32 bit, thus will
typically invoke a warning.

Most users ignore these fields entirely.  Diff and checkout code do use
the values, however only for the cache to determine if they should check
file modification.  Thus, this is not a critical error (and will cause a
hash recomputation at worst).
Cast actual filesystem data to the int32_t that index entries store.
A number of source files have their implementation #ifdef'd out (because
they target another platform).  MSVC warns on empty compilation units
(with warning LNK4221).  Ignore warning 4221 when creating the object
library.
Quiet down a warning from MSVC about how we're potentially losing data.
This is safe since we've explicitly tested it.
Our streams implementation takes a `size_t` that indicates the length of
the data buffer to be written, and returns an `ssize_t` that indicates
the length that _was_ written.  Clearly no such implementation can write
more than `SSIZE_MAX` bytes.  Ensure that each TLS stream implementation
does not try to write more than `SSIZE_MAX` bytes (or smaller; if the
given implementation takes a smaller size).
Windows doesn't include ssize_t or its _MAX value by default.  We are
already declaring ssize_t as SSIZE_T, which is __int64_t on Win64 and
long otherwise.  Include its _MAX value as a correspondence to its type.
The transport code returns an `int` with the number of bytes written;
thus only attempt to write at most `INT_MAX`.
Quiet down a warning from MSVC about how we're potentially losing data.
Validate that our data will fit into the type provided then cast.
The git_describe_format_options.abbreviated_size type is an unsigned
int.  There's no need for it to be anything else; keep it what it is.
Index entries are 32 bit unsigned ints, not `size_t`s.
Validate that the return value of the read is not less than INT_MAX,
then cast.
@ethomson
Copy link
Member Author

OK, fixed up but I'll wait for #4953 to land.

@ethomson ethomson changed the title WIP: clean up some warnings Clean up some warnings Jan 25, 2019
@ethomson
Copy link
Member Author

On second thought, it's only the SSIZE_MAX, so that's a pretty trivial conflict. I want to look at the amd64 warnings, so 🚢

@ethomson ethomson merged commit b1e2862 into master Jan 26, 2019
@ethomson ethomson deleted the ethomson/warnings branch January 27, 2019 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants