From 7776db51bbc0256b994f4b4037213938af6c4d73 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 3 May 2017 12:15:12 +0200 Subject: [PATCH 1/5] odb: shut up gcc warnings regarding uninitilized variables 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. --- src/odb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/odb.c b/src/odb.c index 3090ccaac..f28152bff 100644 --- a/src/odb.c +++ b/src/odb.c @@ -1002,7 +1002,7 @@ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id, git_odb_object *object; git_oid hashed; bool found = false; - int error; + int error = 0; if (!only_refreshed && odb_read_hardcoded(&raw, id) == 0) found = true; @@ -1099,7 +1099,7 @@ static int read_prefix_1(git_odb_object **out, git_odb *db, const git_oid *key, size_t len, bool only_refreshed) { size_t i; - int error; + int error = 0; git_oid found_full_oid = {{0}}; git_rawobj raw = {0}; void *data = NULL; From f0ca00e013885479228c4f076989566a2b77221b Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 3 May 2017 12:25:48 +0200 Subject: [PATCH 2/5] examples: network: refactor credentials callback 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. --- examples/network/common.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/network/common.c b/examples/network/common.c index d123eedbd..1a81a10f8 100644 --- a/examples/network/common.c +++ b/examples/network/common.c @@ -1,5 +1,7 @@ #include "common.h" #include +#include +#include /* Shamelessly borrowed from http://stackoverflow.com/questions/3417837/ * with permission of the original author, Martin Pool. @@ -20,15 +22,27 @@ int cred_acquire_cb(git_cred **out, unsigned int UNUSED(allowed_types), void * UNUSED(payload)) { - char username[128] = {0}; - char password[128] = {0}; + char *username = NULL, *password = NULL; + int error; printf("Username: "); - scanf("%s", username); + if (getline(&username, NULL, stdin) < 0) { + fprintf(stderr, "Unable to read username: %s", strerror(errno)); + return -1; + } /* Yup. Right there on your terminal. Careful where you copy/paste output. */ printf("Password: "); - scanf("%s", password); + if (getline(&password, NULL, stdin) < 0) { + fprintf(stderr, "Unable to read password: %s", strerror(errno)); + free(username); + return -1; + } - return git_cred_userpass_plaintext_new(out, username, password); + error = git_cred_userpass_plaintext_new(out, username, password); + + free(username); + free(password); + + return error; } From 8d93a11cffa8199d212124401fdca64b5ae3bacc Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 3 May 2017 12:38:55 +0200 Subject: [PATCH 3/5] odb: fix printf formatter for git_off_t 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. --- src/odb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/odb.c b/src/odb.c index f28152bff..b66324f87 100644 --- a/src/odb.c +++ b/src/odb.c @@ -1326,9 +1326,9 @@ static int git_odb_stream__invalid_length( { giterr_set(GITERR_ODB, "cannot %s - " - "Invalid length. %"PRIuZ" was expected. The " - "total size of the received chunks amounts to %"PRIuZ".", - action, stream->declared_size, stream->received_bytes); + "Invalid length. %"PRIdZ" was expected. The " + "total size of the received chunks amounts to %"PRIdZ".", + action, stream->declared_size, stream->received_bytes); return -1; } From 7d7f6d332c4011f1e7963958ea09a8cd59178685 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 3 May 2017 13:52:55 +0200 Subject: [PATCH 4/5] tests: clone::local: compile UNC functions for Windows only --- tests/clone/local.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/clone/local.c b/tests/clone/local.c index 91a0a1c2a..7f54d05de 100644 --- a/tests/clone/local.c +++ b/tests/clone/local.c @@ -16,6 +16,7 @@ static int file_url(git_buf *buf, const char *host, const char *path) return git_buf_printf(buf, "file://%s/%s", host, path); } +#ifdef GIT_WIN32 static int git_style_unc_path(git_buf *buf, const char *host, const char *path) { git_buf_clear(buf); @@ -49,6 +50,7 @@ static int unc_path(git_buf *buf, const char *host, const char *path) return 0; } +#endif void test_clone_local__should_clone_local(void) { From 98a5f081c52ab3d85b98a522dec3a95f80f29eda Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 3 May 2017 13:53:13 +0200 Subject: [PATCH 5/5] tests: threads::basic: remove unused function `exit_abruptly` --- tests/threads/basic.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/threads/basic.c b/tests/threads/basic.c index a9310bbd4..af6049090 100644 --- a/tests/threads/basic.c +++ b/tests/threads/basic.c @@ -54,12 +54,6 @@ static void *return_normally(void *param) { return param; } - -static void *exit_abruptly(void *param) -{ - git_thread_exit(param); - return NULL; -} #endif void test_threads_basic__exit(void)