Commit 44ef8b1b by Russell Belfer

Fix warnings on 64-bit windows builds

This fixes all the warnings on win64 except those in deps, which
come from the regex code.
parent f201d613
......@@ -46,7 +46,7 @@ static void net_set_error(const char *str)
}
#endif
void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd)
void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, GIT_SOCKET fd)
{
memset(buf, 0x0, sizeof(gitno_buffer));
memset(data, 0x0, len);
......@@ -60,17 +60,13 @@ int gitno_recv(gitno_buffer *buf)
{
int ret;
ret = recv(buf->fd, buf->data + buf->offset, buf->len - buf->offset, 0);
if (ret == 0) /* Orderly shutdown, so exit */
return 0;
ret = p_recv(buf->fd, buf->data + buf->offset, buf->len - buf->offset, 0);
if (ret < 0) {
net_set_error("Error receiving data");
net_set_error("Error receiving socket data");
return -1;
}
buf->offset += ret;
return ret;
}
......@@ -97,12 +93,12 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons)
buf->offset -= cons;
}
int gitno_connect(const char *host, const char *port)
GIT_SOCKET gitno_connect(const char *host, const char *port)
{
struct addrinfo *info, *p;
struct addrinfo *info = NULL, *p;
struct addrinfo hints;
int ret;
GIT_SOCKET s;
GIT_SOCKET s = INVALID_SOCKET;
memset(&hints, 0x0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
......@@ -110,36 +106,30 @@ int gitno_connect(const char *host, const char *port)
if ((ret = getaddrinfo(host, port, &hints, &info)) < 0) {
giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret));
return -1;
return INVALID_SOCKET;
}
for (p = info; p != NULL; p = p->ai_next) {
s = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
#ifdef GIT_WIN32
if (s == INVALID_SOCKET) {
#else
if (s < 0) {
#endif
net_set_error("Error creating socket");
freeaddrinfo(info);
return -1;
net_set_error("error creating socket");
break;
}
ret = connect(s, p->ai_addr, p->ai_addrlen);
/* If we can't connect, try the next one */
if (ret < 0) {
close(s);
continue;
}
if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0)
break;
/* Return the socket */
freeaddrinfo(info);
return s;
/* If we can't connect, try the next one */
gitno_close(s);
s = INVALID_SOCKET;
}
/* Oops, we couldn't connect to any address */
giterr_set(GITERR_OS, "Failed to connect to %s", host);
return -1;
if (s == INVALID_SOCKET && p == NULL)
giterr_set(GITERR_OS, "Failed to connect to %s", host);
freeaddrinfo(info);
return s;
}
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
......@@ -150,7 +140,7 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
while (off < len) {
errno = 0;
ret = send(s, msg + off, len - off, flags);
ret = p_send(s, msg + off, len - off, flags);
if (ret < 0) {
net_set_error("Error sending data");
return -1;
......@@ -159,7 +149,7 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
off += ret;
}
return off;
return (int)off;
}
......@@ -187,7 +177,7 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
FD_SET(buf->fd, &fds);
/* The select(2) interface is silly */
return select(buf->fd + 1, &fds, NULL, NULL, &tv);
return select((int)buf->fd + 1, &fds, NULL, NULL, &tv);
}
int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port)
......@@ -198,8 +188,8 @@ int gitno_extract_host_and_port(char **host, char **port, const char *url, const
slash = strchr(url, '/');
if (slash == NULL) {
giterr_set(GITERR_NET, "Malformed URL: missing /");
return -1;
giterr_set(GITERR_NET, "Malformed URL: missing /");
return -1;
}
if (colon == NULL) {
......
......@@ -7,11 +7,7 @@
#ifndef INCLUDE_netops_h__
#define INCLUDE_netops_h__
#ifndef GIT_WIN32
typedef int GIT_SOCKET;
#else
typedef SOCKET GIT_SOCKET;
#endif
#include "posix.h"
typedef struct gitno_buffer {
char *data;
......@@ -20,12 +16,12 @@ typedef struct gitno_buffer {
GIT_SOCKET fd;
} gitno_buffer;
void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd);
void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, GIT_SOCKET fd);
int gitno_recv(gitno_buffer *buf);
void gitno_consume(gitno_buffer *buf, const char *ptr);
void gitno_consume_n(gitno_buffer *buf, size_t cons);
int gitno_connect(const char *host, const char *port);
GIT_SOCKET gitno_connect(const char *host, const char *port);
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags);
int gitno_close(GIT_SOCKET s);
int gitno_send_chunk_size(int s, size_t len);
......
......@@ -212,7 +212,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
struct pack_backend *backend = (struct pack_backend *)_data;
struct git_pack_file *pack;
int error;
size_t i;
unsigned int i;
if (git__suffixcmp(path->ptr, ".idx") != 0)
return 0; /* not an index */
......@@ -266,7 +266,7 @@ static int packfile_refresh_all(struct pack_backend *backend)
static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backend, const git_oid *oid)
{
int error;
size_t i;
unsigned int i;
if ((error = packfile_refresh_all(backend)) < 0)
return error;
......@@ -298,7 +298,7 @@ static int pack_entry_find_prefix(
unsigned int len)
{
int error;
size_t i;
unsigned int i;
unsigned found = 0;
if ((error = packfile_refresh_all(backend)) < 0)
......@@ -423,7 +423,7 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid)
static void pack_backend__free(git_odb_backend *_backend)
{
struct pack_backend *backend;
size_t i;
unsigned int i;
assert(_backend);
......
......@@ -260,6 +260,8 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length)
{
git_oid_shorten *os;
assert((size_t)((int)min_length) == min_length);
os = git__calloc(1, sizeof(git_oid_shorten));
if (os == NULL)
return NULL;
......@@ -270,7 +272,7 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length)
}
os->node_count = 1;
os->min_length = min_length;
os->min_length = (int)min_length;
return os;
}
......@@ -328,7 +330,8 @@ void git_oid_shorten_free(git_oid_shorten *os)
*/
int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
{
int i, is_leaf;
int i;
bool is_leaf;
node_index idx;
if (os->full)
......@@ -338,7 +341,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
return os->min_length;
idx = 0;
is_leaf = 0;
is_leaf = false;
for (i = 0; i < GIT_OID_HEXSZ; ++i) {
int c = git__fromhex(text_oid[i]);
......@@ -368,11 +371,11 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
}
idx = node->children[c];
is_leaf = 0;
is_leaf = false;
if (idx < 0) {
node->children[c] = idx = -idx;
is_leaf = 1;
is_leaf = true;
}
}
......
......@@ -165,6 +165,7 @@ static int pack_index_open(struct git_pack_file *p)
{
char *idx_name;
int error;
size_t name_len, offset;
if (p->index_map.data)
return 0;
......@@ -172,7 +173,11 @@ static int pack_index_open(struct git_pack_file *p)
idx_name = git__strdup(p->pack_name);
GITERR_CHECK_ALLOC(idx_name);
strcpy(idx_name + strlen(idx_name) - strlen(".pack"), ".idx");
name_len = strlen(idx_name);
offset = name_len - strlen(".pack");
assert(offset < name_len); /* make sure no underflow */
strncpy(idx_name + offset, ".idx", name_len - offset);
error = pack_index_check(idx_name, p);
git__free(idx_name);
......@@ -474,7 +479,7 @@ git_off_t get_delta_base(
*
***********************************************************/
static struct git_pack_file *packfile_alloc(int extra)
static struct git_pack_file *packfile_alloc(size_t extra)
{
struct git_pack_file *p = git__calloc(1, sizeof(*p) + extra);
if (p != NULL)
......
......@@ -464,21 +464,22 @@ int git_path_find_dir(git_buf *dir, const char *path, const char *base)
return error;
}
int git_path_cmp(const char *name1, int len1, int isdir1,
const char *name2, int len2, int isdir2)
int git_path_cmp(
const char *name1, size_t len1, int isdir1,
const char *name2, size_t len2, int isdir2)
{
int len = len1 < len2 ? len1 : len2;
size_t len = len1 < len2 ? len1 : len2;
int cmp;
cmp = memcmp(name1, name2, len);
if (cmp)
return cmp;
if (len1 < len2)
return ((!isdir1 && !isdir2) ? -1 :
(isdir1 ? '/' - name2[len1] : name2[len1] - '/'));
return (!isdir1 && !isdir2) ? -1 :
(isdir1 ? '/' - name2[len1] : name2[len1] - '/');
if (len1 > len2)
return ((!isdir1 && !isdir2) ? 1 :
(isdir2 ? name1[len2] - '/' : '/' - name1[len2]));
return (!isdir1 && !isdir2) ? 1 :
(isdir2 ? name1[len2] - '/' : '/' - name1[len2]);
return 0;
}
......
......@@ -204,8 +204,8 @@ extern int git_path_direach(
* Sort function to order two paths.
*/
extern int git_path_cmp(
const char *name1, int len1, int isdir1,
const char *name2, int len2, int isdir2);
const char *name1, size_t len1, int isdir1,
const char *name2, size_t len2, int isdir2);
/**
* Invoke callback up path directory by directory until the ceiling is
......
......@@ -102,6 +102,7 @@ static int comment_pkt(git_pkt **out, const char *line, size_t len)
*/
static int ref_pkt(git_pkt **out, const char *line, size_t len)
{
int error;
git_pkt_ref *pkt;
pkt = git__malloc(sizeof(git_pkt_ref));
......@@ -109,14 +110,13 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len)
memset(pkt, 0x0, sizeof(git_pkt_ref));
pkt->type = GIT_PKT_REF;
if (git_oid_fromstr(&pkt->head.oid, line) < 0) {
giterr_set(GITERR_NET, "Error parsing pkt-line");
if ((error = git_oid_fromstr(&pkt->head.oid, line)) < 0)
goto error_out;
}
/* Check for a bit of consistency */
if (line[GIT_OID_HEXSZ] != ' ') {
giterr_set(GITERR_NET, "Error parsing pkt-line");
error = -1;
goto error_out;
}
......@@ -138,30 +138,32 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len)
}
*out = (git_pkt *)pkt;
return 0;
error_out:
git__free(pkt);
return -1;
return error;
}
static int parse_len(const char *line)
static int32_t parse_len(const char *line)
{
char num[PKT_LEN_SIZE + 1];
int i, len;
int i, error;
int32_t len;
const char *num_end;
memcpy(num, line, PKT_LEN_SIZE);
num[PKT_LEN_SIZE] = '\0';
for (i = 0; i < PKT_LEN_SIZE; ++i) {
if (!isxdigit(num[i]))
return GIT_ENOTNUM;
if (!isxdigit(num[i])) {
giterr_set(GITERR_NET, "Found invalid hex digit in length");
return -1;
}
}
if (git__strtol32(&len, num, &num_end, 16) < 0)
return -1;
if ((error = git__strtol32(&len, num, &num_end, 16)) < 0)
return error;
return len;
}
......@@ -179,16 +181,20 @@ static int parse_len(const char *line)
* in ASCII hexadecimal (including itself)
*/
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t bufflen)
int git_pkt_parse_line(
git_pkt **head, const char *line, const char **out, size_t bufflen)
{
int ret = 0;
size_t len;
int ret;
int32_t len;
/* Not even enough for the length */
if (bufflen > 0 && bufflen < PKT_LEN_SIZE)
return GIT_ESHORTBUFFER;
if (bufflen > 0 && bufflen < PKT_LEN_SIZE) {
giterr_set(GITERR_NET, "Insufficient buffer data");
return -1;
}
if ((ret = parse_len(line)) < 0) {
len = parse_len(line);
if (len < 0) {
/*
* If we fail to parse the length, it might be because the
* server is trying to send us the packfile already.
......@@ -198,18 +204,17 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_
return pack_pkt(head);
}
giterr_set(GITERR_NET, "Error parsing pkt-line");
return -1;
return (int)len;
}
len = ret;
/*
* If we were given a buffer length, then make sure there is
* enough in the buffer to satisfy this line
*/
if (bufflen > 0 && bufflen < len)
return GIT_ESHORTBUFFER;
if (bufflen > 0 && bufflen < (size_t)len) {
giterr_set(GITERR_NET, "Insufficient buffer data for packet length");
return -1;
}
line += PKT_LEN_SIZE;
/*
......@@ -245,7 +250,7 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_
void git_pkt_free(git_pkt *pkt)
{
if(pkt->type == GIT_PKT_REF) {
if (pkt->type == GIT_PKT_REF) {
git_pkt_ref *p = (git_pkt_ref *) pkt;
git__free(p->head.name);
}
......@@ -258,7 +263,7 @@ int git_pkt_buffer_flush(git_buf *buf)
return git_buf_put(buf, pkt_flush_str, strlen(pkt_flush_str));
}
int git_pkt_send_flush(int s)
int git_pkt_send_flush(GIT_SOCKET s)
{
return gitno_send(s, pkt_flush_str, strlen(pkt_flush_str), 0);
......@@ -268,12 +273,14 @@ static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps
{
char capstr[20];
char oid[GIT_OID_HEXSZ +1] = {0};
int len;
unsigned int len;
if (caps->ofs_delta)
strcpy(capstr, GIT_CAP_OFS_DELTA);
strncpy(capstr, GIT_CAP_OFS_DELTA, sizeof(capstr));
len = strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ + strlen(capstr) + 1 /* LF */;
len = (unsigned int)
(strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ +
strlen(capstr) + 1 /* LF */);
git_buf_grow(buf, buf->size + len);
git_oid_fmt(oid, &head->oid);
......@@ -283,15 +290,14 @@ static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps
static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps, GIT_SOCKET fd)
{
git_buf buf = GIT_BUF_INIT;
int error;
int ret;
if (buffer_want_with_caps(head, caps, &buf) < 0)
return -1;
error = gitno_send(fd, buf.ptr, buf.size, 0);
ret = gitno_send(fd, buf.ptr, buf.size, 0);
git_buf_free(&buf);
return error;
return ret;
}
/*
......@@ -335,7 +341,7 @@ int git_pkt_buffer_wants(const git_vector *refs, git_transport_caps *caps, git_b
return git_pkt_buffer_flush(buf);
}
int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, int fd)
int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, GIT_SOCKET fd)
{
unsigned int i = 0;
char buf[sizeof(pkt_want_prefix) + GIT_OID_HEXSZ + 1];
......@@ -357,6 +363,7 @@ int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, int fd)
if (send_want_with_caps(refs->contents[i], caps, fd) < 0)
return -1;
/* Increase it here so it's correct whether we run this or not */
i++;
}
......@@ -384,7 +391,7 @@ int git_pkt_buffer_have(git_oid *oid, git_buf *buf)
return git_buf_printf(buf, "%s%s\n", pkt_have_prefix, oidhex);
}
int git_pkt_send_have(git_oid *oid, int fd)
int git_pkt_send_have(git_oid *oid, GIT_SOCKET fd)
{
char buf[] = "0032have 0000000000000000000000000000000000000000\n";
......@@ -398,7 +405,7 @@ int git_pkt_buffer_done(git_buf *buf)
return git_buf_puts(buf, pkt_done_str);
}
int git_pkt_send_done(int fd)
int git_pkt_send_done(GIT_SOCKET fd)
{
return gitno_send(fd, pkt_done_str, strlen(pkt_done_str), 0);
}
......@@ -11,6 +11,7 @@
#include "common.h"
#include "transport.h"
#include "buffer.h"
#include "posix.h"
#include "git2/net.h"
enum git_pkt_type {
......@@ -65,13 +66,13 @@ typedef struct {
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
int git_pkt_buffer_flush(git_buf *buf);
int git_pkt_send_flush(int s);
int git_pkt_send_flush(GIT_SOCKET s);
int git_pkt_buffer_done(git_buf *buf);
int git_pkt_send_done(int s);
int git_pkt_send_done(GIT_SOCKET s);
int git_pkt_buffer_wants(const git_vector *refs, git_transport_caps *caps, git_buf *buf);
int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, int fd);
int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, GIT_SOCKET fd);
int git_pkt_buffer_have(git_oid *oid, git_buf *buf);
int git_pkt_send_have(git_oid *oid, int fd);
int git_pkt_send_have(git_oid *oid, GIT_SOCKET fd);
void git_pkt_free(git_pkt *pkt);
#endif
......@@ -58,7 +58,13 @@ int p_read(git_file fd, void *buf, size_t cnt)
{
char *b = buf;
while (cnt) {
ssize_t r = read(fd, b, cnt);
ssize_t r;
#ifdef GIT_WIN32
assert((size_t)((unsigned int)cnt) == cnt);
r = read(fd, b, (unsigned int)cnt);
#else
r = read(fd, b, cnt);
#endif
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
......@@ -76,7 +82,13 @@ int p_write(git_file fd, const void *buf, size_t cnt)
{
const char *b = buf;
while (cnt) {
ssize_t r = write(fd, b, cnt);
ssize_t r;
#ifdef GIT_WIN32
assert((size_t)((unsigned int)cnt) == cnt);
r = write(fd, b, (unsigned int)cnt);
#else
r = write(fd, b, cnt);
#endif
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
......
......@@ -54,6 +54,14 @@ extern int p_rename(const char *from, const char *to);
#define p_rmdir(p) rmdir(p)
#define p_chmod(p,m) chmod(p, m)
#define p_access(p,m) access(p,m)
#define p_recv(s,b,l,f) recv(s,b,l,f)
#define p_send(s,b,l,f) send(s,b,l,f)
typedef int GIT_SOCKET;
#define INVALID_SOCKET -1
#else
typedef SOCKET GIT_SOCKET;
#endif
......
......@@ -17,14 +17,14 @@ int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri)
assert(q);
/* Need to allocate n+1 elements since element 0 isn't used. */
if ((q->d = git__malloc((n + 1) * sizeof(void *))) == NULL)
return GIT_ENOMEM;
q->d = git__malloc((n + 1) * sizeof(void *));
GITERR_CHECK_ALLOC(q->d);
q->size = 1;
q->avail = q->step = (n + 1); /* see comment above about n+1 */
q->cmppri = cmppri;
return GIT_SUCCESS;
return 0;
}
......@@ -102,8 +102,8 @@ int git_pqueue_insert(git_pqueue *q, void *d)
/* allocate more memory if necessary */
if (q->size >= q->avail) {
newsize = q->size + q->step;
if ((tmp = git__realloc(q->d, sizeof(void *) * newsize)) == NULL)
return GIT_ENOMEM;
tmp = git__realloc(q->d, sizeof(void *) * newsize);
GITERR_CHECK_ALLOC(tmp);
q->d = tmp;
q->avail = newsize;
......@@ -114,7 +114,7 @@ int git_pqueue_insert(git_pqueue *q, void *d)
q->d[i] = d;
bubble_up(q, i);
return GIT_SUCCESS;
return 0;
}
......
......@@ -133,13 +133,13 @@ static int reference_read(
static int loose_parse_symbolic(git_reference *ref, git_buf *file_content)
{
const unsigned int header_len = strlen(GIT_SYMREF);
const unsigned int header_len = (unsigned int)strlen(GIT_SYMREF);
const char *refname_start;
char *eol;
refname_start = (const char *)file_content->ptr;
if (file_content->size < (header_len + 1))
if (file_content->size < header_len + 1)
goto corrupt;
/*
......@@ -730,11 +730,11 @@ static int packed_write(git_repository *repo)
unsigned int i;
git_buf pack_file_path = GIT_BUF_INIT;
git_vector packing_list;
size_t total_refs;
unsigned int total_refs;
assert(repo && repo->references.packfile);
total_refs = repo->references.packfile->key_count;
total_refs = (unsigned int)repo->references.packfile->key_count;
if (git_vector_init(&packing_list, total_refs, packed_sort) < 0)
return -1;
......@@ -821,9 +821,9 @@ static int _reference_available_cb(const char *ref, void *data)
d = (struct reference_available_t *)data;
if (!d->old_ref || strcmp(d->old_ref, ref)) {
int reflen = strlen(ref);
int newlen = strlen(d->new_ref);
int cmplen = reflen < newlen ? reflen : newlen;
size_t reflen = strlen(ref);
size_t newlen = strlen(d->new_ref);
size_t cmplen = reflen < newlen ? reflen : newlen;
const char *lead = reflen < newlen ? d->new_ref : ref;
if (!strncmp(d->new_ref, ref, cmplen) && lead[cmplen] == '/') {
......
......@@ -183,21 +183,20 @@ static int find_ceiling_dir_offset(
char buf[GIT_PATH_MAX + 1];
char buf2[GIT_PATH_MAX + 1];
const char *ceil, *sep;
int len, max_len = -1;
int min_len;
size_t len, max_len = 0, min_len;
assert(path);
min_len = git_path_root(path) + 1;
min_len = (size_t)(git_path_root(path) + 1);
if (ceiling_directories == NULL || min_len == 0)
return min_len;
return (int)min_len;
for (sep = ceil = ceiling_directories; *sep; ceil = sep + 1) {
for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
len = sep - ceil;
if (len == 0 || len >= (int)sizeof(buf) || git_path_root(ceil) == -1)
if (len == 0 || len >= sizeof(buf) || git_path_root(ceil) == -1)
continue;
strncpy(buf, ceil, len);
......@@ -218,7 +217,7 @@ static int find_ceiling_dir_offset(
}
}
return max_len <= min_len ? min_len : max_len;
return (int)(max_len <= min_len ? min_len : max_len);
}
/*
......
......@@ -77,11 +77,10 @@ static int commit_time_cmp(void *a, void *b)
static commit_list *commit_list_insert(commit_object *item, commit_list **list_p)
{
commit_list *new_list = git__malloc(sizeof(commit_list));
if (new_list == NULL)
return NULL;
new_list->item = item;
new_list->next = *list_p;
if (new_list != NULL) {
new_list->item = item;
new_list->next = *list_p;
}
*list_p = new_list;
return new_list;
}
......@@ -143,8 +142,7 @@ static int alloc_chunk(git_revwalk *walk)
void *chunk;
chunk = git__calloc(COMMITS_PER_CHUNK, CHUNK_STEP);
if (chunk == NULL)
return GIT_ENOMEM;
GITERR_CHECK_ALLOC(chunk);
walk->chunk_size = 0;
return git_vector_insert(&walk->memory_alloc, chunk);
......@@ -155,7 +153,8 @@ static commit_object *alloc_commit(git_revwalk *walk)
unsigned char *chunk;
if (walk->chunk_size == COMMITS_PER_CHUNK)
alloc_chunk(walk);
if (alloc_chunk(walk) < 0)
return NULL;
chunk = git_vector_get(&walk->memory_alloc, walk->memory_alloc.length - 1);
chunk += (walk->chunk_size * CHUNK_STEP);
......@@ -186,7 +185,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
git_oid_cpy(&commit->oid, oid);
if (git_hashtable_insert(walk->commits, &commit->oid, commit) < GIT_SUCCESS) {
if (git_hashtable_insert(walk->commits, &commit->oid, commit) < 0) {
git__free(commit);
return NULL;
}
......@@ -196,7 +195,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawobj *raw)
{
const int parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
unsigned char *buffer = raw->data;
unsigned char *buffer_end = buffer + raw->len;
......@@ -262,7 +261,7 @@ static int commit_parse(git_revwalk *walk, commit_object *commit)
return 0;
if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
return -1;
return error;
if (obj->raw.type != GIT_OBJ_COMMIT) {
git_odb_object_free(obj);
......@@ -432,6 +431,8 @@ static void mark_uninteresting(commit_object *commit)
static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
{
int error;
if (hide)
mark_uninteresting(commit);
......@@ -440,8 +441,8 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
commit->seen = 1;
if (commit_parse(walk, commit) < 0)
return -1;
if ((error = commit_parse(walk, commit)) < 0)
return error;
return walk->enqueue(walk, commit);
}
......@@ -449,13 +450,12 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
static int process_commit_parents(git_revwalk *walk, commit_object *commit)
{
unsigned short i;
int error = 0;
for (i = 0; i < commit->out_degree; ++i) {
if (process_commit(walk, commit->parents[i], commit->uninteresting) < 0)
return -1;
}
for (i = 0; i < commit->out_degree && !error; ++i)
error = process_commit(walk, commit->parents[i], commit->uninteresting);
return 0;
return error;
}
static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
......@@ -464,7 +464,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
commit = commit_lookup(walk, oid);
if (commit == NULL)
return -1;
return -1; /* error already reported by failed lookup */
commit->uninteresting = uninteresting;
if (walk->one == NULL && !uninteresting) {
......@@ -549,7 +549,8 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide)
data.glob = git_buf_cstr(&buf);
data.hide = hide;
if (git_reference_foreach(walk->repo, GIT_REF_LISTALL, push_glob_cb, &data) < 0)
if (git_reference_foreach(
walk->repo, GIT_REF_LISTALL, push_glob_cb, &data) < 0)
goto on_error;
regfree(&preg);
......@@ -605,7 +606,7 @@ static int revwalk_enqueue_timesort(git_revwalk *walk, commit_object *commit)
static int revwalk_enqueue_unsorted(git_revwalk *walk, commit_object *commit)
{
return commit_list_insert(commit, &walk->iterator_rand) ? GIT_SUCCESS : GIT_ENOMEM;
return commit_list_insert(commit, &walk->iterator_rand) ? 0 : -1;
}
static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
......@@ -615,7 +616,7 @@ static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) {
if ((error = process_commit_parents(walk, next)) < 0)
return -1;
return error;
if (!next->uninteresting) {
*object_out = next;
......@@ -633,7 +634,7 @@ static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
while ((next = commit_list_pop(&walk->iterator_rand)) != NULL) {
if ((error = process_commit_parents(walk, next)) < 0)
return -1;
return error;
if (!next->uninteresting) {
*object_out = next;
......@@ -715,19 +716,19 @@ static int prepare_walk(git_revwalk *walk)
}
if (error != GIT_EREVWALKOVER)
return -1;
return error;
walk->get_next = &revwalk_next_toposort;
}
if (walk->sorting & GIT_SORT_REVERSE) {
while ((error = walk->get_next(&next, walk)) == GIT_SUCCESS)
while ((error = walk->get_next(&next, walk)) == 0)
if (commit_list_insert(next, &walk->iterator_reverse) == NULL)
return -1;
if (error != GIT_EREVWALKOVER)
return -1;
return error;
walk->get_next = &revwalk_next_reverse;
}
......@@ -752,16 +753,13 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
walk->commits = git_hashtable_alloc(64,
object_table_hash,
(git_hash_keyeq_ptr)git_oid_cmp);
GITERR_CHECK_ALLOC(walk->commits);
if (walk->commits == NULL) {
git__free(walk);
if (git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp) < 0 ||
git_vector_init(&walk->memory_alloc, 8, NULL) < 0 ||
git_vector_init(&walk->twos, 4, NULL) < 0 ||
alloc_chunk(walk) < 0)
return -1;
}
git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp);
git_vector_init(&walk->memory_alloc, 8, NULL);
git_vector_init(&walk->twos, 4, NULL);
alloc_chunk(walk);
walk->get_next = &revwalk_next_unsorted;
walk->enqueue = &revwalk_enqueue_unsorted;
......@@ -840,7 +838,7 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk)
if (!walk->walking) {
if ((error = prepare_walk(walk)) < 0)
return -1;
return error;
}
error = walk->get_next(&next, walk);
......@@ -850,11 +848,10 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk)
return GIT_EREVWALKOVER;
}
if (error < 0)
return -1;
if (!error)
git_oid_cpy(oid, &next->oid);
git_oid_cpy(oid, &next->oid);
return 0;
return error;
}
void git_revwalk_reset(git_revwalk *walk)
......
......@@ -232,7 +232,7 @@ void git__blk_SHA1_Init(blk_SHA_CTX *ctx)
ctx->H[4] = 0xc3d2e1f0;
}
void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, size_t len)
{
unsigned int lenW = ctx->size & 63;
......@@ -242,7 +242,7 @@ void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
if (lenW) {
unsigned int left = 64 - lenW;
if (len < left)
left = len;
left = (unsigned int)len;
memcpy(lenW + (char *)ctx->W, data, left);
lenW = (lenW + left) & 63;
len -= left;
......
......@@ -12,7 +12,7 @@ typedef struct {
} blk_SHA_CTX;
void git__blk_SHA1_Init(blk_SHA_CTX *ctx);
void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len);
void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, size_t len);
void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx);
#define SHA_CTX blk_SHA_CTX
......
......@@ -47,7 +47,7 @@ static int signature_error(const char *msg)
static int process_trimming(const char *input, char **storage, const char *input_end, int fail_when_empty)
{
const char *left, *right;
int trimmed_input_length;
size_t trimmed_input_length;
assert(storage);
......
......@@ -67,7 +67,8 @@ int git_tag__parse_buffer(git_tag *tag, const char *buffer, size_t length)
NULL, "commit\n", "tree\n", "blob\n", "tag\n"
};
unsigned int i, text_len;
unsigned int i;
size_t text_len;
char *search;
int error;
......
......@@ -46,7 +46,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
char *delim, *repo;
char default_command[] = "git-upload-pack";
char host[] = "host=";
int len;
size_t len;
delim = strchr(url, '/');
if (delim == NULL) {
......@@ -66,7 +66,8 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1;
git_buf_grow(request, len);
git_buf_printf(request, "%04x%s %s%c%s", len, cmd, repo, 0, host);
git_buf_printf(request, "%04x%s %s%c%s",
(unsigned int)(len & 0x0FFFF), cmd, repo, 0, host);
git_buf_put(request, url, delim - url);
git_buf_putc(request, '\0');
......@@ -119,7 +120,7 @@ static int do_connect(transport_git *t, const char *url)
git__free(port);
if (error < GIT_SUCCESS && s > 0)
close(s);
gitno_close(s);
if (!connected) {
giterr_set(GITERR_NET, "Failed to connect to the host");
return -1;
......
......@@ -32,7 +32,7 @@ typedef struct {
git_protocol proto;
git_vector refs;
git_vector common;
int socket;
GIT_SOCKET socket;
git_buf buf;
git_remote_head **heads;
int error;
......@@ -96,7 +96,7 @@ static int do_connect(transport_http *t, const char *host, const char *port)
t->socket = s;
t->parent.connected = 1;
return GIT_SUCCESS;
return 0;
}
/*
......
......@@ -624,7 +624,7 @@ static int tree_frompath(
git_tree **parent_out,
git_tree *root,
git_buf *treeentry_path,
int offset)
size_t offset)
{
char *slash_pos = NULL;
const git_tree_entry* entry;
......
......@@ -30,8 +30,10 @@ static int binsearch(void **dst, const void *x, size_t size, cmp_ptr_t cmp)
int l, c, r;
void *lx, *cx;
assert(size > 0);
l = 0;
r = size - 1;
r = (int)size - 1;
c = r >> 1;
lx = dst[l];
......@@ -84,7 +86,7 @@ static void bisort(void **dst, size_t start, size_t size, cmp_ptr_t cmp)
/* Else we need to find the right place, shift everything over, and squeeze in */
x = dst[i];
location = binsearch(dst, x, i, cmp);
for (j = i - 1; j >= location; j--) {
for (j = (int)i - 1; j >= location; j--) {
dst[j + 1] = dst[j];
}
dst[location] = x;
......@@ -104,7 +106,7 @@ struct tsort_store {
void **storage;
};
static void reverse_elements(void **dst, int start, int end)
static void reverse_elements(void **dst, ssize_t start, ssize_t end)
{
while (start < end) {
void *tmp = dst[start];
......@@ -116,7 +118,7 @@ static void reverse_elements(void **dst, int start, int end)
}
}
static int count_run(void **dst, ssize_t start, ssize_t size, struct tsort_store *store)
static ssize_t count_run(void **dst, ssize_t start, ssize_t size, struct tsort_store *store)
{
ssize_t curr = start + 2;
......@@ -148,7 +150,7 @@ static int count_run(void **dst, ssize_t start, ssize_t size, struct tsort_store
}
}
static int compute_minrun(size_t n)
static size_t compute_minrun(size_t n)
{
int r = 0;
while (n >= 64) {
......@@ -158,19 +160,19 @@ static int compute_minrun(size_t n)
return n + r;
}
static int check_invariant(struct tsort_run *stack, int stack_curr)
static int check_invariant(struct tsort_run *stack, ssize_t stack_curr)
{
if (stack_curr < 2)
return 1;
else if (stack_curr == 2) {
const int A = stack[stack_curr - 2].length;
const int B = stack[stack_curr - 1].length;
const ssize_t A = stack[stack_curr - 2].length;
const ssize_t B = stack[stack_curr - 1].length;
return (A > B);
} else {
const int A = stack[stack_curr - 3].length;
const int B = stack[stack_curr - 2].length;
const int C = stack[stack_curr - 1].length;
const ssize_t A = stack[stack_curr - 3].length;
const ssize_t B = stack[stack_curr - 2].length;
const ssize_t C = stack[stack_curr - 1].length;
return !((A <= B + C) || (B <= C));
}
}
......@@ -195,7 +197,7 @@ static int resize(struct tsort_store *store, size_t new_size)
return 0;
}
static void merge(void **dst, const struct tsort_run *stack, int stack_curr, struct tsort_store *store)
static void merge(void **dst, const struct tsort_run *stack, ssize_t stack_curr, struct tsort_store *store)
{
const ssize_t A = stack[stack_curr - 2].length;
const ssize_t B = stack[stack_curr - 1].length;
......@@ -343,7 +345,7 @@ void git__tsort(void **dst, size_t size, cmp_ptr_t cmp)
}
/* compute the minimum run length */
minrun = compute_minrun(size);
minrun = (ssize_t)compute_minrun(size);
/* temporary storage for merges */
store->alloc = 0;
......
......@@ -391,10 +391,11 @@ int git__bsearch(
int (*compare)(const void *, const void *),
size_t *position)
{
int lim, cmp = -1;
unsigned int lim;
int cmp = -1;
void **part, **base = array;
for (lim = array_len; lim != 0; lim >>= 1) {
for (lim = (unsigned int)array_len; lim != 0; lim >>= 1) {
part = base + (lim >> 1);
cmp = (*compare)(key, *part);
if (cmp == 0) {
......
......@@ -10,7 +10,7 @@
#include "vector.h"
static const double resize_factor = 1.75;
static const size_t minimum_size = 8;
static const unsigned int minimum_size = 8;
static int resize_vector(git_vector *v)
{
......
......@@ -49,5 +49,7 @@ extern int p_open(const char *path, int flags);
extern int p_creat(const char *path, mode_t mode);
extern int p_getcwd(char *buffer_out, size_t size);
extern int p_rename(const char *from, const char *to);
extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags);
extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags);
#endif
......@@ -4,7 +4,7 @@
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "posix.h"
#include "../posix.h"
#include "path.h"
#include "utf-conv.h"
#include <errno.h>
......@@ -179,11 +179,11 @@ int p_readlink(const char *link, char *target, size_t target_len)
target_w = (wchar_t*)git__malloc(target_len * sizeof(wchar_t));
GITERR_CHECK_ALLOC(target_w);
dwRet = pGetFinalPath(hFile, target_w, target_len, 0x0);
dwRet = pGetFinalPath(hFile, target_w, (DWORD)target_len, 0x0);
if (dwRet == 0 ||
dwRet >= target_len ||
!WideCharToMultiByte(CP_UTF8, 0, target_w, -1, target,
target_len * sizeof(char), NULL, NULL))
(int)(target_len * sizeof(char)), NULL, NULL))
error = -1;
git__free(target_w);
......@@ -241,13 +241,19 @@ int p_creat(const char *path, mode_t mode)
int p_getcwd(char *buffer_out, size_t size)
{
wchar_t* buf = (wchar_t*)git__malloc(sizeof(wchar_t) * (int)size);
int ret;
wchar_t* buf;
if ((size_t)((int)size) != size)
return -1;
buf = (wchar_t*)git__malloc(sizeof(wchar_t) * (int)size);
GITERR_CHECK_ALLOC(buf);
_wgetcwd(buf, (int)size);
ret = WideCharToMultiByte(
CP_UTF8, 0, buf, -1, buffer_out, size, NULL, NULL);
CP_UTF8, 0, buf, -1, buffer_out, (int)size, NULL, NULL);
git__free(buf);
return !ret ? -1 : 0;
......@@ -421,3 +427,19 @@ int p_rename(const char *from, const char *to)
return ret;
}
int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags)
{
if ((size_t)((int)length) != length)
return -1; /* giterr_set will be done by caller */
return recv(socket, buffer, (int)length, flags);
}
int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags)
{
if ((size_t)((int)length) != length)
return -1; /* giterr_set will be done by caller */
return send(socket, buffer, (int)length, flags);
}
......@@ -31,27 +31,23 @@ void gitwin_set_utf8(void)
wchar_t* gitwin_to_utf16(const char* str)
{
wchar_t* ret;
int cb;
size_t cb;
if (!str)
return NULL;
cb = strlen(str) * sizeof(wchar_t);
if (cb == 0) {
ret = (wchar_t*)git__malloc(sizeof(wchar_t));
if (ret)
ret[0] = 0;
return ret;
}
if (cb == 0)
return (wchar_t *)git__calloc(1, sizeof(wchar_t));
/* Add space for null terminator */
cb += sizeof(wchar_t);
ret = (wchar_t*)git__malloc(cb);
ret = (wchar_t *)git__malloc(cb);
if (!ret)
return NULL;
if (MultiByteToWideChar(_active_codepage, 0, str, -1, ret, cb) == 0) {
if (MultiByteToWideChar(_active_codepage, 0, str, -1, ret, (int)cb) == 0) {
giterr_set(GITERR_OS, "Could not convert string to UTF-16");
git__free(ret);
ret = NULL;
......@@ -62,7 +58,7 @@ wchar_t* gitwin_to_utf16(const char* str)
int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len)
{
int result = MultiByteToWideChar(_active_codepage, 0, str, -1, buffer, len);
int result = MultiByteToWideChar(_active_codepage, 0, str, -1, buffer, (int)len);
if (result == 0)
giterr_set(GITERR_OS, "Could not convert string to UTF-16");
return result;
......@@ -71,19 +67,14 @@ int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len)
char* gitwin_from_utf16(const wchar_t* str)
{
char* ret;
int cb;
size_t cb;
if (!str) {
if (!str)
return NULL;
}
cb = wcslen(str) * sizeof(char);
if (cb == 0) {
ret = (char*)git__malloc(sizeof(char));
if (ret)
ret[0] = 0;
return ret;
}
if (cb == 0)
return (char *)git__calloc(1, sizeof(char));
/* Add space for null terminator */
cb += sizeof(char);
......@@ -92,7 +83,7 @@ char* gitwin_from_utf16(const wchar_t* str)
if (!ret)
return NULL;
if (WideCharToMultiByte(_active_codepage, 0, str, -1, ret, cb, NULL, NULL) == 0) {
if (WideCharToMultiByte(_active_codepage, 0, str, -1, ret, (int)cb, NULL, NULL) == 0) {
giterr_set(GITERR_OS, "Could not convert string to UTF-8");
git__free(ret);
ret = NULL;
......
......@@ -40,7 +40,7 @@ static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec) {
static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb) {
long size, psize = strlen(pre);
long size, psize = (long)strlen(pre);
char const *rec;
size = xdl_get_rec(xdf, ri, &rec);
......
......@@ -149,9 +149,9 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
int size, int i, int style,
xdmerge_t *m, char *dest, int marker_size)
{
int marker1_size = (name1 ? strlen(name1) + 1 : 0);
int marker2_size = (name2 ? strlen(name2) + 1 : 0);
int marker3_size = (name3 ? strlen(name3) + 1 : 0);
int marker1_size = (name1 ? (int)strlen(name1) + 1 : 0);
int marker2_size = (name2 ? (int)strlen(name2) + 1 : 0);
int marker3_size = (name3 ? (int)strlen(name3) + 1 : 0);
if (marker_size <= 0)
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
......
......@@ -62,14 +62,14 @@ int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize,
void *xdl_mmfile_first(mmfile_t *mmf, long *size)
{
*size = mmf->size;
*size = (long)mmf->size;
return mmf->ptr;
}
long xdl_mmfile_size(mmfile_t *mmf)
{
return mmf->size;
return (long)mmf->size;
}
......@@ -321,7 +321,7 @@ int xdl_num_out(char *out, long val) {
*str++ = '0';
*str = '\0';
return str - out;
return (int)(str - out);
}
......
......@@ -5,7 +5,7 @@ git_tree *resolve_commit_oid_to_tree(
git_repository *repo,
const char *partial_oid)
{
size_t len = strlen(partial_oid);
unsigned int len = (unsigned int)strlen(partial_oid);
git_oid oid;
git_object *obj = NULL;
git_tree *tree = NULL;
......
#include "clar_libgit2.h"
#include "fileops.h"
#include <ctype.h>
void test_repo_open__cleanup(void)
{
......@@ -234,7 +235,6 @@ void test_repo_open__win32_path(void)
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("empty_standard_repo"), *repo2;
git_buf winpath = GIT_BUF_INIT;
char *src, *tgt;
static const char *repo_path = "empty_standard_repo/.git/";
static const char *repo_wd = "empty_standard_repo/";
......
struct status_entry_counts {
int wrong_status_flags_count;
int wrong_sorted_path;
int entry_count;
size_t wrong_status_flags_count;
size_t wrong_sorted_path;
size_t entry_count;
const unsigned int* expected_statuses;
const char** expected_paths;
int expected_entry_count;
size_t expected_entry_count;
};
/* entries for a plain copy of tests/resources/status */
......
......@@ -112,7 +112,7 @@ BEGIN_TEST(table2, "make sure the table resizes automatically")
const int objects_n = 64;
int i;
unsigned int old_size;
size_t old_size;
table_item *objects;
git_hashtable *table = NULL;
......
......@@ -87,7 +87,7 @@ void locate_loose_object(const char *repository_folder, git_object *object, char
static const char *objects_folder = "objects/";
char *ptr, *full_path, *top_folder;
int path_length, objects_length;
size_t path_length, objects_length;
assert(repository_folder && object);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment