diff --git a/src/or/buffers.c b/src/or/buffers.c index a5732253be..7b54dd3968 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -553,7 +553,7 @@ static INLINE int 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 @@ read_to_chunk(buf_t *buf, chunk_t *chunk, int fd, size_t at_most, } 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 @@ read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof) 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 @@ static INLINE int 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 @@ flush_chunk(int s, buf_t *buf, chunk_t *chunk, size_t sz, } 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 @@ flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen) 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 @@ flush_buf_tls(tor_tls_t *tls, buf_t *buf, size_t flushlen, if (r == 0) /* Can't flush any more now. */ break; } while (sz > 0); - return flushed; + tor_assert(flushed < INT_MAX); + return (int)flushed; } /** Append string_len bytes from string to the end of @@ -853,7 +859,7 @@ int 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 @@ write_to_buf(const char *string, size_t string_len, buf_t *buf) } check(); - return buf->datalen; + tor_assert(buf->datalen < INT_MAX); + return (int)buf->datalen; } /** Helper: copy the first string_len bytes from buf @@ -917,7 +924,8 @@ fetch_from_buf(char *string, size_t string_len, buf_t *buf) 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 buf for a variable-length cell according to the rules of link @@ -982,6 +990,7 @@ move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen) 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 @@ move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen) len -= n; } *buf_flushlen -= cp; - return cp; + return (int)cp; } /** Internal structure: represents a position in a buffer. */ @@ -1014,7 +1023,7 @@ buf_pos_init(const buf_t *buf, buf_pos_t *out) /** Advance out to the first appearance of ch at the current * position of out, 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 @@ buf_find_pos_of_char(char ch, buf_pos_t *out) 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_find_string_offset(const buf_t *buf, const char *s, size_t n) 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 @@ peek_buf_has_control0_command(buf_t *buf) /** Return the index within buf at which ch first appears, * or -1 if ch 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 @@ int 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; diff --git a/src/or/circuituse.c b/src/or/circuituse.c index e0e8350e10..5f45292859 100644 --- a/src/or/circuituse.c +++ b/src/or/circuituse.c @@ -1272,7 +1272,7 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn) 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) ? diff --git a/src/or/command.c b/src/or/command.c index 66723d4dd0..d05f6cdae9 100644 --- a/src/or/command.c +++ b/src/or/command.c @@ -530,7 +530,7 @@ command_process_netinfo_cell(cell_t *cell, or_connection_t *conn) 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 @@ command_process_netinfo_cell(cell_t *cell, or_connection_t *conn) /* 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. */ diff --git a/src/or/config.c b/src/or/config.c index 461282f8db..6be55dd6df 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -1514,7 +1514,7 @@ config_assign_value(config_format_t *fmt, or_options_t *options, 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 @@ config_assign_value(config_format_t *fmt, or_options_t *options, } 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.", diff --git a/src/or/connection.c b/src/or/connection.c index 54edcea73d..8243e61110 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -789,10 +789,11 @@ connection_create_listener(struct sockaddr *listensockaddr, int type, * 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 @@ client_check_address_changed(int sock) { 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 @@ static void 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));