Fix even more win64 warnings

This commit is contained in:
Nick Mathewson 2010-11-01 13:43:43 -04:00
parent b6a158ca22
commit 7484df61c9
7 changed files with 31 additions and 17 deletions

View File

@ -201,10 +201,14 @@ evbuffer_launch_write(struct evbuffer *buf, ev_ssize_t at_most,
_evbuffer_chain_pin(chain, EVBUFFER_MEM_PINNED_W); _evbuffer_chain_pin(chain, EVBUFFER_MEM_PINNED_W);
if ((size_t)at_most > chain->off) { if ((size_t)at_most > chain->off) {
b->len = chain->off; /* XXXX Cast is safe for now, since win32 has no
mmaped chains. But later, we need to have this
add more WSAbufs if chain->off is greater than
ULONG_MAX */
b->len = (unsigned long)chain->off;
at_most -= chain->off; at_most -= chain->off;
} else { } else {
b->len = at_most; b->len = (unsigned long)at_most;
++i; ++i;
break; break;
} }

View File

@ -194,7 +194,9 @@ bev_async_consider_writing(struct bufferevent_async *beva)
at_most = evbuffer_get_length(bev->output); at_most = evbuffer_get_length(bev->output);
/* XXXX This over-commits. */ /* XXXX This over-commits. */
limit = _bufferevent_get_write_max(&beva->bev); /* This is safe so long as bufferevent_get_write_max never returns
* more than INT_MAX. That's true for now. XXXX */
limit = (int)_bufferevent_get_write_max(&beva->bev);
if (at_most >= (size_t)limit && limit >= 0) if (at_most >= (size_t)limit && limit >= 0)
at_most = limit; at_most = limit;
@ -248,7 +250,8 @@ bev_async_consider_reading(struct bufferevent_async *beva)
} }
/* XXXX This over-commits. */ /* XXXX This over-commits. */
limit = _bufferevent_get_read_max(&beva->bev); /* XXXX see also not above on cast on _bufferevent_get_write_max() */
limit = (int)_bufferevent_get_read_max(&beva->bev);
if (at_most >= (size_t)limit && limit >= 0) if (at_most >= (size_t)limit && limit >= 0)
at_most = limit; at_most = limit;

View File

