Skip to content

Commit 381991a

Browse files
authored
Merge pull request libgit2#5749 from lhchavez/gcc-10
Fix the `-DENABLE_WERROR=ON` build for gcc 10.2
2 parents f4b473f + 212ae9a commit 381991a

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

tests/clar/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static void
396396
fs_copy(const char *source, const char *_dest)
397397
{
398398
char *dbuf = NULL;
399-
const char *dest;
399+
const char *dest = NULL;
400400
struct stat source_st, dest_st;
401401

402402
cl_must_pass_(lstat(source, &source_st), "Failed to stat copy source");

tests/clar/sandbox.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <sys/syslimits.h>
33
#endif
44

5-
static char _clar_path[4096];
5+
static char _clar_path[4096 + 1];
66

77
static int
88
is_valid_tmp_path(const char *path)
@@ -39,7 +39,8 @@ find_tmp_path(char *buffer, size_t length)
3939
if (length >= PATH_MAX && realpath(env, buffer) != NULL)
4040
return 0;
4141
#endif
42-
strncpy(buffer, env, length);
42+
strncpy(buffer, env, length - 1);
43+
buffer[length - 1] = '\0';
4344
return 0;
4445
}
4546
}
@@ -50,7 +51,8 @@ find_tmp_path(char *buffer, size_t length)
5051
if (length >= PATH_MAX && realpath("/tmp", buffer) != NULL)
5152
return 0;
5253
#endif
53-
strncpy(buffer, "/tmp", length);
54+
strncpy(buffer, "/tmp", length - 1);
55+
buffer[length - 1] = '\0';
5456
return 0;
5557
}
5658

@@ -65,7 +67,8 @@ find_tmp_path(char *buffer, size_t length)
6567

6668
/* This system doesn't like us, try to use the current directory */
6769
if (is_valid_tmp_path(".")) {
68-
strncpy(buffer, ".", length);
70+
strncpy(buffer, ".", length - 1);
71+
buffer[length - 1] = '\0';
6972
return 0;
7073
}
7174

tests/clar_libgit2.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ const char* cl_git_fixture_url(const char *fixturename)
275275

276276
const char* cl_git_path_url(const char *path)
277277
{
278-
static char url[4096];
278+
static char url[4096 + 1];
279279

280280
const char *in_buf;
281281
git_buf path_buf = GIT_BUF_INIT;
@@ -311,9 +311,10 @@ const char* cl_git_path_url(const char *path)
311311
in_buf++;
312312
}
313313

314-
cl_assert(url_buf.size < 4096);
314+
cl_assert(url_buf.size < sizeof(url) - 1);
315315

316-
strncpy(url, git_buf_cstr(&url_buf), 4096);
316+
strncpy(url, git_buf_cstr(&url_buf), sizeof(url) - 1);
317+
url[sizeof(url) - 1] = '\0';
317318
git_buf_dispose(&url_buf);
318319
git_buf_dispose(&path_buf);
319320
return url;

0 commit comments

Comments
 (0)