Skip to content

Fix GCC warnings#4240

Merged
carlosmn merged 5 commits into
libgit2:masterfrom
pks-t:pks/fix-gcc-warnings
May 16, 2017
Merged

Fix GCC warnings#4240
carlosmn merged 5 commits into
libgit2:masterfrom
pks-t:pks/fix-gcc-warnings

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented May 15, 2017

This is split out from #4211. With this, we're free of compiler warnings on Ubuntu Trusty images, which will allow us to selectively enable "-Werror" in the future.

pks-t added 5 commits May 15, 2017 07:34
The `error` variable is used as a return value in the out-section of
both `odb_read_1` and `read_prefix_1`. While the value will actually
always be initialized inside of this section, GCC fails to realize this
due to interactions with the `found` variable: if `found` is set, the
error will always be initialized. If it is not, we return early without
reaching the out-statements.

Shut up the warnings by initializing the error variable, even though it
is unnecessary.
The credentials callback reads the username and password via scanf into
fixed-length arrays. While these are simply examples and as such not as
interesting, the unchecked return value of scanf causes GCC to emit
warnings. So while we're busy to shut up GCC, we also fix the possible
overflow of scanf by using getline instead.
The fields `declared_size` and `received_bytes` of the `git_odb_stream`
are both of type `git_off_t` which is defined as a signed integer. When
passing these values to a printf-style string in
`git_odb_stream__invalid_length`, though, we format these as PRIuZ,
which is unsigned.

Fix the issue by using PRIdZ instead, silencing warnings on macOS.
@carlosmn carlosmn merged commit 924f5d1 into libgit2:master May 16, 2017
Comment thread examples/network/common.c

printf("Username: ");
scanf("%s", username);
if (getline(&username, NULL, stdin) < 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

According to my manpage, "This buffer should be freed by the user program even if getline() failed", not that it's a big deal in this case.

@pks-t pks-t deleted the pks/fix-gcc-warnings branch May 17, 2017 07:03
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