summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlosmn@github.com>2016-02-18 12:31:56 +0100
committerCarlos Martín Nieto <carlosmn@github.com>2016-02-18 12:31:56 +0100
commit5663d4f69124481fcfab2952b5207c7563568388 (patch)
tree4925a5c8de2f660f9bf70160aa61970b6ecf81eb
parent594a5d12d4b9ba3ea542722805ada1028bd1b646 (diff)
parent9ce0399c4dad5ff040f2219fa1dd7a4531766414 (diff)
downloadlibgit2-5663d4f69124481fcfab2952b5207c7563568388.tar.gz
Merge pull request #3613 from ethomson/fixups
Remove most of the silly warnings
-rw-r--r--src/index.c12
-rw-r--r--src/submodule.c4
-rw-r--r--src/transports/winhttp.c2
-rw-r--r--src/tree.c26
-rw-r--r--src/unix/posix.h4
-rw-r--r--src/win32/posix.h10
-rw-r--r--src/win32/posix_w32.c20
-rw-r--r--src/win32/w32_util.h55
-rw-r--r--src/win32/win32-compat.h7
-rw-r--r--tests/checkout/checkout_helpers.c2
-rw-r--r--tests/core/posix.c2
-rw-r--r--tests/diff/workdir.c4
-rw-r--r--tests/index/racy.c2
-rw-r--r--tests/merge/workdir/dirty.c8
-rw-r--r--tests/reset/hard.c2
-rw-r--r--tests/win32/longpath.c2
16 files changed, 114 insertions, 48 deletions
diff --git a/src/index.c b/src/index.c
index c5a1b071c..d0a0da2c5 100644
--- a/src/index.c
+++ b/src/index.c
@@ -603,14 +603,14 @@ const git_oid *git_index_checksum(git_index *index)
*/
static int compare_checksum(git_index *index)
{
- int fd, error;
+ int fd;
ssize_t bytes_read;
git_oid checksum = {{ 0 }};
if ((fd = p_open(index->index_file_path, O_RDONLY)) < 0)
return fd;
- if ((error = p_lseek(fd, -20, SEEK_END)) < 0) {
+ if (p_lseek(fd, -20, SEEK_END) < 0) {
p_close(fd);
giterr_set(GITERR_OS, "failed to seek to end of file");
return -1;
@@ -826,8 +826,8 @@ const git_index_entry *git_index_get_bypath(
void git_index_entry__init_from_stat(
git_index_entry *entry, struct stat *st, bool trust_mode)
{
- entry->ctime.seconds = (git_time_t)st->st_ctime;
- entry->mtime.seconds = (git_time_t)st->st_mtime;
+ entry->ctime.seconds = (int32_t)st->st_ctime;
+ entry->mtime.seconds = (int32_t)st->st_mtime;
#if defined(GIT_USE_NSEC)
entry->mtime.nanoseconds = st->st_mtim.tv_nsec;
entry->ctime.nanoseconds = st->st_ctim.tv_nsec;
@@ -838,7 +838,7 @@ void git_index_entry__init_from_stat(
git_index__create_mode(0666) : git_index__create_mode(st->st_mode);
entry->uid = st->st_uid;
entry->gid = st->st_gid;
- entry->file_size = st->st_size;
+ entry->file_size = (uint32_t)st->st_size;
}
static void index_entry_adjust_namemask(
@@ -1529,7 +1529,7 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
return 0;
git_vector_size_hint(&index->entries, source_entries->length);
- git_idxmap_resize(index->entries_map, source_entries->length * 1.3);
+ git_idxmap_resize(index->entries_map, (khint_t)(source_entries->length * 1.3));
git_vector_foreach(source_entries, i, source_entry) {
git_index_entry *entry = NULL;
diff --git a/src/submodule.c b/src/submodule.c
index 3e55c5676..38db41529 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -778,9 +778,9 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
if ((error = git_commit_lookup(&head, sm_repo, &sm->wd_oid)) < 0)
goto cleanup;
- entry.ctime.seconds = git_commit_time(head);
+ entry.ctime.seconds = (int32_t)git_commit_time(head);
entry.ctime.nanoseconds = 0;
- entry.mtime.seconds = git_commit_time(head);
+ entry.mtime.seconds = (int32_t)git_commit_time(head);
entry.mtime.nanoseconds = 0;
git_commit_free(head);
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 3750f6e32..ded041686 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -283,7 +283,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS;
int default_timeout = TIMEOUT_INFINITE;
int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
- int i;
+ size_t i;
/* Prepare URL */
git_buf_printf(&buf, "%s%s", t->connection_data.path, s->service_url);
diff --git a/src/tree.c b/src/tree.c
index aab4b58ad..cfceb3f33 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -17,6 +17,9 @@
#define DEFAULT_TREE_SIZE 16
#define MAX_FILEMODE_BYTES 6
+#define TREE_ENTRY_CHECK_NAMELEN(n) \
+ if (n > UINT16_MAX) { giterr_set(GITERR_INVALID, "tree entry path too long"); }
+
GIT__USE_STRMAP
static bool valid_filemode(const int filemode)
@@ -89,10 +92,7 @@ static git_tree_entry *alloc_entry_base(git_pool *pool, const char *filename, si
git_tree_entry *entry = NULL;
size_t tree_len;
- if (filename_len > UINT16_MAX) {
- giterr_set(GITERR_INVALID, "tree entry is over UINT16_MAX in length");
- return NULL;
- }
+ TREE_ENTRY_CHECK_NAMELEN(filename_len);
if (GIT_ADD_SIZET_OVERFLOW(&tree_len, sizeof(git_tree_entry), filename_len) ||
GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, 1))
@@ -106,7 +106,7 @@ static git_tree_entry *alloc_entry_base(git_pool *pool, const char *filename, si
memset(entry, 0x0, sizeof(git_tree_entry));
memcpy(entry->filename, filename, filename_len);
entry->filename[filename_len] = 0;
- entry->filename_len = filename_len;
+ entry->filename_len = (uint16_t)filename_len;
return entry;
}
@@ -143,8 +143,8 @@ static int homing_search_cmp(const void *key, const void *array_member)
const struct tree_key_search *ksearch = key;
const git_tree_entry *entry = array_member;
- const size_t len1 = ksearch->filename_len;
- const size_t len2 = entry->filename_len;
+ const uint16_t len1 = ksearch->filename_len;
+ const uint16_t len2 = entry->filename_len;
return memcmp(
ksearch->filename,
@@ -180,8 +180,10 @@ static int tree_key_search(
const git_tree_entry *entry;
size_t homing, i;
+ TREE_ENTRY_CHECK_NAMELEN(filename_len);
+
ksearch.filename = filename;
- ksearch.filename_len = filename_len;
+ ksearch.filename_len = (uint16_t)filename_len;
/* Initial homing search; find an entry on the tree with
* the same prefix as the filename we're looking for */
@@ -334,6 +336,7 @@ const git_tree_entry *git_tree_entry_byname(
const git_tree *tree, const char *filename)
{
assert(tree && filename);
+
return entry_fromname(tree, filename, strlen(filename));
}
@@ -364,13 +367,16 @@ int git_tree__prefix_position(const git_tree *tree, const char *path)
{
const git_vector *entries = &tree->entries;
struct tree_key_search ksearch;
- size_t at_pos;
+ size_t at_pos, path_len;
if (!path)
return 0;
+ path_len = strlen(path);
+ TREE_ENTRY_CHECK_NAMELEN(path_len);
+
ksearch.filename = path;
- ksearch.filename_len = strlen(path);
+ ksearch.filename_len = (uint16_t)path_len;
/* be safe when we cast away constness - i.e. don't trigger a sort */
assert(git_vector_is_sorted(&tree->entries));
diff --git a/src/unix/posix.h b/src/unix/posix.h
index 6633689bc..83edf2b7e 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -52,8 +52,10 @@ extern char *p_realpath(const char *, char *);
#define p_localtime_r(c, r) localtime_r(c, r)
#define p_gmtime_r(c, r) gmtime_r(c, r)
+#define p_timeval timeval
+
#ifdef HAVE_FUTIMENS
-GIT_INLINE(int) p_futimes(int f, const struct timeval t[2])
+GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2])
{
struct timespec s[2];
s[0].tv_sec = t[0].tv_sec;
diff --git a/src/win32/posix.h b/src/win32/posix.h
index ac98fd864..5fab267c2 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -9,6 +9,7 @@
#include "common.h"
#include "../posix.h"
+#include "win32-compat.h"
#include "path_w32.h"
#include "utf-conv.h"
#include "dir.h"
@@ -16,12 +17,13 @@
typedef SOCKET GIT_SOCKET;
#define p_lseek(f,n,w) _lseeki64(f, n, w)
-#define p_fstat(f,b) _fstat64(f, b)
+
+extern int p_fstat(int fd, struct stat *buf);
extern int p_lstat(const char *file_name, struct stat *buf);
-extern int p_stat(const char* path, struct stat* buf);
+extern int p_stat(const char* path, struct stat *buf);
-extern int p_utimes(const char *filename, const struct timeval times[2]);
-extern int p_futimes(int fd, const struct timeval times[2]);
+extern int p_utimes(const char *filename, const struct p_timeval times[2]);
+extern int p_futimes(int fd, const struct p_timeval times[2]);
extern int p_readlink(const char *path, char *buf, size_t bufsiz);
extern int p_symlink(const char *old, const char *new);
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 414cb4701..fea634b00 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -210,7 +210,7 @@ int p_lstat_posixly(const char *filename, struct stat *buf)
return do_lstat(filename, buf, true);
}
-int p_utimes(const char *filename, const struct timeval times[2])
+int p_utimes(const char *filename, const struct p_timeval times[2])
{
int fd, error;
@@ -223,7 +223,7 @@ int p_utimes(const char *filename, const struct timeval times[2])
return error;
}
-int p_futimes(int fd, const struct timeval times[2])
+int p_futimes(int fd, const struct p_timeval times[2])
{
HANDLE handle;
FILETIME atime = {0}, mtime = {0};
@@ -398,6 +398,22 @@ static int follow_and_lstat_link(git_win32_path path, struct stat* buf)
return lstat_w(target_w, buf, false);
}
+int p_fstat(int fd, struct stat *buf)
+{
+ BY_HANDLE_FILE_INFORMATION fhInfo;
+
+ HANDLE fh = (HANDLE)_get_osfhandle(fd);
+
+ if (fh == INVALID_HANDLE_VALUE ||
+ !GetFileInformationByHandle(fh, &fhInfo)) {
+ errno = EBADF;
+ return -1;
+ }
+
+ git_win32__file_information_to_stat(buf, &fhInfo);
+ return 0;
+}
+
int p_stat(const char* path, struct stat* buf)
{
git_win32_path path_w;
diff --git a/src/win32/w32_util.h b/src/win32/w32_util.h
index 727ed1cef..2e475e5e9 100644
--- a/src/win32/w32_util.h
+++ b/src/win32/w32_util.h
@@ -96,7 +96,7 @@ GIT_INLINE(void) git_win32__filetime_to_timespec(
}
GIT_INLINE(void) git_win32__timeval_to_filetime(
- FILETIME *ft, const struct timeval tv)
+ FILETIME *ft, const struct p_timeval tv)
{
long long ticks = (tv.tv_sec * 10000000LL) +
(tv.tv_usec * 10LL) + 116444736000000000LL;
@@ -105,19 +105,25 @@ GIT_INLINE(void) git_win32__timeval_to_filetime(
ft->dwLowDateTime = (ticks & 0xffffffffLL);
}
-GIT_INLINE(int) git_win32__file_attribute_to_stat(
+GIT_INLINE(void) git_win32__stat_init(
struct stat *st,
- const WIN32_FILE_ATTRIBUTE_DATA *attrdata,
- const wchar_t *path)
+ DWORD dwFileAttributes,
+ DWORD nFileSizeHigh,
+ DWORD nFileSizeLow,
+ FILETIME ftCreationTime,
+ FILETIME ftLastAccessTime,
+ FILETIME ftLastWriteTime)
{
mode_t mode = S_IREAD;
- if (attrdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ memset(st, 0, sizeof(struct stat));
+
+ if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
mode |= S_IFDIR;
else
mode |= S_IFREG;
- if ((attrdata->dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0)
+ if ((dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0)
mode |= S_IWRITE;
st->st_ino = 0;
@@ -125,12 +131,39 @@ GIT_INLINE(int) git_win32__file_attribute_to_stat(
st->st_uid = 0;
st->st_nlink = 1;
st->st_mode = mode;
- st->st_size = ((git_off_t)attrdata->nFileSizeHigh << 32) + attrdata->nFileSizeLow;
+ st->st_size = ((git_off_t)nFileSizeHigh << 32) + nFileSizeLow;
st->st_dev = _getdrive() - 1;
st->st_rdev = st->st_dev;
- git_win32__filetime_to_timespec(&(attrdata->ftLastAccessTime), &(st->st_atim));
- git_win32__filetime_to_timespec(&(attrdata->ftLastWriteTime), &(st->st_mtim));
- git_win32__filetime_to_timespec(&(attrdata->ftCreationTime), &(st->st_ctim));
+ git_win32__filetime_to_timespec(&ftLastAccessTime, &(st->st_atim));
+ git_win32__filetime_to_timespec(&ftLastWriteTime, &(st->st_mtim));
+ git_win32__filetime_to_timespec(&ftCreationTime, &(st->st_ctim));
+}
+
+GIT_INLINE(void) git_win32__file_information_to_stat(
+ struct stat *st,
+ const BY_HANDLE_FILE_INFORMATION *fileinfo)
+{
+ git_win32__stat_init(st,
+ fileinfo->dwFileAttributes,
+ fileinfo->nFileSizeHigh,
+ fileinfo->nFileSizeLow,
+ fileinfo->ftCreationTime,
+ fileinfo->ftLastAccessTime,
+ fileinfo->ftLastWriteTime);
+}
+
+GIT_INLINE(int) git_win32__file_attribute_to_stat(
+ struct stat *st,
+ const WIN32_FILE_ATTRIBUTE_DATA *attrdata,
+ const wchar_t *path)
+{
+ git_win32__stat_init(st,
+ attrdata->dwFileAttributes,
+ attrdata->nFileSizeHigh,
+ attrdata->nFileSizeLow,
+ attrdata->ftCreationTime,
+ attrdata->ftLastAccessTime,
+ attrdata->ftLastWriteTime);
if (attrdata->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && path) {
git_win32_path target;
@@ -139,7 +172,7 @@ GIT_INLINE(int) git_win32__file_attribute_to_stat(
st->st_mode = (st->st_mode & ~S_IFMT) | S_IFLNK;
/* st_size gets the UTF-8 length of the target name, in bytes,
- * not counting the NULL terminator */
+ * not counting the NULL terminator */
if ((st->st_size = git__utf16_to_8(NULL, 0, target)) < 0) {
giterr_set(GITERR_OS, "Could not convert reparse point name for '%s'", path);
return -1;
diff --git a/src/win32/win32-compat.h b/src/win32/win32-compat.h
index d3a5b68a3..dff1f45be 100644
--- a/src/win32/win32-compat.h
+++ b/src/win32/win32-compat.h
@@ -13,6 +13,13 @@
#include <sys/stat.h>
#include <sys/types.h>
+typedef long suseconds_t;
+
+struct p_timeval {
+ time_t tv_sec;
+ suseconds_t tv_usec;
+};
+
struct p_timespec {
time_t tv_sec;
long tv_nsec;
diff --git a/tests/checkout/checkout_helpers.c b/tests/checkout/checkout_helpers.c
index fb2f415e7..d7d24f33f 100644
--- a/tests/checkout/checkout_helpers.c
+++ b/tests/checkout/checkout_helpers.c
@@ -133,7 +133,7 @@ int checkout_count_callback(
void tick_index(git_index *index)
{
struct timespec ts;
- struct timeval times[2];
+ struct p_timeval times[2];
cl_assert(index->on_disk);
cl_assert(git_index_path(index));
diff --git a/tests/core/posix.c b/tests/core/posix.c
index 5a9e24899..34a67bf47 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -100,7 +100,7 @@ void test_core_posix__inet_pton(void)
void test_core_posix__utimes(void)
{
- struct timeval times[2];
+ struct p_timeval times[2];
struct stat st;
time_t curtime;
int fd;
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index 4c782339d..892c7b72d 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -1755,7 +1755,7 @@ void test_diff_workdir__with_stale_index(void)
static int touch_file(void *payload, git_buf *path)
{
struct stat st;
- struct timeval times[2];
+ struct p_timeval times[2];
GIT_UNUSED(payload);
if (git_path_isdir(path->ptr))
@@ -2006,7 +2006,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void)
git_oid initial, first, second;
git_buf path = GIT_BUF_INIT;
struct stat st;
- struct timeval times[2];
+ struct p_timeval times[2];
opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_UPDATE_INDEX;
diff --git a/tests/index/racy.c b/tests/index/racy.c
index e2275ea14..ace84d585 100644
--- a/tests/index/racy.c
+++ b/tests/index/racy.c
@@ -54,7 +54,7 @@ void test_index_racy__write_index_just_after_file(void)
git_index *index;
git_diff *diff;
git_buf path = GIT_BUF_INIT;
- struct timeval times[2];
+ struct p_timeval times[2];
/* Make sure we do have a timestamp */
cl_git_pass(git_repository_index(&index, g_repo));
diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c
index f168963b2..99e33e0cd 100644
--- a/tests/merge/workdir/dirty.c
+++ b/tests/merge/workdir/dirty.c
@@ -133,7 +133,7 @@ static void hack_index(char *files[])
struct stat statbuf;
git_buf path = GIT_BUF_INIT;
git_index_entry *entry;
- struct timeval times[2];
+ struct p_timeval times[2];
time_t now;
size_t i;
@@ -162,8 +162,8 @@ static void hack_index(char *files[])
cl_git_pass(p_utimes(path.ptr, times));
cl_git_pass(p_stat(path.ptr, &statbuf));
- entry->ctime.seconds = (git_time_t)statbuf.st_ctime;
- entry->mtime.seconds = (git_time_t)statbuf.st_mtime;
+ entry->ctime.seconds = (int32_t)statbuf.st_ctime;
+ entry->mtime.seconds = (int32_t)statbuf.st_mtime;
#if defined(GIT_USE_NSEC)
entry->ctime.nanoseconds = statbuf.st_ctim.tv_nsec;
entry->mtime.nanoseconds = statbuf.st_mtim.tv_nsec;
@@ -175,7 +175,7 @@ static void hack_index(char *files[])
entry->ino = statbuf.st_ino;
entry->uid = statbuf.st_uid;
entry->gid = statbuf.st_gid;
- entry->file_size = statbuf.st_size;
+ entry->file_size = (uint32_t)statbuf.st_size;
}
git_buf_free(&path);
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index 149973374..0c0af914c 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -238,7 +238,7 @@ void test_reset_hard__reflog_is_correct(void)
void test_reset_hard__switch_file_to_dir(void)
{
- git_index_entry entry = { 0 };
+ git_index_entry entry = {{ 0 }};
git_index *idx;
git_object *commit;
git_tree *tree;
diff --git a/tests/win32/longpath.c b/tests/win32/longpath.c
index 07eecd394..5a36875ed 100644
--- a/tests/win32/longpath.c
+++ b/tests/win32/longpath.c
@@ -36,7 +36,7 @@ void assert_name_too_long(void)
{
const git_error *err;
size_t expected_len, actual_len;
- const char *expected_msg;
+ char *expected_msg;
err = giterr_last();
actual_len = strlen(err->message);