[or-cvs] r13672: More 64-to-32 fixes. (in tor/trunk: . src/or)
nickm at seul.org
nickm at seul.org
Fri Feb 22 03:44:37 UTC 2008
Author: nickm
Date: 2008-02-21 22:44:36 -0500 (Thu, 21 Feb 2008)
New Revision: 13672
Modified:
tor/trunk/
tor/trunk/src/or/buffers.c
tor/trunk/src/or/circuituse.c
tor/trunk/src/or/command.c
tor/trunk/src/or/config.c
tor/trunk/src/or/connection.c
Log:
r14388 at tombo: nickm | 2008-02-21 22:44:28 -0500
More 64-to-32 fixes.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r14388] on 49666b30-7950-49c5-bedf-9dc8f3168102
Modified: tor/trunk/src/or/buffers.c
===================================================================
--- tor/trunk/src/or/buffers.c 2008-02-22 03:29:17 UTC (rev 13671)
+++ tor/trunk/src/or/buffers.c 2008-02-22 03:44:36 UTC (rev 13672)
@@ -553,7 +553,7 @@
read_to_chunk(buf_t *buf, chunk_t *chunk, int fd, size_t at_most,
int *reached_eof)
{
- int read_result;
+ ssize_t read_result;
tor_assert(CHUNK_REMAINING_CAPACITY(chunk) >= at_most);
read_result = tor_socket_recv(fd, CHUNK_WRITE_PTR(chunk), at_most, 0);
@@ -574,9 +574,10 @@
} else { /* actually got bytes. */
buf->datalen += read_result;
chunk->datalen += read_result;
- log_debug(LD_NET,"Read %d bytes. %d on inbuf.", read_result,
+ log_debug(LD_NET,"Read %ld bytes. %d on inbuf.", (long)read_result,
(int)buf->datalen);
- return read_result;
+ tor_assert(read_result < INT_MAX);
+ return (int)read_result;
}
}
@@ -634,8 +635,10 @@
check();
if (r < 0)
return r; /* Error */
- else if ((size_t)r < readlen) /* eof, block, or no more to read. */
- return r + total_read;
+ else if ((size_t)r < readlen) { /* eof, block, or no more to read. */
+ tor_assert(r+total_read < INT_MAX);
+ return (int)(r + total_read);
+ }
total_read += r;
}
return r;
@@ -702,7 +705,7 @@
flush_chunk(int s, buf_t *buf, chunk_t *chunk, size_t sz,
size_t *buf_flushlen)
{
- int write_result;
+ ssize_t write_result;
tor_assert(sz <= chunk->datalen);
write_result = tor_socket_send(s, chunk->data, sz, 0);
@@ -720,7 +723,8 @@
} else {
*buf_flushlen -= write_result;
buf_remove_from_front(buf, write_result);
- return write_result;
+ tor_assert(write_result < INT_MAX);
+ return (int)write_result;
}
}
@@ -798,7 +802,8 @@
if (r == 0 || (size_t)r < flushlen0) /* can't flush any more now. */
break;
}
- return flushed;
+ tor_assert(flushed < INT_MAX);
+ return (int)flushed;
}
/** As flush_buf(), but writes data to a TLS connection. Can write more than
@@ -841,7 +846,8 @@
if (r == 0) /* Can't flush any more now. */
break;
} while (sz > 0);
- return flushed;
+ tor_assert(flushed < INT_MAX);
+ return (int)flushed;
}
/** Append <b>string_len</b> bytes from <b>string</b> to the end of
@@ -853,7 +859,7 @@
write_to_buf(const char *string, size_t string_len, buf_t *buf)
{
if (!string_len)
- return buf->datalen;
+ return (int)buf->datalen;
check();
while (string_len) {
@@ -872,7 +878,8 @@
}
check();
- return buf->datalen;
+ tor_assert(buf->datalen < INT_MAX);
+ return (int)buf->datalen;
}
/** Helper: copy the first <b>string_len</b> bytes from <b>buf</b>
@@ -917,7 +924,8 @@
peek_from_buf(string, string_len, buf);
buf_remove_from_front(buf, string_len);
check();
- return buf->datalen;
+ tor_assert(buf->datalen < INT_MAX);
+ return (int)buf->datalen;
}
/** Check <b>buf</b> for a variable-length cell according to the rules of link
@@ -982,6 +990,7 @@
len = buf_in->datalen;
cp = len; /* Remember the number of bytes we intend to copy. */
+ tor_assert(cp < INT_MAX);
while (len) {
/* This isn't the most efficient implementation one could imagine, since
* it does two copies instead of 1, but I kinda doubt that this will be
@@ -992,7 +1001,7 @@
len -= n;
}
*buf_flushlen -= cp;
- return cp;
+ return (int)cp;
}
/** Internal structure: represents a position in a buffer. */
@@ -1014,7 +1023,7 @@
/** Advance <b>out</b> to the first appearance of <b>ch</b> at the current
* position of <b>out</b>, or later. Return -1 if no instances are found;
* otherwise returns the absolute position of the character. */
-static int
+static off_t
buf_find_pos_of_char(char ch, buf_pos_t *out)
{
const chunk_t *chunk;
@@ -1040,7 +1049,8 @@
char *cp = memchr(chunk->data+pos, ch, chunk->datalen - pos);
if (cp) {
out->chunk = chunk;
- out->pos = cp - chunk->data;
+ tor_assert(cp - chunk->data < INT_MAX);
+ out->pos = (int)(cp - chunk->data);
return out->chunk_pos + out->pos;
} else {
out->chunk_pos += chunk->datalen;
@@ -1101,7 +1111,8 @@
buf_pos_init(buf, &pos);
while (buf_find_pos_of_char(*s, &pos) >= 0) {
if (buf_matches_at_pos(&pos, s, n)) {
- return pos.chunk_pos + pos.pos;
+ tor_assert(pos.chunk_pos + pos.pos < INT_MAX);
+ return (int)(pos.chunk_pos + pos.pos);
} else {
if (buf_pos_inc(&pos)<0)
return -1;
@@ -1561,11 +1572,11 @@
/** Return the index within <b>buf</b> at which <b>ch</b> first appears,
* or -1 if <b>ch</b> does not appear on buf. */
-static int
+static off_t
buf_find_offset_of_char(buf_t *buf, char ch)
{
chunk_t *chunk;
- int offset = 0;
+ off_t offset = 0;
for (chunk = buf->head; chunk; chunk = chunk->next) {
char *cp = memchr(chunk->data, ch, chunk->datalen);
if (cp)
@@ -1587,7 +1598,7 @@
fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len)
{
size_t sz;
- int offset;
+ off_t offset;
if (!buf->head)
return 0;
Modified: tor/trunk/src/or/circuituse.c
===================================================================
--- tor/trunk/src/or/circuituse.c 2008-02-22 03:29:17 UTC (rev 13671)
+++ tor/trunk/src/or/circuituse.c 2008-02-22 03:44:36 UTC (rev 13672)
@@ -1272,7 +1272,7 @@
tor_assert(conn->socks_request);
want_onehop = conn->want_onehop;
- conn_age = time(NULL) - conn->_base.timestamp_created;
+ conn_age = (int)(time(NULL) - conn->_base.timestamp_created);
if (conn_age >= get_options()->SocksTimeout) {
int severity = (!conn->_base.addr && !conn->_base.port) ?
Modified: tor/trunk/src/or/command.c
===================================================================
--- tor/trunk/src/or/command.c 2008-02-22 03:29:17 UTC (rev 13671)
+++ tor/trunk/src/or/command.c 2008-02-22 03:44:36 UTC (rev 13672)
@@ -530,7 +530,7 @@
conn->handshake_state->received_versions);
/* Decode the cell. */
timestamp = ntohl(get_uint32(cell->payload));
- if (abs(now - conn->handshake_state->sent_versions_at) < 180) {
+ if (labs(now - conn->handshake_state->sent_versions_at) < 180) {
apparent_skew = now - timestamp;
}
@@ -574,7 +574,7 @@
/* Act on apparent skew. */
/** Warn when we get a netinfo skew with at least this value. */
#define NETINFO_NOTICE_SKEW 3600
- if (abs(apparent_skew) > NETINFO_NOTICE_SKEW &&
+ if (labs(apparent_skew) > NETINFO_NOTICE_SKEW &&
router_get_by_digest(conn->identity_digest)) {
char dbuf[64];
/*XXXX This should check the trustedness of the other side. */
Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c 2008-02-22 03:29:17 UTC (rev 13671)
+++ tor/trunk/src/or/config.c 2008-02-22 03:44:36 UTC (rev 13672)
@@ -1514,7 +1514,7 @@
switch (var->type) {
case CONFIG_TYPE_UINT:
- i = tor_parse_long(c->value, 10, 0, INT_MAX, &ok, NULL);
+ i = (int)tor_parse_long(c->value, 10, 0, INT_MAX, &ok, NULL);
if (!ok) {
r = tor_snprintf(buf, sizeof(buf),
"Int keyword '%s %s' is malformed or out of bounds.",
@@ -1552,7 +1552,7 @@
}
case CONFIG_TYPE_BOOL:
- i = tor_parse_long(c->value, 10, 0, 1, &ok, NULL);
+ i = (int)tor_parse_long(c->value, 10, 0, 1, &ok, NULL);
if (!ok) {
r = tor_snprintf(buf, sizeof(buf),
"Boolean '%s %s' expects 0 or 1.",
Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c 2008-02-22 03:29:17 UTC (rev 13671)
+++ tor/trunk/src/or/connection.c 2008-02-22 03:44:36 UTC (rev 13672)
@@ -789,10 +789,11 @@
* right after somebody else has let it go. But REUSEADDR on win32
* means you can bind to the port _even when somebody else
* already has it bound_. So, don't do that on Win32. */
- setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one, sizeof(one));
+ setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one,
+ (socklen_t)sizeof(one));
#endif
- if (bind(s,listensockaddr,sizeof(struct sockaddr_in)) < 0) {
+ if (bind(s,listensockaddr,(socklen_t)sizeof(struct sockaddr_in)) < 0) {
const char *helpfulhint = "";
int e = tor_socket_errno(s);
if (ERRNO_IS_EADDRINUSE(e))
@@ -2585,7 +2586,7 @@
{
uint32_t iface_ip, ip_out;
struct sockaddr_in out_addr;
- socklen_t out_addr_len = sizeof(out_addr);
+ socklen_t out_addr_len = (socklen_t) sizeof(out_addr);
uint32_t *ip;
if (!last_interface_ip)
@@ -2640,12 +2641,12 @@
set_constrained_socket_buffers(int sock, int size)
{
void *sz = (void*)&size;
- if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, sz, sizeof(size)) < 0) {
+ if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, sz,(socklen_t)sizeof(size)) < 0) {
int e = tor_socket_errno(sock);
log_warn(LD_NET, "setsockopt() to constrain send "
"buffer to %d bytes failed: %s", size, tor_socket_strerror(e));
}
- if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, sz, sizeof(size)) < 0) {
+ if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, sz,(socklen_t)sizeof(size)) < 0) {
int e = tor_socket_errno(sock);
log_warn(LD_NET, "setsockopt() to constrain recv "
"buffer to %d bytes failed: %s", size, tor_socket_strerror(e));
More information about the tor-commits
mailing list