Fix -Wsign-compare warnings: use size_t or unsigned for byte counts

This commit is contained in:
Andrew Bettison 2013-12-10 16:52:53 +10:30
parent 476a538ef7
commit 4af6cf9d6a
15 changed files with 41 additions and 42 deletions

4
cli.c
View File

@ -195,7 +195,7 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema *
// Look for a match. // Look for a match.
const char *prefix = NULL; const char *prefix = NULL;
unsigned prefixlen = 0; unsigned prefixlen = 0;
char prefixarglen = 0; unsigned prefixarglen = 0;
const char *caret = strchr(word, '<'); const char *caret = strchr(word, '<');
if (wordlen > 2 && caret && word[wordlen-1] == '>') { if (wordlen > 2 && caret && word[wordlen-1] == '>') {
if ((prefixarglen = prefixlen = caret - word)) { if ((prefixarglen = prefixlen = caret - word)) {
@ -297,7 +297,7 @@ int cli_invoke(const struct cli_parsed *parsed, struct cli_context *context)
int _cli_arg(struct __sourceloc __whence, const struct cli_parsed *parsed, char *label, const char **dst, int (*validator)(const char *arg), char *defaultvalue) int _cli_arg(struct __sourceloc __whence, const struct cli_parsed *parsed, char *label, const char **dst, int (*validator)(const char *arg), char *defaultvalue)
{ {
int labellen = strlen(label); unsigned labellen = strlen(label);
if (dst) if (dst)
*dst = defaultvalue; *dst = defaultvalue;
unsigned i; unsigned i;

View File

@ -1820,7 +1820,7 @@ int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *con
retfile = rhizome_extract_file(m, filepath); retfile = rhizome_extract_file(m, filepath);
}else{ }else{
// Save the file without attempting to decrypt // Save the file without attempting to decrypt
int64_t length; uint64_t length;
retfile = rhizome_dump_file(&m->filehash, filepath, &length); retfile = rhizome_dump_file(&m->filehash, filepath, &length);
} }
} }
@ -1870,7 +1870,7 @@ int app_rhizome_export_file(const struct cli_parsed *parsed, struct cli_context
return -1; return -1;
if (!rhizome_exists(&hash)) if (!rhizome_exists(&hash))
return 1; return 1;
int64_t length; uint64_t length;
int ret = rhizome_dump_file(&hash, filepath, &length); int ret = rhizome_dump_file(&hash, filepath, &length);
if (ret) if (ret)
return ret == -1 ? -1 : 1; return ret == -1 ? -1 : 1;
@ -2278,15 +2278,14 @@ static int handle_pins(const struct cli_parsed *parsed, struct cli_context *UNUS
}else{ }else{
request->action=ACTION_UNLOCK; request->action=ACTION_UNLOCK;
} }
int len = sizeof(struct mdp_identity_request); size_t len = sizeof(struct mdp_identity_request);
if (pin && *pin) { if (pin && *pin) {
request->type=TYPE_PIN; request->type=TYPE_PIN;
int pin_len = strlen(pin)+1; size_t pin_siz = strlen(pin) + 1;
if (pin_len+len > sizeof(request_payload)) if (pin_siz + len > sizeof(request_payload))
return WHY("Supplied pin is too long"); return WHY("Supplied pin is too long");
bcopy(pin, &request_payload[len], pin_len); bcopy(pin, &request_payload[len], pin_siz);
len+=pin_len; len += pin_siz;
}else if(sid_hex && *sid_hex){ }else if(sid_hex && *sid_hex){
request->type=TYPE_SID; request->type=TYPE_SID;
sid_t sid; sid_t sid;

View File

@ -102,10 +102,10 @@ int crypto_create_signature(unsigned char *key,
} }
// sign the hash of a message, adding the signature to the end of the message buffer. // sign the hash of a message, adding the signature to the end of the message buffer.
int crypto_sign_message(struct subscriber *source, unsigned char *content, int buffer_len, int *content_len) int crypto_sign_message(struct subscriber *source, unsigned char *content, size_t buffer_len, size_t *content_len)
{ {
if (*content_len + SIGNATURE_BYTES > buffer_len) if (*content_len + SIGNATURE_BYTES > buffer_len)
return WHYF("Insufficient space in message buffer to add signature. %d, need %d",buffer_len, *content_len + SIGNATURE_BYTES); return WHYF("Insufficient space in message buffer to add signature. %zu, need %zu",buffer_len, *content_len + SIGNATURE_BYTES);
unsigned char *key=keyring_find_sas_private(keyring, &source->sid, NULL); unsigned char *key=keyring_find_sas_private(keyring, &source->sid, NULL);
if (!key) if (!key)

View File

@ -30,7 +30,7 @@ int crypto_verify_message(struct subscriber *subscriber, unsigned char *message,
int crypto_create_signature(unsigned char *key, int crypto_create_signature(unsigned char *key,
unsigned char *content, int content_len, unsigned char *content, int content_len,
unsigned char *signature, int *sig_length); unsigned char *signature, int *sig_length);
int crypto_sign_message(struct subscriber *source, unsigned char *content, int buffer_len, int *content_len); int crypto_sign_message(struct subscriber *source, unsigned char *content, size_t buffer_len, size_t *content_len);
int crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk); int crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk);
#endif #endif

View File

@ -10,7 +10,7 @@
rs = NULL; rs = NULL;
/* Check parameter ranges */ /* Check parameter ranges */
if(symsize < 0 || symsize > 8*sizeof(data_t)){ if(symsize < 0 || symsize > (int)(8*sizeof(data_t))){
goto done; goto done;
} }

13
lsif.c
View File

@ -124,7 +124,7 @@ int
lsif(void) { lsif(void) {
char buf[8192]; char buf[8192];
struct ifconf ifc; struct ifconf ifc;
int sck, nInterfaces, ofs; int sck;
struct ifreq *ifr; struct ifreq *ifr;
struct in_addr addr, netmask; struct in_addr addr, netmask;
@ -138,7 +138,7 @@ lsif(void) {
} }
/* Query available interfaces. */ /* Query available interfaces. */
ifc.ifc_len = sizeof(buf); ifc.ifc_len = sizeof buf;
ifc.ifc_buf = buf; ifc.ifc_buf = buf;
if(ioctl(sck, SIOCGIFCONF, &ifc) < 0) { if(ioctl(sck, SIOCGIFCONF, &ifc) < 0) {
WHY_perror("ioctl(SIOCGIFCONF)"); WHY_perror("ioctl(SIOCGIFCONF)");
@ -147,10 +147,9 @@ lsif(void) {
} }
/* Iterate through the list of interfaces. */ /* Iterate through the list of interfaces. */
nInterfaces = 0; unsigned nInterfaces = 0;
ofs = 0; unsigned ofs = 0;
while (ofs < (unsigned)ifc.ifc_len && ofs < sizeof buf) {
while (ofs < ifc.ifc_len && ofs < sizeof(buf)) {
ifr = (struct ifreq *)(ifc.ifc_ifcu.ifcu_buf + ofs); ifr = (struct ifreq *)(ifc.ifc_ifcu.ifcu_buf + ofs);
ofs += _SIZEOF_ADDR_IFREQ(*ifr); ofs += _SIZEOF_ADDR_IFREQ(*ifr);
@ -183,7 +182,7 @@ lsif(void) {
nInterfaces++; nInterfaces++;
} }
if (config.debug.overlayinterfaces) DEBUGF("Examined %d interface addresses", nInterfaces); if (config.debug.overlayinterfaces) DEBUGF("Examined %u interface addresses", nInterfaces);
close(sck); close(sck);
return 0; return 0;

View File

@ -351,7 +351,7 @@ end:
static int overlay_mdp_service_manifest_requests(struct overlay_frame *frame, const uint8_t *payload, size_t len) static int overlay_mdp_service_manifest_requests(struct overlay_frame *frame, const uint8_t *payload, size_t len)
{ {
int offset=0; size_t offset = 0;
while (offset < len) { while (offset < len) {
rhizome_manifest *m = rhizome_new_manifest(); rhizome_manifest *m = rhizome_new_manifest();
if (!m) if (!m)

View File

@ -708,7 +708,7 @@ struct rhizome_read
unsigned char key[RHIZOME_CRYPT_KEY_BYTES]; unsigned char key[RHIZOME_CRYPT_KEY_BYTES];
unsigned char nonce[crypto_stream_xsalsa20_NONCEBYTES]; unsigned char nonce[crypto_stream_xsalsa20_NONCEBYTES];
int64_t hash_offset; uint64_t hash_offset;
SHA512_CTX sha512_context; SHA512_CTX sha512_context;
char invalid; char invalid;
@ -808,7 +808,7 @@ void rhizome_direct_bundle_iterator_unlimit(rhizome_direct_bundle_cursor *r);
int rhizome_direct_bundle_iterator_pickle_range(rhizome_direct_bundle_cursor *r, int rhizome_direct_bundle_iterator_pickle_range(rhizome_direct_bundle_cursor *r,
unsigned char *pickled, unsigned char *pickled,
int pickle_buffer_size); int pickle_buffer_size);
rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix,int prefix_length); rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix, size_t prefix_length);
int rhizome_direct_bundle_iterator_unpickle_range(rhizome_direct_bundle_cursor *r, int rhizome_direct_bundle_iterator_unpickle_range(rhizome_direct_bundle_cursor *r,
const unsigned char *pickled, const unsigned char *pickled,
int pickle_buffer_size); int pickle_buffer_size);
@ -941,7 +941,7 @@ ssize_t rhizome_read_buffered(struct rhizome_read *read, struct rhizome_read_buf
int rhizome_read_close(struct rhizome_read *read); int rhizome_read_close(struct rhizome_read *read);
int rhizome_open_decrypt_read(rhizome_manifest *m, struct rhizome_read *read_state); int rhizome_open_decrypt_read(rhizome_manifest *m, struct rhizome_read *read_state);
int rhizome_extract_file(rhizome_manifest *m, const char *filepath); int rhizome_extract_file(rhizome_manifest *m, const char *filepath);
int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, int64_t *length); int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, uint64_t *lengthp);
int rhizome_read_cached(const rhizome_bid_t *bid, uint64_t version, time_ms_t timeout, int rhizome_read_cached(const rhizome_bid_t *bid, uint64_t version, time_ms_t timeout,
uint64_t fileOffset, unsigned char *buffer, size_t length); uint64_t fileOffset, unsigned char *buffer, size_t length);
int rhizome_cache_close(); int rhizome_cache_close();

View File

@ -391,7 +391,7 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
return c; return c;
} }
rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix,int prefix_length) rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix, size_t prefix_length)
{ {
/* Give a BID prefix, e.g., from a BAR, find the matching manifest and return it. /* Give a BID prefix, e.g., from a BAR, find the matching manifest and return it.
Of course, it is possible that more than one manifest matches. This should Of course, it is possible that more than one manifest matches. This should
@ -407,7 +407,6 @@ rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix,int pref
*/ */
rhizome_bid_t low = RHIZOME_BID_ZERO; rhizome_bid_t low = RHIZOME_BID_ZERO;
rhizome_bid_t high = RHIZOME_BID_MAX; rhizome_bid_t high = RHIZOME_BID_MAX;
assert(prefix_length >= 0);
assert(prefix_length <= sizeof(rhizome_bid_t)); assert(prefix_length <= sizeof(rhizome_bid_t));
bcopy(bid_prefix, low.binary, prefix_length); bcopy(bid_prefix, low.binary, prefix_length);
bcopy(bid_prefix, high.binary, prefix_length); bcopy(bid_prefix, high.binary, prefix_length);

View File

@ -419,12 +419,12 @@ int rhizome_direct_dispatch(rhizome_http_request *r, const char *UNUSED(remainde
static int receive_http_response(int sock, char *buffer, size_t buffer_len, struct http_response_parts *parts) static int receive_http_response(int sock, char *buffer, size_t buffer_len, struct http_response_parts *parts)
{ {
int len = 0; size_t len = 0;
int count; ssize_t count;
do { do {
if ((count = read(sock, &buffer[len], buffer_len - len)) == -1) if ((count = read(sock, &buffer[len], buffer_len - len)) == -1)
return WHYF_perror("read(%d, %p, %d)", sock, &buffer[len], (int)buffer_len - len); return WHYF_perror("read(%d, %p, %d)", sock, &buffer[len], (int)buffer_len - len);
len += count; len += (size_t)count;
} while (len < buffer_len && count != 0 && !is_http_header_complete(buffer, len, len)); } while (len < buffer_len && count != 0 && !is_http_header_complete(buffer, len, len));
if (config.debug.rhizome_rx) if (config.debug.rhizome_rx)
DEBUGF("Received HTTP response %s", alloca_toprint(-1, buffer, len)); DEBUGF("Received HTTP response %s", alloca_toprint(-1, buffer, len));
@ -440,7 +440,7 @@ static int receive_http_response(int sock, char *buffer, size_t buffer_len, stru
return -1; return -1;
} }
if (config.debug.rhizome_rx) if (config.debug.rhizome_rx)
DEBUGF("content_length=%"PRId64, parts->content_length); DEBUGF("content_length=%"PRIu64, parts->content_length);
return len - (parts->content_start - buffer); return len - (parts->content_start - buffer);
} }

View File

@ -1147,7 +1147,7 @@ int rhizome_extract_file(rhizome_manifest *m, const char *filepath)
* *
* Returns -1 on error, 0 if dumped successfully, 1 if not found. * Returns -1 on error, 0 if dumped successfully, 1 if not found.
*/ */
int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, int64_t *length) int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, uint64_t *lengthp)
{ {
struct rhizome_read read_state; struct rhizome_read read_state;
bzero(&read_state, sizeof read_state); bzero(&read_state, sizeof read_state);
@ -1156,8 +1156,8 @@ int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, int
if (ret == 0) { if (ret == 0) {
ret = write_file(&read_state, filepath); ret = write_file(&read_state, filepath);
if (length) if (lengthp)
*length = read_state.length; *lengthp = read_state.length;
} }
rhizome_read_close(&read_state); rhizome_read_close(&read_state);
return ret; return ret;
@ -1166,7 +1166,8 @@ int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, int
// pipe data from one payload to another // pipe data from one payload to another
static int rhizome_pipe(struct rhizome_read *read, struct rhizome_write *write, uint64_t length) static int rhizome_pipe(struct rhizome_read *read, struct rhizome_write *write, uint64_t length)
{ {
if (length > write->file_length - write->file_offset) assert(write->file_offset <= write->file_length);
if (length > (uint64_t)(write->file_length - write->file_offset))
return WHY("Unable to pipe that much data"); return WHY("Unable to pipe that much data");
unsigned char buffer[RHIZOME_CRYPT_PAGE_SIZE]; unsigned char buffer[RHIZOME_CRYPT_PAGE_SIZE];

View File

@ -291,7 +291,7 @@ int isOverlayPacket(XPRINTF xpf, const unsigned char *packet, size_t *ofs, size_
xprintf(xpf, "%sMDP Sequence; 0x%02x\n", indent(6), packet[(*ofs)++]); xprintf(xpf, "%sMDP Sequence; 0x%02x\n", indent(6), packet[(*ofs)++]);
} }
int payload_len = 0; uint16_t payload_len = 0;
if (encapsulation==1){ if (encapsulation==1){
payload_len=packet[(*ofs)++]<<8; payload_len=packet[(*ofs)++]<<8;
payload_len|=packet[(*ofs)++]; payload_len|=packet[(*ofs)++];

View File

@ -80,7 +80,8 @@ int _make_local_sockaddr(struct __sourceloc __whence, struct socket_address *add
*/ */
int real_sockaddr(const struct socket_address *src_addr, struct socket_address *dst_addr) int real_sockaddr(const struct socket_address *src_addr, struct socket_address *dst_addr)
{ {
int src_path_len = src_addr->addrlen - sizeof src_addr->local.sun_family; assert(src_addr->addrlen > sizeof src_addr->local.sun_family);
size_t src_path_len = src_addr->addrlen - sizeof src_addr->local.sun_family;
if ( src_addr->addrlen >= sizeof src_addr->local.sun_family + 1 if ( src_addr->addrlen >= sizeof src_addr->local.sun_family + 1
&& src_addr->local.sun_family == AF_UNIX && src_addr->local.sun_family == AF_UNIX
&& src_addr->local.sun_path[0] != '\0' && src_addr->local.sun_path[0] != '\0'

2
str.c
View File

@ -632,7 +632,7 @@ int parse_argv(char *cmdline, char delim, char **argv, int max_argv)
} }
/* Like strstr() but doesn't depend on null termination */ /* Like strstr() but doesn't depend on null termination */
char *str_str(char *haystack, const char *needle, int haystack_len) char *str_str(char *haystack, const char *needle, size_t haystack_len)
{ {
size_t needle_len = strlen(needle); size_t needle_len = strlen(needle);
if (needle_len == 0) if (needle_len == 0)

2
str.h
View File

@ -378,7 +378,7 @@ int strn_str_casecmp(const char *str1, size_t len1, const char *str2);
* @author Paul Gardner-Stephen <paul@servalproject.org> * @author Paul Gardner-Stephen <paul@servalproject.org>
* @author Andrew Bettison <andrew@servalproject.com> * @author Andrew Bettison <andrew@servalproject.com>
*/ */
char *str_str(char *haystack, const char *needle, int haystack_len); char *str_str(char *haystack, const char *needle, size_t haystack_len);
/* Parse a string as an integer in ASCII radix notation in the given 'base' (eg, base=10 means /* Parse a string as an integer in ASCII radix notation in the given 'base' (eg, base=10 means
* decimal). * decimal).