@ -152,13 +152,13 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
} }
readmax = _bufferevent_get_read_max(bufev_p); readmax = _bufferevent_get_read_max(bufev_p);
if (howmuch < 0 || howmuch > readmax) /* The use of -1 for "unlimited" if (howmuch < 0 || howmuch > readmax) /* The use of -1 for "unlimited"
* uglifies this code. */ * uglifies this code. XXXX */
howmuch = readmax; howmuch = readmax;
if (bufev_p->read_suspended) if (bufev_p->read_suspended)
goto done; goto done;
evbuffer_unfreeze(input, 0); evbuffer_unfreeze(input, 0);
res = evbuffer_read(input, fd, howmuch); res = evbuffer_read(input, fd, (int)howmuch); /* XXXX evbuffer_read would do better to take and return ev_ssize_t */
evbuffer_freeze(input, 0); evbuffer_freeze(input, 0);
if (res == -1) { if (res == -1) {
@ -203,7 +203,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
int res = 0; int res = 0;
short what = BEV_EVENT_WRITING; short what = BEV_EVENT_WRITING;
int connected = 0; int connected = 0;
int atmost = -1; ev_ssize_t atmost = -1;
_bufferevent_incref_and_lock(bufev); _bufferevent_incref_and_lock(bufev);

View File

@ -161,7 +161,7 @@ struct evbuffer_chain {
/** unused space at the beginning of buffer or an offset into a /** unused space at the beginning of buffer or an offset into a
* file for sendfile buffers. */ * file for sendfile buffers. */
off_t misalign; ev_off_t misalign;
/** Offset into buffer + misalign at which to start writing. /** Offset into buffer + misalign at which to start writing.
* In other words, the total number of bytes actually stored * In other words, the total number of bytes actually stored
@ -262,8 +262,10 @@ int _evbuffer_read_setup_vecs(struct evbuffer *buf, ev_ssize_t howmuch,
/* Helper macro: copies an evbuffer_iovec in ei to a win32 WSABUF in i. */ /* Helper macro: copies an evbuffer_iovec in ei to a win32 WSABUF in i. */
#define WSABUF_FROM_EVBUFFER_IOV(i,ei) do { \ #define WSABUF_FROM_EVBUFFER_IOV(i,ei) do { \
(i)->buf = (ei)->iov_base; \ (i)->buf = (ei)->iov_base; \
(i)->len = (ei)->iov_len; \ (i)->len = (unsigned long)(ei)->iov_len; \
} while (0) } while (0)
/* XXXX the cast above is safe for now, but not if we allow mmaps on win64.
* See note in buffer_iocp's launch_write function */
/** Set the parent bufferevent object for buf to bev */ /** Set the parent bufferevent object for buf to bev */
void evbuffer_set_parent(struct evbuffer *buf, struct bufferevent *bev); void evbuffer_set_parent(struct evbuffer *buf, struct bufferevent *bev);

View File

@ -83,8 +83,8 @@
#define open _open #define open _open
#define read _read #define read _read
#define close _close #define close _close
#define fstat _fstat #define fstat _fstati64
#define stat _stat #define stat _stati64
#endif #endif
/** /**
@ -131,7 +131,12 @@ evutil_read_file(const char *filename, char **content_out, size_t *len_out,
return -2; return -2;
} }
read_so_far = 0; read_so_far = 0;
while ((r = read(fd, mem+read_so_far, st.st_size - read_so_far)) > 0) { #ifdef WIN32
#define N_TO_READ(x) ((x) > INT_MAX) ? INT_MAX : ((int)(x))
#else
#defien N_TO_READ(x) (x)
#endif
while ((r = read(fd, mem+read_so_far, N_TO_READ(st.st_size - read_so_far))) > 0) {
read_so_far += r; read_so_far += r;
if (read_so_far >= (size_t)st.st_size) if (read_so_far >= (size_t)st.st_size)
break; break;
@ -1717,7 +1722,7 @@ evutil_parse_sockaddr_port(const char *ip_as_string, struct sockaddr *out, int *
if (!(cp = strchr(ip_as_string, ']'))) { if (!(cp = strchr(ip_as_string, ']'))) {
return -1; return -1;
} }
len = cp-(ip_as_string + 1); len = (int) ( cp-(ip_as_string + 1) );
if (len > (int)sizeof(buf)-1) { if (len > (int)sizeof(buf)-1) {
return -1; return -1;
} }

View File

@ -121,6 +121,6 @@ void
evutil_secure_rng_add_bytes(const char *buf, size_t n) evutil_secure_rng_add_bytes(const char *buf, size_t n)
{ {
arc4random_addrandom((unsigned char*)buf, arc4random_addrandom((unsigned char*)buf,
n>(size_t)INT_MAX ? INT_MAX : n); n>(size_t)INT_MAX ? INT_MAX : (int)n);
} }

View File

@ -139,17 +139,17 @@ evbuffer_get_waste(struct evbuffer *buf, size_t *allocatedp, size_t *wastedp, si
a += chain->buffer_len; a += chain->buffer_len;
u += chain->off; u += chain->off;
if (chain->next && chain->next->off) if (chain->next && chain->next->off)
w += chain->buffer_len - (chain->misalign + chain->off); w += (size_t)(chain->buffer_len - (chain->misalign + chain->off));
chain = chain->next; chain = chain->next;
} }
/* subsequent nonempty chains */ /* subsequent nonempty chains */
while (chain && chain->off) { while (chain && chain->off) {
++n; ++n;
a += chain->buffer_len; a += chain->buffer_len;
w += chain->misalign; w += (size_t)chain->misalign;
u += chain->off; u += chain->off;
if (chain->next && chain->next->off) if (chain->next && chain->next->off)
w += chain->buffer_len - (chain->misalign + chain->off); w += (size_t) (chain->buffer_len - (chain->misalign + chain->off));
chain = chain->next; chain = chain->next;
} }
/* subsequent empty chains */ /* subsequent empty chains */