Commit 3d251737 authored by Pekka Pessi's avatar Pekka Pessi

msg, nth, nua, sip, soa, sresolv, su, tport: signed/unsigned fixes, fixes in...

msg, nth, nua, sip, soa, sresolv, su, tport: signed/unsigned fixes, fixes in checking error returns.

darcs-hash:20060926112825-65a35-d94b2830f4e2cc4d7af21308f69d4d94d068b3e6.gz
parent a576102e
...@@ -1573,7 +1573,7 @@ size_t msg_header_prepare(msg_mclass_t const *mc, int flags, ...@@ -1573,7 +1573,7 @@ size_t msg_header_prepare(msg_mclass_t const *mc, int flags,
msg_header_t *h0, *next; msg_header_t *h0, *next;
msg_hclass_t *hc; msg_hclass_t *hc;
char const *s; char const *s;
size_t n, m; size_t n; ssize_t m;
int middle = 0, compact, one_line_list, comma_list; int middle = 0, compact, one_line_list, comma_list;
assert(h); assert(h->sh_class); assert(h); assert(h->sh_class);
...@@ -1944,8 +1944,6 @@ isize_t msg_iovec(msg_t *msg, msg_iovec_t vec[], isize_t veclen) ...@@ -1944,8 +1944,6 @@ isize_t msg_iovec(msg_t *msg, msg_iovec_t vec[], isize_t veclen)
msg->m_size = total; msg->m_size = total;
assert(n > 0);
return n; return n;
} }
......
...@@ -1583,7 +1583,7 @@ issize_t msg_random_token(char token[], isize_t tlen, ...@@ -1583,7 +1583,7 @@ issize_t msg_random_token(char token[], isize_t tlen,
random = random | (rbyte << n); random = random | (rbyte << n);
n += 8; n += 8;
} else { } else {
rword = (uint32_t)su_randint(INT_MIN, INT_MAX); rword = su_random();
random = (rword >> 13) & 31; random = (rword >> 13) & 31;
n = 6; n = 6;
} }
......
...@@ -144,7 +144,7 @@ struct nth_client_s { ...@@ -144,7 +144,7 @@ struct nth_client_s {
url_string_t const *hc_route_url; url_string_t const *hc_route_url;
tp_name_t hc_tpn[1]; /**< Where to send requests */ tp_name_t hc_tpn[1]; /**< Where to send requests */
tport_t *hc_tport; tport_t *hc_tport;
unsigned hc_pending; /**< Request is pending in tport */ int hc_pending; /**< Request is pending in tport */
tagi_t *hc_tags; /**< Transport tags */ tagi_t *hc_tags; /**< Transport tags */
auth_client_t **hc_auc; /**< List of authenticators */ auth_client_t **hc_auc; /**< List of authenticators */
...@@ -1043,7 +1043,7 @@ static nth_client_t *hc_send(nth_client_t * hc) ...@@ -1043,7 +1043,7 @@ static nth_client_t *hc_send(nth_client_t * hc)
hc->hc_tport = tport_incref(tp); hc->hc_tport = tport_incref(tp);
hc->hc_pending = tport_pend(tp, hc->hc_request, hc_tport_error, hc); hc->hc_pending = tport_pend(tp, hc->hc_request, hc_tport_error, hc);
if (hc->hc_pending < 0) if (hc->hc_pending == -1)
hc->hc_pending = 0; hc->hc_pending = 0;
if (hc->hc_expires) { if (hc->hc_expires) {
......
...@@ -79,7 +79,7 @@ su_inline void nhp_or_set(nua_handle_preferences_t *a, ...@@ -79,7 +79,7 @@ su_inline void nhp_or_set(nua_handle_preferences_t *a,
{ {
unsigned *ap = (unsigned *)&a->nhp_set; unsigned *ap = (unsigned *)&a->nhp_set;
unsigned const *bp = (unsigned const *)&b->nhp_set; unsigned const *bp = (unsigned const *)&b->nhp_set;
int i; size_t i;
memcpy(a, b, offsetof(nua_handle_preferences_t, nhp_set)); memcpy(a, b, offsetof(nua_handle_preferences_t, nhp_set));
......
...@@ -316,7 +316,7 @@ int process_response_to_publish(nua_handle_t *nh, ...@@ -316,7 +316,7 @@ int process_response_to_publish(nua_handle_t *nh,
struct nua_client_request *cr = nh->nh_cr; struct nua_client_request *cr = nh->nh_cr;
nua_dialog_usage_t *du = cr->cr_usage; nua_dialog_usage_t *du = cr->cr_usage;
struct publish_usage *pu = nua_dialog_usage_private(du); struct publish_usage *pu = nua_dialog_usage_private(du);
int saved_retry_count = cr->cr_retry_count + 1; unsigned saved_retry_count = cr->cr_retry_count + 1;
if (nua_creq_check_restart(nh, cr, orq, sip, restart_publish)) if (nua_creq_check_restart(nh, cr, orq, sip, restart_publish))
return 0; return 0;
......
...@@ -368,10 +368,10 @@ issize_t sip_header_field_d(su_home_t *home, sip_header_t *h, char *s, isize_t s ...@@ -368,10 +368,10 @@ issize_t sip_header_field_d(su_home_t *home, sip_header_t *h, char *s, isize_t s
size_t n = span_lws(s); size_t n = span_lws(s);
s += n; slen -= n; s += n; slen -= n;
for (n = slen - 1; n >= 0 && IS_LWS(s[n]); n--) for (n = slen; n >= 1 && IS_LWS(s[n - 1]); n--)
; ;
s[n + 1] = '\0'; s[n] = '\0';
return h->sh_class->hc_parse(home, h, s, slen); return h->sh_class->hc_parse(home, h, s, slen);
} }
......
...@@ -406,7 +406,7 @@ int soa_base_set_params(soa_session_t *ss, tagi_t const *tags) ...@@ -406,7 +406,7 @@ int soa_base_set_params(soa_session_t *ss, tagi_t const *tags)
int af; int af;
char const *media_address, *hold; char const *media_address, *hold;
unsigned rtp_select, rtp_sort; int rtp_select, rtp_sort;
int rtp_mismatch; int rtp_mismatch;
int srtp_enable, srtp_confidentiality, srtp_integrity; int srtp_enable, srtp_confidentiality, srtp_integrity;
......
...@@ -208,7 +208,7 @@ struct sres_server { ...@@ -208,7 +208,7 @@ struct sres_server {
time_t dns_error; time_t dns_error;
}; };
HTABLE_DECLARE(sres_qtable, qt, sres_query_t); HTABLE_DECLARE_WITH(sres_qtable, qt, sres_query_t, unsigned, size_t);
struct sres_resolver_s { struct sres_resolver_s {
su_home_t res_home[1]; su_home_t res_home[1];
...@@ -278,7 +278,7 @@ struct sres_config { ...@@ -278,7 +278,7 @@ struct sres_config {
}; };
struct sres_query_s { struct sres_query_s {
hash_value_t q_hash; unsigned q_hash;
sres_resolver_t*q_res; sres_resolver_t*q_res;
sres_answer_f *q_callback; sres_answer_f *q_callback;
sres_context_t *q_context; sres_context_t *q_context;
...@@ -346,7 +346,7 @@ enum { ...@@ -346,7 +346,7 @@ enum {
SRES_HDR_RCODE = (15 << 0) /* mask of return code */ SRES_HDR_RCODE = (15 << 0) /* mask of return code */
}; };
HTABLE_PROTOS(sres_qtable, qt, sres_query_t); HTABLE_PROTOS_WITH(sres_qtable, qt, sres_query_t, unsigned, size_t);
#define CHOME(cache) ((su_home_t *)(cache)) #define CHOME(cache) ((su_home_t *)(cache))
...@@ -1537,7 +1537,8 @@ sres_resolver_destructor(void *arg) ...@@ -1537,7 +1537,8 @@ sres_resolver_destructor(void *arg)
#define Q_PRIME 3571 #define Q_PRIME 3571
#define SRES_QUERY_HASH(q) ((q)->q_hash) #define SRES_QUERY_HASH(q) ((q)->q_hash)
HTABLE_BODIES(sres_qtable, qt, sres_query_t, SRES_QUERY_HASH); HTABLE_BODIES_WITH(sres_qtable, qt, sres_query_t, SRES_QUERY_HASH,
unsigned, size_t);
/** Allocate a query structure */ /** Allocate a query structure */
static static
...@@ -1676,20 +1677,20 @@ sres_sockaddr2string(sres_resolver_t *res, ...@@ -1676,20 +1677,20 @@ sres_sockaddr2string(sres_resolver_t *res,
#if HAVE_SIN6 #if HAVE_SIN6
else if (addr->sa_family == AF_INET6) { else if (addr->sa_family == AF_INET6) {
struct sockaddr_in6 const *sin6 = (struct sockaddr_in6 *)addr; struct sockaddr_in6 const *sin6 = (struct sockaddr_in6 *)addr;
int addrsize = sizeof(sin6->sin6_addr.s6_addr); size_t addrsize = sizeof(sin6->sin6_addr.s6_addr);
char *postfix; char *postfix;
int required; size_t required;
int i; size_t i;
if (res->res_config->c_opt.ip6int) if (res->res_config->c_opt.ip6int)
postfix = "ip6.int."; postfix = "ip6.int.";
else else
postfix = "ip6.arpa."; postfix = "ip6.arpa.";
required = addrsize * 4 + (int)strlen(postfix); required = addrsize * 4 + strlen(postfix);
if (namelen <= required) if (namelen <= required)
return required; return (int)required;
for (i = 0; i < addrsize; i++) { for (i = 0; i < addrsize; i++) {
uint8_t byte = sin6->sin6_addr.s6_addr[addrsize - i - 1]; uint8_t byte = sin6->sin6_addr.s6_addr[addrsize - i - 1];
...@@ -1705,7 +1706,7 @@ sres_sockaddr2string(sres_resolver_t *res, ...@@ -1705,7 +1706,7 @@ sres_sockaddr2string(sres_resolver_t *res,
strcpy(name + 4 * i, postfix); strcpy(name + 4 * i, postfix);
return required; return (int)required;
} }
#endif /* HAVE_SIN6 */ #endif /* HAVE_SIN6 */
else { else {
...@@ -2683,7 +2684,7 @@ sres_query_report_error(sres_query_t *q, ...@@ -2683,7 +2684,7 @@ sres_query_report_error(sres_query_t *q,
*/ */
void sres_resolver_timer(sres_resolver_t *res, int dummy) void sres_resolver_timer(sres_resolver_t *res, int dummy)
{ {
int i; size_t i;
sres_query_t *q; sres_query_t *q;
time_t now, retry_time; time_t now, retry_time;
...@@ -3059,7 +3060,7 @@ sres_resolver_report_error(sres_resolver_t *res, ...@@ -3059,7 +3060,7 @@ sres_resolver_report_error(sres_resolver_t *res,
/* Report error to queries */ /* Report error to queries */
sres_server_t *dns; sres_server_t *dns;
sres_query_t *q; sres_query_t *q;
int i; size_t i;
dns = sres_server_by_socket(res, socket); dns = sres_server_by_socket(res, socket);
...@@ -3203,8 +3204,8 @@ sres_decode_msg(sres_resolver_t *res, ...@@ -3203,8 +3204,8 @@ sres_decode_msg(sres_resolver_t *res,
sres_query_t *query = NULL, **hq; sres_query_t *query = NULL, **hq;
su_home_t *chome = CHOME(res->res_cache); su_home_t *chome = CHOME(res->res_cache);
hash_value_t hash; hash_value_t hash;
int i, err; int err;
unsigned total, errorcount = 0; unsigned i, total, errorcount = 0;
assert(res && m && return_answers); assert(res && m && return_answers);
......
...@@ -84,7 +84,7 @@ typedef unsigned _int32 uint32_t; ...@@ -84,7 +84,7 @@ typedef unsigned _int32 uint32_t;
typedef struct sres_rr_hash_entry_s sres_rr_hash_entry_t; typedef struct sres_rr_hash_entry_s sres_rr_hash_entry_t;
HTABLE_DECLARE(sres_htable, ht, sres_rr_hash_entry_t); HTABLE_DECLARE_WITH(sres_htable, ht, sres_rr_hash_entry_t, unsigned, size_t);
struct sres_rr_hash_entry_s { struct sres_rr_hash_entry_s {
unsigned int rr_hash_key; unsigned int rr_hash_key;
...@@ -124,7 +124,7 @@ void _sres_cache_free_answers(sres_cache_t *cache, sres_record_t **answers); ...@@ -124,7 +124,7 @@ void _sres_cache_free_answers(sres_cache_t *cache, sres_record_t **answers);
static unsigned sres_hash_key(const char *string); static unsigned sres_hash_key(const char *string);
HTABLE_PROTOS(sres_htable, ht, sres_rr_hash_entry_t); HTABLE_PROTOS_WITH(sres_htable, ht, sres_rr_hash_entry_t, unsigned, size_t);
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
...@@ -197,7 +197,7 @@ int sres_cache_get(sres_cache_t *cache, ...@@ -197,7 +197,7 @@ int sres_cache_get(sres_cache_t *cache,
rr = (*rr_iter)->rr; rr = (*rr_iter)->rr;
if (rr != NULL && if (rr != NULL &&
now - (*rr_iter)->rr_received <= rr->sr_ttl && (uint32_t)(now - (*rr_iter)->rr_received) <= rr->sr_ttl &&
(type == sres_qtype_any || rr->sr_type == type) && (type == sres_qtype_any || rr->sr_type == type) &&
rr->sr_name != NULL && rr->sr_name != NULL &&
strcasecmp(rr->sr_name, domain) == 0) strcasecmp(rr->sr_name, domain) == 0)
...@@ -224,7 +224,7 @@ int sres_cache_get(sres_cache_t *cache, ...@@ -224,7 +224,7 @@ int sres_cache_get(sres_cache_t *cache,
rr = (*rr_iter)->rr; rr = (*rr_iter)->rr;
if (rr != NULL && if (rr != NULL &&
now - (*rr_iter)->rr_received <= rr->sr_ttl && (uint32_t)(now - (*rr_iter)->rr_received) <= rr->sr_ttl &&
(type == sres_qtype_any || rr->sr_type == type) && (type == sres_qtype_any || rr->sr_type == type) &&
rr->sr_name != NULL && rr->sr_name != NULL &&
strcasecmp(rr->sr_name, domain) == 0) { strcasecmp(rr->sr_name, domain) == 0) {
...@@ -253,9 +253,8 @@ sres_cache_alloc_record(sres_cache_t *cache, ...@@ -253,9 +253,8 @@ sres_cache_alloc_record(sres_cache_t *cache,
sres_record_t const *template, sres_record_t const *template,
size_t extra) size_t extra)
{ {
int size;
sres_record_t *sr; sres_record_t *sr;
size_t name_length; size_t size, name_length;
size = template->sr_size; size = template->sr_size;
...@@ -420,7 +419,7 @@ sres_hash_key(const char *string) ...@@ -420,7 +419,7 @@ sres_hash_key(const char *string)
void sres_cache_clean(sres_cache_t *cache, time_t now) void sres_cache_clean(sres_cache_t *cache, time_t now)
{ {
int i; size_t i;
if (now < cache->cache_cleaned + SRES_CACHE_TIMER_INTERVAL) if (now < cache->cache_cleaned + SRES_CACHE_TIMER_INTERVAL)
return; return;
...@@ -447,4 +446,5 @@ void sres_cache_clean(sres_cache_t *cache, time_t now) ...@@ -447,4 +446,5 @@ void sres_cache_clean(sres_cache_t *cache, time_t now)
UNLOCK(cache); UNLOCK(cache);
} }
HTABLE_BODIES(sres_htable, ht, sres_rr_hash_entry_t, SRES_HENTRY_HASH); HTABLE_BODIES_WITH(sres_htable, ht, sres_rr_hash_entry_t, SRES_HENTRY_HASH,
unsigned, size_t);
...@@ -81,9 +81,9 @@ SU_DLL void su_home_preload(su_home_t *h, isize_t n, isize_t size); ...@@ -81,9 +81,9 @@ SU_DLL void su_home_preload(su_home_t *h, isize_t n, isize_t size);
SU_DLL su_home_t *su_home_auto(void *area, isize_t size); SU_DLL su_home_t *su_home_auto(void *area, isize_t size);
#define SU_HOME_AUTO_SIZE(n) \ #define SU_HOME_AUTO_SIZE(n) \
(((n) + ((sizeof(su_home_t) + 7) & ~8) + \ (((n) + ((sizeof(su_home_t) + 7) & (size_t)~8) + \
((3 * sizeof (void *) + 4 * sizeof(unsigned) + \ ((3 * sizeof (void *) + 4 * sizeof(unsigned) + \
7 * (sizeof (long) + sizeof(void *)) + 7) & ~8)) \ 7 * (sizeof (long) + sizeof(void *)) + 7) & (size_t)~8)) \
/ sizeof(su_home_t)) / sizeof(su_home_t))
SU_DLL int su_home_move(su_home_t *dst, su_home_t *src); SU_DLL int su_home_move(su_home_t *dst, su_home_t *src);
......
...@@ -217,7 +217,7 @@ enum { ...@@ -217,7 +217,7 @@ enum {
}; };
#define ALIGNMENT (8) #define ALIGNMENT (8)
#define ALIGN(n) (size_t)(((n) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1)) #define ALIGN(n) (size_t)(((n) + (ALIGNMENT - 1)) & (size_t)~(ALIGNMENT - 1))
#define SIZEBITS (sizeof (size_t) * 8 - 1) #define SIZEBITS (sizeof (size_t) * 8 - 1)
typedef struct { typedef struct {
...@@ -396,7 +396,7 @@ void *sub_alloc(su_home_t *home, ...@@ -396,7 +396,7 @@ void *sub_alloc(su_home_t *home,
{ {
void *data, *preload = NULL; void *data, *preload = NULL;
assert (size >= 0 && size < (1 << 31)); assert (size < (1L << SIZEBITS));
if (sub == NULL || 3 * sub->sub_used > 2 * sub->sub_n) { if (sub == NULL || 3 * sub->sub_used > 2 * sub->sub_n) {
/* Resize the hash table */ /* Resize the hash table */
......
...@@ -965,7 +965,7 @@ int su_port_unregister_all(su_port_t *self, ...@@ -965,7 +965,7 @@ int su_port_unregister_all(su_port_t *self,
*/ */
int su_port_eventmask(su_port_t *self, int index, int socket, int events) int su_port_eventmask(su_port_t *self, int index, int socket, int events)
{ {
unsigned n; int n;
assert(self); assert(self);
assert(SU_PORT_OWN_THREAD(self)); assert(SU_PORT_OWN_THREAD(self));
......
...@@ -581,7 +581,7 @@ static int test_vectors(void) ...@@ -581,7 +581,7 @@ static int test_vectors(void)
} }
#define ALIGNMENT (8) #define ALIGNMENT (8)
#define ALIGN(n) (((n) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1)) #define ALIGN(n) ((size_t)((n) + (ALIGNMENT - 1)) & (size_t)~(ALIGNMENT - 1))
static int test_auto(void) static int test_auto(void)
{ {
......
...@@ -335,15 +335,16 @@ static int ...@@ -335,15 +335,16 @@ static int
tport_base_wakeup(tport_t *self, int events), tport_base_wakeup(tport_t *self, int events),
tport_connected(su_root_magic_t *m, su_wait_t *w, tport_t *self), tport_connected(su_root_magic_t *m, su_wait_t *w, tport_t *self),
tport_resolve(tport_t *self, msg_t *msg, tp_name_t const *tpn), tport_resolve(tport_t *self, msg_t *msg, tp_name_t const *tpn),
tport_vsend(tport_t *self, msg_t *msg, tp_name_t const *tpn,
msg_iovec_t iov[], size_t iovused,
struct sigcomp_compartment *cc),
tport_send_error(tport_t *, msg_t *, tp_name_t const *), tport_send_error(tport_t *, msg_t *, tp_name_t const *),
tport_queue(tport_t *self, msg_t *msg), tport_queue(tport_t *self, msg_t *msg),
tport_queue_rest(tport_t *self, msg_t *msg, msg_iovec_t iov[], ssize_t iovused), tport_queue_rest(tport_t *self, msg_t *msg, msg_iovec_t iov[], ssize_t iovused),
tport_pending_error(tport_t *self, su_sockaddr_t const *dst, int error), tport_pending_error(tport_t *self, su_sockaddr_t const *dst, int error),
tport_pending_errmsg(tport_t *self, msg_t *msg, int error); tport_pending_errmsg(tport_t *self, msg_t *msg, int error);
static ssize_t tport_vsend(tport_t *self, msg_t *msg, tp_name_t const *tpn,
msg_iovec_t iov[], size_t iovused,
struct sigcomp_compartment *cc);
tport_t *tport_by_addrinfo(tport_primary_t const *pri, tport_t *tport_by_addrinfo(tport_primary_t const *pri,
su_addrinfo_t const *ai, su_addrinfo_t const *ai,
tp_name_t const *tpn); tp_name_t const *tpn);
...@@ -3210,12 +3211,12 @@ int tport_send_msg(tport_t *self, msg_t *msg, ...@@ -3210,12 +3211,12 @@ int tport_send_msg(tport_t *self, msg_t *msg,
} }
static static
int tport_vsend(tport_t *self, ssize_t tport_vsend(tport_t *self,
msg_t *msg, msg_t *msg,
tp_name_t const *tpn, tp_name_t const *tpn,
msg_iovec_t iov[], msg_iovec_t iov[],
size_t iovused, size_t iovused,
struct sigcomp_compartment *cc) struct sigcomp_compartment *cc)
{ {
ssize_t n; ssize_t n;
su_addrinfo_t *ai = msg_addrinfo(msg); su_addrinfo_t *ai = msg_addrinfo(msg);
...@@ -3573,10 +3574,10 @@ void tport_send_event(tport_t *self) ...@@ -3573,10 +3574,10 @@ void tport_send_event(tport_t *self)
static static
void tport_send_queue(tport_t *self) void tport_send_queue(tport_t *self)
{ {
size_t i, n, total;
msg_t *msg; msg_t *msg;
msg_iovec_t *iov; msg_iovec_t *iov;
size_t iovused; size_t i, total, iovused;
ssize_t n;
unsigned short qhead = self->tp_qhead, N = self->tp_params->tpp_qsize; unsigned short qhead = self->tp_qhead, N = self->tp_params->tpp_qsize;
su_time_t now; su_time_t now;
......
...@@ -189,8 +189,6 @@ void tport_log_msg(tport_t *self, msg_t *msg, ...@@ -189,8 +189,6 @@ void tport_log_msg(tport_t *self, msg_t *msg,
"------------------------------------------------------------------------\n" "------------------------------------------------------------------------\n"
#define MAX_LINELEN 2047 #define MAX_LINELEN 2047
if (iovlen < 0) return;
for (i = n = 0; i < iovlen && i < 80; i++) for (i = n = 0; i < iovlen && i < 80; i++)
n += iov[i].mv_len; n += iov[i].mv_len;
......
...@@ -177,18 +177,18 @@ int tport_udp_init_client(tport_primary_t *pri, ...@@ -177,18 +177,18 @@ int tport_udp_init_client(tport_primary_t *pri,
static void tport_check_trunc(tport_t *tp, su_addrinfo_t *ai) static void tport_check_trunc(tport_t *tp, su_addrinfo_t *ai)
{ {
#if HAVE_MSG_TRUNC #if HAVE_MSG_TRUNC
int n; ssize_t n;
char buffer[2]; char buffer[2];
su_sockaddr_t su[1]; su_sockaddr_t su[1];
socklen_t sulen = sizeof su; socklen_t sulen = sizeof su;
n = sendto(tp->tp_socket, n = su_sendto(tp->tp_socket,
"TEST", 4, 0, "TEST", 4, 0,
(void *)ai->ai_addr, ai->ai_addrlen); (void *)ai->ai_addr, ai->ai_addrlen);
for (;;) { for (;;) {
n = recvfrom(tp->tp_socket, buffer, sizeof buffer, MSG_TRUNC, n = su_recvfrom(tp->tp_socket, buffer, sizeof buffer, MSG_TRUNC,
(void *)&su, &sulen); (void *)&su, &sulen);
if (n > sizeof buffer) { if (n > sizeof buffer) {
tp->tp_trunc = 1; tp->tp_trunc = 1;
......
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