TT#111150 convert str.len to size_t

This makes the type in line with string(3) functions and eliminates some
compiler warnings.

Also update the related bencode data type.

Change-Id: I7ef4024f4b5a0f737b3dbe03bcd078032395bce6
pull/1252/head
Richard Fuchs 4 years ago
parent 61a852fa71
commit d5d0a3a994

@ -201,7 +201,7 @@ static void __bencode_container_add(bencode_item_t *parent, bencode_item_t *chil
}
static bencode_item_t *__bencode_string_alloc(bencode_buffer_t *buf, const void *base,
int str_len, int iov_len, int iov_cnt, bencode_type_t type)
size_t str_len, size_t iov_len, unsigned int iov_cnt, bencode_type_t type)
{
bencode_item_t *ret;
int len_len;
@ -210,7 +210,7 @@ static bencode_item_t *__bencode_string_alloc(bencode_buffer_t *buf, const void
ret = __bencode_item_alloc(buf, 7);
if (!ret)
return NULL;
len_len = sprintf(ret->__buf, "%d:", str_len);
len_len = sprintf(ret->__buf, "%zu:", str_len);
ret->type = type;
ret->iov[0].iov_base = ret->__buf;
@ -223,7 +223,7 @@ static bencode_item_t *__bencode_string_alloc(bencode_buffer_t *buf, const void
return ret;
}
bencode_item_t *bencode_string_len_dup(bencode_buffer_t *buf, const char *s, int len) {
bencode_item_t *bencode_string_len_dup(bencode_buffer_t *buf, const char *s, size_t len) {
char *sd = bencode_buffer_alloc(buf, len);
if (!sd)
return NULL;
@ -231,11 +231,13 @@ bencode_item_t *bencode_string_len_dup(bencode_buffer_t *buf, const char *s, int
return bencode_string_len(buf, sd, len);
}
bencode_item_t *bencode_string_len(bencode_buffer_t *buf, const char *s, int len) {
bencode_item_t *bencode_string_len(bencode_buffer_t *buf, const char *s, size_t len) {
return __bencode_string_alloc(buf, s, len, len, 1, BENCODE_STRING);
}
bencode_item_t *bencode_string_iovec(bencode_buffer_t *buf, const struct iovec *iov, int iov_cnt, int str_len) {
bencode_item_t *bencode_string_iovec(bencode_buffer_t *buf, const struct iovec *iov, unsigned int iov_cnt,
size_t str_len)
{
int i;
if (iov_cnt < 0)
@ -275,7 +277,7 @@ bencode_item_t *bencode_integer(bencode_buffer_t *buf, long long int i) {
return ret;
}
bencode_item_t *bencode_dictionary_add_len(bencode_item_t *dict, const char *key, int keylen, bencode_item_t *val) {
bencode_item_t *bencode_dictionary_add_len(bencode_item_t *dict, const char *key, size_t keylen, bencode_item_t *val) {
bencode_item_t *str;
if (!dict || !val)
@ -337,7 +339,7 @@ static int __bencode_iovec_dump(struct iovec *out, bencode_item_t *item) {
return item->iov_cnt;
}
static int __bencode_str_dump(char *out, bencode_item_t *item) {
static size_t __bencode_str_dump(char *out, bencode_item_t *item) {
char *orig = out;
bencode_item_t *child;
@ -376,9 +378,9 @@ struct iovec *bencode_iovec(bencode_item_t *root, int *cnt, unsigned int head, u
return ret;
}
char *bencode_collapse(bencode_item_t *root, int *len) {
char *bencode_collapse(bencode_item_t *root, size_t *len) {
char *ret;
int l;
size_t l;
if (!root)
return NULL;
@ -393,7 +395,7 @@ char *bencode_collapse(bencode_item_t *root, int *len) {
return ret;
}
char *bencode_collapse_dup(bencode_item_t *root, int *len) {
char *bencode_collapse_dup(bencode_item_t *root, size_t *len) {
char *ret;
int l;
@ -641,13 +643,13 @@ static bencode_item_t *__bencode_decode(bencode_buffer_t *buf, const char *s, co
}
}
bencode_item_t *bencode_decode(bencode_buffer_t *buf, const char *s, int len) {
bencode_item_t *bencode_decode(bencode_buffer_t *buf, const char *s, size_t len) {
assert(s != NULL);
return __bencode_decode(buf, s, s + len);
}
static int __bencode_dictionary_key_match(bencode_item_t *key, const char *keystr, int keylen) {
static int __bencode_dictionary_key_match(bencode_item_t *key, const char *keystr, size_t keylen) {
assert(key->type == BENCODE_STRING);
if (keylen != key->iov[1].iov_len)
@ -658,7 +660,7 @@ static int __bencode_dictionary_key_match(bencode_item_t *key, const char *keyst
return 1;
}
bencode_item_t *bencode_dictionary_get_len(bencode_item_t *dict, const char *keystr, int keylen) {
bencode_item_t *bencode_dictionary_get_len(bencode_item_t *dict, const char *keystr, size_t keylen) {
bencode_item_t *key;
unsigned int bucket, i;
struct __bencode_hash *hash;
@ -710,17 +712,17 @@ void bencode_buffer_destroy_add(bencode_buffer_t *buf, free_func_t func, void *p
buf->free_list = li;
}
static int __bencode_string(const char *s, int offset, int len) {
int pos;
unsigned long long sl;
static int __bencode_string(const char *s, size_t offset, size_t len) {
size_t pos;
unsigned long sl;
char *end;
for (pos = offset + 1; s[pos] != ':' && isdigit(s[pos]) && pos < len; ++pos);
for (pos = offset; s[pos] != ':' && isdigit(s[pos]) && pos < len; ++pos);
if (pos == len)
return -1;
sl = strtoul(s + offset + 1, &end, 10);
if (s + offset + 1 == end || end != s + pos)
sl = strtoul(s + offset, &end, 10);
if (s + offset == end || end != s + pos)
return -2;
if (pos + sl > len)
@ -729,8 +731,8 @@ static int __bencode_string(const char *s, int offset, int len) {
return pos + sl + 1;
}
static int __bencode_integer(const char *s, int offset, int len) {
int pos;
static int __bencode_integer(const char *s, size_t offset, size_t len) {
size_t pos;
if (s[offset + 1] == '-') {
if (offset + 3 < len && s[offset + 2] == '0' && s[offset + 3] == 'e') {
@ -759,9 +761,9 @@ static int __bencode_integer(const char *s, int offset, int len) {
return pos + 1;
}
static int __bencode_next(const char *s, int offset, int len);
static int __bencode_next(const char *s, size_t offset, size_t len);
static int __bencode_list(const char *s, int offset, int len) {
static int __bencode_list(const char *s, size_t offset, size_t len) {
for (++offset; s[offset] != 'e' && offset < len;) {
offset = __bencode_next(s, offset, len);
if (offset < 0)
@ -774,9 +776,9 @@ static int __bencode_list(const char *s, int offset, int len) {
return offset + 1;
}
static int __bencode_dictionary(const char *s, int offset, int len) {
static int __bencode_dictionary(const char *s, size_t offset, size_t len) {
for (++offset; s[offset] != 'e' && offset < len;) {
offset = __bencode_string(s, offset - 1, len);
offset = __bencode_string(s, offset, len);
if (offset < 0)
return offset;
offset = __bencode_next(s, offset, len);
@ -790,7 +792,7 @@ static int __bencode_dictionary(const char *s, int offset, int len) {
return offset + 1;
}
static int __bencode_next(const char *s, int offset, int len) {
static int __bencode_next(const char *s, size_t offset, size_t len) {
if (offset >= len)
return -1;
switch(s[offset]) {
@ -810,11 +812,11 @@ static int __bencode_next(const char *s, int offset, int len) {
case '7':
case '8':
case '9':
return __bencode_string(s, offset - 1, len);
return __bencode_string(s, offset, len);
}
return -2;
}
int bencode_valid(const char *s, int len) {
int bencode_valid(const char *s, size_t len) {
return __bencode_next(s, 0, len);
}

@ -2558,7 +2558,7 @@ void call_destroy(struct call *c) {
(unsigned int) (rtpe_now.tv_sec - ml->created) % 60,
STR_FMT_M(&ml->viabranch),
ml->active_dialogue ? rtpe_common_config_ptr->log_mark_prefix : "",
ml->active_dialogue ? ml->active_dialogue->tag.len : 6,
ml->active_dialogue ? (int) ml->active_dialogue->tag.len : 6,
ml->active_dialogue ? ml->active_dialogue->tag.s : "(none)",
ml->active_dialogue ? rtpe_common_config_ptr->log_mark_suffix : "");

@ -577,7 +577,7 @@ static void cli_incoming_list_callid(str *instr, struct cli_writer *cw) {
STR_FMT(&ml->viabranch),
tim_result_duration.tv_sec,
tim_result_duration.tv_usec,
ml->active_dialogue ? ml->active_dialogue->tag.len : 6,
ml->active_dialogue ? (int) ml->active_dialogue->tag.len : 6,
ml->active_dialogue ? ml->active_dialogue->tag.s : "(none)");
for (k = ml->medias.head; k; k = k->next) {

@ -2132,7 +2132,7 @@ static int __handler_func_supplemental(struct codec_handler *h, struct media_pac
// create new packet and insert it into sequencer queue
ilogs(transcoding, LOG_DEBUG, "Received %s RTP packet: SSRC %" PRIx32 ", PT %u, seq %u, TS %u, len %i",
ilogs(transcoding, LOG_DEBUG, "Received %s RTP packet: SSRC %" PRIx32 ", PT %u, seq %u, TS %u, len %zu",
h->source_pt.codec_def->rtpname,
ntohl(mp->rtp->ssrc), mp->rtp->m_pt, ntohs(mp->rtp->seq_num),
ntohl(mp->rtp->timestamp), mp->payload.len);
@ -2903,7 +2903,7 @@ static int packet_encoded_rtp(encoder_t *enc, void *u1, void *u2) {
break;
}
ilogs(transcoding, LOG_DEBUG, "Received packet of %i bytes from packetizer", inout.len);
ilogs(transcoding, LOG_DEBUG, "Received packet of %zu bytes from packetizer", inout.len);
// check special payloads
@ -3145,7 +3145,7 @@ static int handler_func_transcode(struct codec_handler *h, struct media_packet *
// create new packet and insert it into sequencer queue
ilogs(transcoding, LOG_DEBUG, "Received RTP packet: SSRC %" PRIx32 ", PT %u, seq %u, TS %u, len %i",
ilogs(transcoding, LOG_DEBUG, "Received RTP packet: SSRC %" PRIx32 ", PT %u, seq %u, TS %u, len %zu",
ntohl(mp->rtp->ssrc), mp->rtp->m_pt, ntohs(mp->rtp->seq_num),
ntohl(mp->rtp->timestamp), mp->payload.len);

@ -495,7 +495,7 @@ int crypto_gen_session_key(struct crypto_context *c, str *out, unsigned char lab
"%02x%02x%02x%02x..., "
"master salt "
"%02x%02x%02x%02x..., "
"label %02x, length %i, result "
"label %02x, length %zu, result "
"%02x%02x%02x%02x...",
c->params.master_key[0],
c->params.master_key[1],

@ -701,7 +701,7 @@ int dtls(struct stream_fd *sfd, const str *s, const endpoint_t *fsin) {
return 0;
if (s)
__DBG("dtls packet input: len %u %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
__DBG("dtls packet input: len %zu %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
s->len,
(unsigned char) s->s[0], (unsigned char) s->s[1], (unsigned char) s->s[2], (unsigned char) s->s[3],
(unsigned char) s->s[4], (unsigned char) s->s[5], (unsigned char) s->s[6], (unsigned char) s->s[7],

@ -114,7 +114,7 @@ int dtmf_do_logging(void) {
int dtmf_event(struct media_packet *mp, str *payload, int clockrate) {
struct telephone_event_payload *dtmf;
if (payload->len < sizeof(*dtmf)) {
ilog(LOG_WARN | LOG_FLAG_LIMIT, "Short DTMF event packet (len %u)", payload->len);
ilog(LOG_WARN | LOG_FLAG_LIMIT, "Short DTMF event packet (len %zu)", payload->len);
return -1;
}
dtmf = (void *) payload->s;

@ -550,9 +550,9 @@ static void options(int *argc, char ***argv) {
if ((errno == ERANGE && (uint_keyspace_db == ULONG_MAX)) ||
(errno != 0 && uint_keyspace_db == 0)) {
ilog(LOG_ERR, "Fail adding keyspace '%.*s' to redis notifications; errono=%d\n", str_keyspace_db.len, str_keyspace_db.s, errno);
ilog(LOG_ERR, "Fail adding keyspace '" STR_FORMAT "' to redis notifications; errono=%d\n", STR_FMT(&str_keyspace_db), errno);
} else if (endptr == str_keyspace_db.s) {
ilog(LOG_ERR, "Fail adding keyspace '%.*s' to redis notifications; no digits found\n", str_keyspace_db.len, str_keyspace_db.s);
ilog(LOG_ERR, "Fail adding keyspace '" STR_FORMAT "' to redis notifications; no digits found\n", STR_FMT(&str_keyspace_db));
} else {
g_queue_push_tail(&rtpe_config.redis_subscribed_keyspaces, GUINT_TO_POINTER(uint_keyspace_db));
}

@ -425,7 +425,7 @@ static void sdp_after_pcap(struct recording *recording, GString *str, struct cal
// descriptor does not. Make sure to flush any unwritten contents
// so the file contents appear in order.
if (ml->label.len) {
fprintf(meta_fp, "\nLabel: %*s", ml->label.len, ml->label.s);
fprintf(meta_fp, "\nLabel: " STR_FORMAT, STR_FMT(&ml->label));
}
fprintf(meta_fp, "\nTimestamp started ms: ");
fprintf(meta_fp, "%.3lf", ml->started.tv_sec*1000.0+ml->started.tv_usec/1000.0);

@ -920,7 +920,7 @@ static void redis_delete_async_call_json(struct call *c, struct redis *r) {
redis_command = g_strdup_printf("SELECT %i", c->redis_hosted_db);
g_queue_push_tail(&r->async_queue, redis_command);
redis_command = g_strdup_printf("DEL %.*s", c->callid.len, c->callid.s);
redis_command = g_strdup_printf("DEL " STR_FORMAT, STR_FMT(&c->callid));
g_queue_push_tail(&r->async_queue, redis_command);
}

@ -568,11 +568,11 @@ int t38_gateway_input_udptl(struct t38_gateway *tg, const str *buf) {
return 0;
if (buf->len < 4) {
ilog(LOG_INFO | LOG_FLAG_LIMIT, "Ignoring short UDPTL packet (%i bytes)", buf->len);
ilog(LOG_INFO | LOG_FLAG_LIMIT, "Ignoring short UDPTL packet (%zu bytes)", buf->len);
return 0;
}
ilog(LOG_DEBUG, "Processing %i UDPTL bytes", buf->len);
ilog(LOG_DEBUG, "Processing %zu UDPTL bytes", buf->len);
str s = *buf;
str piece;
@ -587,7 +587,7 @@ int t38_gateway_input_udptl(struct t38_gateway *tg, const str *buf) {
if (__get_udptl(&piece, &s))
goto err;
ilog(LOG_DEBUG, "Received primary IFP packet, len %i, seq %i", piece.len, seq);
ilog(LOG_DEBUG, "Received primary IFP packet, len %zu, seq %i", piece.len, seq);
str primary = piece;
up = __make_udptl_packet(&primary, seq);
@ -636,7 +636,7 @@ int t38_gateway_input_udptl(struct t38_gateway *tg, const str *buf) {
// ignore zero-length packets
if (!piece.len)
continue;
ilog(LOG_DEBUG, "Received secondary IFP packet, len %i, seq %i", piece.len,
ilog(LOG_DEBUG, "Received secondary IFP packet, len %zu, seq %i", piece.len,
seq - 1 - i);
up = __make_udptl_packet(&piece, seq - 1 - i);
packet_sequencer_insert(&tg->sequencer, &up->p);
@ -744,7 +744,7 @@ seq_ok:;
if (!up)
break;
ilog(LOG_DEBUG, "Processing %i IFP bytes, seq %i", up->s->len, up->p.seq);
ilog(LOG_DEBUG, "Processing %zu IFP bytes, seq %i", up->s->len, up->p.seq);
t38_core_rx_ifp_packet(t38, (uint8_t *) up->s->s, up->s->len, up->p.seq);

@ -31,7 +31,7 @@ struct bencode_item {
bencode_type_t type;
struct iovec iov[2]; /* when decoding, iov[1] contains the contents of a string object */
unsigned int iov_cnt;
unsigned int str_len; /* length of the whole ENCODED object. NOT the length of a byte string */
size_t str_len; /* length of the whole ENCODED object. NOT the length of a byte string */
long long int value; /* when decoding an integer, contains the value; otherwise used internally */
bencode_item_t *parent, *child, *last_child, *sibling;
bencode_buffer_t *buffer;
@ -106,13 +106,13 @@ INLINE bencode_item_t *bencode_dictionary_add(bencode_item_t *dict, const char *
INLINE bencode_item_t *bencode_dictionary_str_add(bencode_item_t *dict, const str *key, bencode_item_t *val);
/* Identical to bencode_dictionary_add() but doesn't require the key string to be null-terminated */
bencode_item_t *bencode_dictionary_add_len(bencode_item_t *dict, const char *key, int keylen, bencode_item_t *val);
bencode_item_t *bencode_dictionary_add_len(bencode_item_t *dict, const char *key, size_t keylen, bencode_item_t *val);
/* Convenience function to add a string value to a dictionary, possibly duplicated into the
* bencode_buffer_t object. */
INLINE bencode_item_t *bencode_dictionary_add_string(bencode_item_t *dict, const char *key, const char *val);
INLINE bencode_item_t *bencode_dictionary_add_string_dup(bencode_item_t *dict, const char *key, const char *val);
INLINE bencode_item_t *bencode_dictionary_add_string_len(bencode_item_t *dict, const char *key, const char *val, int len);
INLINE bencode_item_t *bencode_dictionary_add_string_len(bencode_item_t *dict, const char *key, const char *val, size_t len);
/* Ditto, but for a "str" object */
INLINE bencode_item_t *bencode_dictionary_add_str(bencode_item_t *dict, const char *key, const str *val);
@ -122,7 +122,7 @@ INLINE bencode_item_t *bencode_dictionary_add_str_dup(bencode_item_t *dict, cons
/* Ditto, but adds a string created through an iovec array to the dictionary. See
* bencode_string_iovec(). */
INLINE bencode_item_t *bencode_dictionary_add_iovec(bencode_item_t *dict, const char *key,
const struct iovec *iov, int iov_cnt, int str_len);
const struct iovec *iov, unsigned int iov_cnt, size_t str_len);
/* Convenience functions to add the respective (newly created) objects to a dictionary */
INLINE bencode_item_t *bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val);
@ -158,7 +158,7 @@ INLINE bencode_item_t *bencode_list_add_dictionary(bencode_item_t *list);
* be allocated.
* Strings are not copied or duplicated, so the string pointed to by "s" must remain valid until
* the complete document is finally encoded or sent out. */
bencode_item_t *bencode_string_len(bencode_buffer_t *buf, const char *s, int len);
bencode_item_t *bencode_string_len(bencode_buffer_t *buf, const char *s, size_t len);
/* Creates a new byte-string object. The given string must be null-terminated. Otherwise identical
* to bencode_string_len(). */
@ -170,7 +170,7 @@ INLINE bencode_item_t *bencode_str(bencode_buffer_t *buf, const str *s);
/* Identical to the above three functions, but copies the string into the bencode_buffer_t object.
* Thus, the given string doesn't have to remain valid and accessible afterwards. */
bencode_item_t *bencode_string_len_dup(bencode_buffer_t *buf, const char *s, int len);
bencode_item_t *bencode_string_len_dup(bencode_buffer_t *buf, const char *s, size_t len);
INLINE bencode_item_t *bencode_string_dup(bencode_buffer_t *buf, const char *s);
INLINE bencode_item_t *bencode_str_dup(bencode_buffer_t *buf, const str *s);
@ -180,7 +180,7 @@ INLINE bencode_item_t *bencode_str_dup(bencode_buffer_t *buf, const str *s);
* document is encoded. The full length of the string composed of the iovec array is given in the
* "str_len" parameter, which can be negative, in which case the array is iterated to calculate the
* length. */
bencode_item_t *bencode_string_iovec(bencode_buffer_t *buf, const struct iovec *iov, int iov_cnt, int str_len);
bencode_item_t *bencode_string_iovec(bencode_buffer_t *buf, const struct iovec *iov, unsigned int iov_cnt, size_t str_len);
/* Convenience function to compare a string object to a regular C string. Returns 2 if object
* isn't a string object, otherwise returns according to strcmp(). */
@ -230,7 +230,7 @@ struct iovec *bencode_iovec(bencode_item_t *root, int *cnt, unsigned int head, u
* in *len. This is important if the encoded document contains binary data, in which case null
* termination cannot be trusted. The returned string is freed when the corresponding
* bencode_buffer_t object is destroyed. */
char *bencode_collapse(bencode_item_t *root, int *len);
char *bencode_collapse(bencode_item_t *root, size_t *len);
/* Identical to bencode_collapse() but fills in a "str" object. Returns "out". */
static str *bencode_collapse_str(bencode_item_t *root, str *out);
@ -239,7 +239,7 @@ static str *bencode_collapse_str(bencode_item_t *root, str *out);
* a bencode_buffer_t object, but instead using the function defined as BENCODE_MALLOC (normally
* malloc() or pkg_malloc()), similar to strdup(). Using this function, the bencode_buffer_t
* object can be destroyed, but the returned string remains valid and usable. */
char *bencode_collapse_dup(bencode_item_t *root, int *len);
char *bencode_collapse_dup(bencode_item_t *root, size_t *len);
@ -292,17 +292,17 @@ char *bencode_collapse_dup(bencode_item_t *root, int *len);
*
* All memory is freed when the bencode_buffer_t object is destroyed.
*/
bencode_item_t *bencode_decode(bencode_buffer_t *buf, const char *s, int len);
bencode_item_t *bencode_decode(bencode_buffer_t *buf, const char *s, size_t len);
/* Identical to bencode_decode(), but returns successfully only if the type of the decoded object match
* "expect". */
INLINE bencode_item_t *bencode_decode_expect(bencode_buffer_t *buf, const char *s, int len, bencode_type_t expect);
INLINE bencode_item_t *bencode_decode_expect(bencode_buffer_t *buf, const char *s, size_t len, bencode_type_t expect);
/* Identical to bencode_decode_expect() but takes a "str" argument. */
INLINE bencode_item_t *bencode_decode_expect_str(bencode_buffer_t *buf, const str *s, bencode_type_t expect);
/* Returns the number of bytes that could successfully be decoded from 's', -1 if more bytes are needed or -2 on error */
int bencode_valid(const char *s, int len);
int bencode_valid(const char *s, size_t len);
/*** DICTIONARY LOOKUP & EXTRACTION ***/
@ -313,13 +313,13 @@ int bencode_valid(const char *s, int len);
INLINE bencode_item_t *bencode_dictionary_get(bencode_item_t *dict, const char *key);
/* Identical to bencode_dictionary_get() but doesn't require the key to be null-terminated. */
bencode_item_t *bencode_dictionary_get_len(bencode_item_t *dict, const char *key, int key_len);
bencode_item_t *bencode_dictionary_get_len(bencode_item_t *dict, const char *key, size_t key_len);
/* Identical to bencode_dictionary_get() but returns the value only if its type is a string, and
* returns it as a pointer to the string itself. Returns NULL if the value is of some other type. The
* returned string is NOT null-terminated. Length of the string is returned in *len, which must be a
* valid pointer. The returned string will be valid until dict's bencode_buffer_t object is destroyed. */
INLINE char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, int *len);
INLINE char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, size_t *len);
/* Identical to bencode_dictionary_get_string() but fills in a "str" struct. Returns str->s, which
* may be NULL. */
@ -332,7 +332,7 @@ INLINE int bencode_dictionary_get_strcmp(bencode_item_t *dict, const char *key,
/* Identical to bencode_dictionary_get() but returns the string in a newly allocated buffer (using the
* BENCODE_MALLOC function), which remains valid even after bencode_buffer_t is destroyed. */
INLINE char *bencode_dictionary_get_string_dup(bencode_item_t *dict, const char *key, int *len);
INLINE char *bencode_dictionary_get_string_dup(bencode_item_t *dict, const char *key, size_t *len);
/* Combines bencode_dictionary_get_str() and bencode_dictionary_get_string_dup(). Fills in a "str"
* struct, but copies the string into a newly allocated buffer. Returns str->s. */
@ -400,7 +400,7 @@ INLINE bencode_item_t *bencode_dictionary_add_string(bencode_item_t *dict, const
return bencode_dictionary_add(dict, key, bencode_string(bencode_item_buffer(dict), val));
}
INLINE bencode_item_t *bencode_dictionary_add_string_len(bencode_item_t *dict, const char *key, const char *val, int len) {
INLINE bencode_item_t *bencode_dictionary_add_string_len(bencode_item_t *dict, const char *key, const char *val, size_t len) {
if (!val)
return NULL;
return bencode_dictionary_add(dict, key, bencode_string_len(bencode_item_buffer(dict), val, len));
@ -476,7 +476,7 @@ INLINE bencode_item_t *bencode_dictionary_get(bencode_item_t *dict, const char *
return bencode_dictionary_get_len(dict, key, strlen(key));
}
INLINE char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, int *len) {
INLINE char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, size_t *len) {
bencode_item_t *val;
val = bencode_dictionary_get(dict, key);
if (!val || val->type != BENCODE_STRING)
@ -492,7 +492,7 @@ INLINE char *bencode_dictionary_get_str(bencode_item_t *dict, const char *key, s
return str->s;
}
INLINE char *bencode_dictionary_get_string_dup(bencode_item_t *dict, const char *key, int *len) {
INLINE char *bencode_dictionary_get_string_dup(bencode_item_t *dict, const char *key, size_t *len) {
const char *s;
char *ret;
s = bencode_dictionary_get_string(dict, key, len);
@ -542,7 +542,7 @@ INLINE long long int bencode_dictionary_get_int_str(bencode_item_t *dict, const
return ret;
}
INLINE bencode_item_t *bencode_decode_expect(bencode_buffer_t *buf, const char *s, int len, bencode_type_t expect) {
INLINE bencode_item_t *bencode_decode_expect(bencode_buffer_t *buf, const char *s, size_t len, bencode_type_t expect) {
bencode_item_t *ret;
ret = bencode_decode(buf, s, len);
if (!ret || ret->type != expect)
@ -593,7 +593,7 @@ INLINE str *bencode_get_str(bencode_item_t *in, str *out) {
}
INLINE bencode_item_t *bencode_dictionary_add_iovec(bencode_item_t *dict, const char *key,
const struct iovec *iov, int iov_cnt, int str_len)
const struct iovec *iov, unsigned int iov_cnt, size_t str_len)
{
return bencode_dictionary_add(dict, key, bencode_string_iovec(bencode_item_buffer(dict), iov, iov_cnt, str_len));
}

@ -1928,7 +1928,7 @@ static int amr_decoder_input(decoder_t *dec, const str *data, GQueue *out) {
goto err;
// add TOC byte
str_shift(&frame, -1);
str_unshift(&frame, 1);
frame.s[0] = toc_byte & 0x7c; // strip F bit, keep FT and Q, zero padding (01111100)
if (dec->codec_options.amr.octet_aligned && (bits % 8) != 0) {
@ -2284,7 +2284,7 @@ static const char *dtmf_decoder_init(decoder_t *dec, const str *fmtp, const str
static int dtmf_decoder_input(decoder_t *dec, const str *data, GQueue *out) {
struct telephone_event_payload *dtmf;
if (data->len < sizeof(*dtmf)) {
ilog(LOG_WARN | LOG_FLAG_LIMIT, "Short DTMF event packet (len %u)", data->len);
ilog(LOG_WARN | LOG_FLAG_LIMIT, "Short DTMF event packet (len %zu)", data->len);
return -1;
}
dtmf = (void *) data->s;

@ -69,7 +69,7 @@ char *rand_hex_str(char *rand_str, int num_bytes) {
static const char *hex_chars = "0123456789abcdef";
int str_uri_encode_len(char *out, const char *in, int len) {
size_t str_uri_encode_len(char *out, const char *in, size_t len) {
const char *end = in + len;
char *ori_out = out;
@ -89,7 +89,7 @@ int str_uri_encode_len(char *out, const char *in, int len) {
return out - ori_out;
}
str *str_uri_decode_len(const char *in, int in_len) {
str *str_uri_decode_len(const char *in, size_t in_len) {
const char *end = in + in_len;
str *ret = str_alloc(in_len);
char *outp = ret->s;

@ -13,7 +13,7 @@
struct _str {
char *s;
int len;
size_t len;
};
typedef struct _str str;
@ -22,9 +22,9 @@ typedef struct _str str;
#define STR_FORMAT "%.*s"
#define STR_FORMAT_M "%s%.*s%s"
#define STR_FMT(str) (str)->len, (str)->s
#define STR_FMT(str) (int) (str)->len, (str)->s
#define STR_FMT_M(str) FMT_M(STR_FMT(str))
#define STR_FMT0(str) ((str) ? (str)->len : 6), ((str) ? (str)->s : "(NULL)")
#define STR_FMT0(str) ((str) ? (int) (str)->len : 6), ((str) ? (str)->s : "(NULL)")
#define STR_FMT0_M(str) FMT_M(STR_FMT0(str))
#define G_STR_FMT(gstr) (int) (gstr)->len, (gstr)->str // for glib GString
@ -48,7 +48,7 @@ INLINE char *str_chr_str(str *out, const str *s, int c);
/* compares a str to a regular string */
INLINE int str_cmp(const str *a, const char *b);
/* compares a str to a non-null-terminated string */
INLINE int str_cmp_len(const str *a, const char *b, int len);
INLINE int str_cmp_len(const str *a, const char *b, size_t len);
/* compares two str objects */
INLINE int str_cmp_str(const str *a, const str *b);
INLINE int str_casecmp_str(const str *a, const str *b);
@ -57,23 +57,25 @@ INLINE int str_cmp_str0(const str *a, const str *b);
/* inits a str object from a regular string. returns out */
INLINE str *str_init(str *out, char *s);
/* inits a str object from any binary string. returns out */
INLINE str *str_init_len(str *out, char *s, int len);
INLINE str *str_init_len_assert_len(str *out, char *s, int buflen, int len);
INLINE str *str_init_len(str *out, char *s, size_t len);
INLINE str *str_init_len_assert_len(str *out, char *s, size_t buflen, size_t len);
#define str_init_len_assert(out, s, len) str_init_len_assert_len(out, s, sizeof(s), len)
/* inits a str object from a regular string and duplicates the contents. returns out */
INLINE str *str_init_dup(str *out, char *s);
INLINE str *str_init_dup_str(str *out, const str *s);
INLINE void str_free_dup(str *out);
/* returns new str object with uninitialized buffer large enough to hold `len` characters (+1 for null byte) */
INLINE str *str_alloc(int len);
INLINE str *str_alloc(size_t len);
/* returns new str object allocated with malloc, including buffer */
INLINE str *str_dup(const str *s);
/* shifts pointer by len chars and decrements len. returns -1 if buffer too short, 0 otherwise */
INLINE int str_shift(str *s, int len);
INLINE int str_shift(str *s, size_t len);
/* to revert a previously successful str_shift(). no error checking */
INLINE void str_unshift(str *s, size_t len);
/* eats the supplied string from the beginning of s. returns -1 if string head doesn't match */
INLINE int str_shift_cmp(str *s, const char *);
/* shifts the string by given length and returns the shifted part. returns -1 if string is too short */
INLINE int str_shift_ret(str *s, int len, str *ret);
INLINE int str_shift_ret(str *s, size_t len, str *ret);
/* binary compares str object with memory chunk of equal size */
INLINE int str_memcmp(const str *s, void *m);
/* locate a substring within a string, returns character index or -1 */
@ -112,10 +114,10 @@ INLINE str *str_slice_dup(const str *);
void str_slice_free(void *);
/* saves "in" into "out" pseudo-URI encoded. "out" point to a buffer with sufficient length. returns length */
int str_uri_encode_len(char *out, const char *in, int in_len);
INLINE int str_uri_encode(char *out, const str *in);
size_t str_uri_encode_len(char *out, const char *in, size_t in_len);
INLINE size_t str_uri_encode(char *out, const str *in);
/* reverse of the above. returns newly allocated str + buffer as per str_alloc (must be free'd) */
str *str_uri_decode_len(const char *in, int in_len);
str *str_uri_decode_len(const char *in, size_t in_len);
@ -124,10 +126,10 @@ str *str_uri_decode_len(const char *in, int in_len);
INLINE char *str_end(const str *s) {
return s->s + s->len;
}
INLINE int str_shift(str *s, int len) {
INLINE int str_shift(str *s, size_t len) {
return str_shift_ret(s, len, NULL);
}
INLINE int str_shift_ret(str *s, int len, str *ret) {
INLINE int str_shift_ret(str *s, size_t len, str *ret) {
if (s->len < len)
return -1;
if (ret)
@ -136,8 +138,12 @@ INLINE int str_shift_ret(str *s, int len, str *ret) {
s->len -= len;
return 0;
}
INLINE void str_unshift(str *s, size_t len) {
s->s -= len;
s->len += len;
}
INLINE int str_shift_cmp(str *s, const char *t) {
int len = strlen(t);
size_t len = strlen(t);
if (s->len < len)
return -1;
if (memcmp(s->s, t, len))
@ -162,7 +168,7 @@ INLINE char *str_chr_str(str *out, const str *s, int c) {
str_shift(out, p - out->s);
return out->s;
}
INLINE int str_cmp_len(const str *a, const char *b, int l) {
INLINE int str_cmp_len(const str *a, const char *b, size_t l) {
if (a->len < l)
return -1;
if (a->len > l)
@ -217,12 +223,12 @@ INLINE str *str_init(str *out, char *s) {
out->len = s ? strlen(s) : 0;
return out;
}
INLINE str *str_init_len(str *out, char *s, int len) {
INLINE str *str_init_len(str *out, char *s, size_t len) {
out->s = s;
out->len = len;
return out;
}
INLINE str *str_init_len_assert_len(str *out, char *s, int buflen, int len) {
INLINE str *str_init_len_assert_len(str *out, char *s, size_t buflen, size_t len) {
assert(buflen >= len);
return str_init_len(out, s, len);
}
@ -252,7 +258,7 @@ INLINE void str_free_dup(str *out) {
out->s = NULL;
out->len = 0;
}
INLINE str *str_alloc(int len) {
INLINE str *str_alloc(size_t len) {
str *r;
r = malloc(sizeof(*r) + len + 1);
r->s = ((char *) r) + sizeof(*r);
@ -278,7 +284,8 @@ INLINE str *str_slice_dup(const str *s) {
#define STR_MALLOC_PADDING "xxxxxxxxxxxxxxxx"
INLINE str *__str_vsprintf(const char *fmt, va_list ap) {
char *r;
int l, pl;
int l;
size_t pl;
str *ret;
l = vasprintf(&r, fmt, ap);
@ -294,7 +301,7 @@ INLINE str *__str_vsprintf(const char *fmt, va_list ap) {
str *__str_sprintf(const char *fmt, ...) __attribute__((format(printf,1,2)));
INLINE GString *g_string_new_str(void) {
int pl;
size_t pl;
GString *ret;
ret = g_string_new("");
@ -305,7 +312,7 @@ INLINE GString *g_string_new_str(void) {
}
INLINE str *g_string_free_str(GString *gs) {
str *ret;
int pl;
size_t pl;
pl = strlen(STR_MALLOC_PADDING);
assert(gs->len >= pl);
@ -385,7 +392,7 @@ INLINE int str_token_sep(str *new_token, str *ori_and_remainder, int sep) {
return 0;
}
INLINE int str_uri_encode(char *out, const str *in) {
INLINE size_t str_uri_encode(char *out, const str *in) {
return str_uri_encode_len(out, in->s, in->len);
}

@ -70,7 +70,7 @@ int do_test(const char *input, unsigned int input_len,
ret, result, file, line, argc);
if (ret == 0 && output) {
if (outp.len != output_len)
err("ERROR output len %i instead of %i (%s:%i arg %i)\n",
err("ERROR output len %zu instead of %u (%s:%i arg %i)\n",
outp.len, output_len, file, line, argc);
if (memcmp(outp.s, output, output_len))
err("ERROR output string mismatch (%s:%i arg %i)\n",

Loading…
Cancel
Save