Skip to content

Commit 924f5d1

Browse files
authored
Merge pull request libgit2#4240 from pks-t/pks/fix-gcc-warnings
Fix GCC warnings
2 parents 87f5fba + 98a5f08 commit 924f5d1

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

examples/network/common.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "common.h"
22
#include <stdio.h>
3+
#include <string.h>
4+
#include <errno.h>
35

46
/* Shamelessly borrowed from http://stackoverflow.com/questions/3417837/
57
* with permission of the original author, Martin Pool.
@@ -20,15 +22,27 @@ int cred_acquire_cb(git_cred **out,
2022
unsigned int UNUSED(allowed_types),
2123
void * UNUSED(payload))
2224
{
23-
char username[128] = {0};
24-
char password[128] = {0};
25+
char *username = NULL, *password = NULL;
26+
int error;
2527

2628
printf("Username: ");
27-
scanf("%s", username);
29+
if (getline(&username, NULL, stdin) < 0) {
30+
fprintf(stderr, "Unable to read username: %s", strerror(errno));
31+
return -1;
32+
}
2833

2934
/* Yup. Right there on your terminal. Careful where you copy/paste output. */
3035
printf("Password: ");
31-
scanf("%s", password);
36+
if (getline(&password, NULL, stdin) < 0) {
37+
fprintf(stderr, "Unable to read password: %s", strerror(errno));
38+
free(username);
39+
return -1;
40+
}
3241

33-
return git_cred_userpass_plaintext_new(out, username, password);
42+
error = git_cred_userpass_plaintext_new(out, username, password);
43+
44+
free(username);
45+
free(password);
46+
47+
return error;
3448
}

src/odb.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id,
10021002
git_odb_object *object;
10031003
git_oid hashed;
10041004
bool found = false;
1005-
int error;
1005+
int error = 0;
10061006

10071007
if (!only_refreshed && odb_read_hardcoded(&raw, id) == 0)
10081008
found = true;
@@ -1099,7 +1099,7 @@ static int read_prefix_1(git_odb_object **out, git_odb *db,
10991099
const git_oid *key, size_t len, bool only_refreshed)
11001100
{
11011101
size_t i;
1102-
int error;
1102+
int error = 0;
11031103
git_oid found_full_oid = {{0}};
11041104
git_rawobj raw = {0};
11051105
void *data = NULL;
@@ -1326,9 +1326,9 @@ static int git_odb_stream__invalid_length(
13261326
{
13271327
giterr_set(GITERR_ODB,
13281328
"cannot %s - "
1329-
"Invalid length. %"PRIuZ" was expected. The "
1330-
"total size of the received chunks amounts to %"PRIuZ".",
1331-
action, stream->declared_size, stream->received_bytes);
1329+
"Invalid length. %"PRIdZ" was expected. The "
1330+
"total size of the received chunks amounts to %"PRIdZ".",
1331+
action, stream->declared_size, stream->received_bytes);
13321332

13331333
return -1;
13341334
}

tests/clone/local.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static int file_url(git_buf *buf, const char *host, const char *path)
1616
return git_buf_printf(buf, "file://%s/%s", host, path);
1717
}
1818

19+
#ifdef GIT_WIN32
1920
static int git_style_unc_path(git_buf *buf, const char *host, const char *path)
2021
{
2122
git_buf_clear(buf);
@@ -49,6 +50,7 @@ static int unc_path(git_buf *buf, const char *host, const char *path)
4950

5051
return 0;
5152
}
53+
#endif
5254

5355
void test_clone_local__should_clone_local(void)
5456
{

tests/threads/basic.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ static void *return_normally(void *param)
5454
{
5555
return param;
5656
}
57-
58-
static void *exit_abruptly(void *param)
59-
{
60-
git_thread_exit(param);
61-
return NULL;
62-
}
6357
#endif
6458

6559
void test_threads_basic__exit(void)

0 commit comments

Comments
 (0)