Commit 0654787a authored by Pekka Pessi's avatar Pekka Pessi

su: using isize_t, usize_t, issize_t in API.

Internally using size_t.

darcs-hash:20060906225539-65a35-5ef913b376cf87ae25f10de387ad20fe77b89503.gz
parent bf584ce9
......@@ -251,12 +251,12 @@ SOFIAPUBFUN int su_getmsgsize(su_socket_t s);
/** Scatter-gather send. */
SOFIAPUBFUN
int su_vsend(su_socket_t s, su_iovec_t const iov[], int iovlen, int flags,
su_sockaddr_t const *su, socklen_t sulen);
issize_t su_vsend(su_socket_t, su_iovec_t const iov[], isize_t len, int flags,
su_sockaddr_t const *su, socklen_t sulen);
/** Scatter-gather receive. */
SOFIAPUBFUN
int su_vrecv(su_socket_t s, su_iovec_t iov[], int iovlen, int flags,
su_sockaddr_t *su, socklen_t *sulen);
issize_t su_vrecv(su_socket_t, su_iovec_t iov[], isize_t len, int flags,
su_sockaddr_t *su, socklen_t *sulen);
/** Return local IP address */
SOFIAPUBFUN int su_getlocalip(su_sockaddr_t *sin);
......
......@@ -34,8 +34,8 @@
* @date Created: Thu Aug 19 01:12:25 1999 ppessi
*/
#ifndef SU_CONFIG_H
#include <sofia-sip/su_config.h>
#ifndef SU_TYPES_H
#include <sofia-sip/su_types.h>
#endif
#include <stdarg.h>
......@@ -55,30 +55,30 @@ typedef struct su_alock su_alock_t;
/** Memory home structure */
struct su_home_s {
int suh_size;
int suh_size;
su_block_t *suh_blocks;
su_alock_t *suh_lock;
};
#define SU_HOME_INIT(obj) { 0 }
SU_DLL void *su_home_new(int size)
SU_DLL void *su_home_new(isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_home_ref(su_home_t const *);
SU_DLL int su_home_unref(su_home_t *);
SU_DLL int su_home_desctructor(su_home_t *, void (*)(void *));
SU_DLL void *su_home_clone(su_home_t *parent, int size)
SU_DLL void *su_home_clone(su_home_t *parent, isize_t size)
__attribute__((__malloc__));
SU_DLL int su_home_init(su_home_t *h);
SU_DLL void su_home_deinit(su_home_t *h);
SU_DLL void su_home_preload(su_home_t *h, int n, int size);
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, int size);
SU_DLL su_home_t *su_home_auto(void *area, isize_t size);
#define SU_HOME_AUTO_SIZE(n) \
(((n) + ((sizeof(su_home_t) + 7) & ~8) + \
......@@ -98,20 +98,20 @@ SU_DLL int su_home_mutex_lock(su_home_t *home);
SU_DLL int su_home_mutex_unlock(su_home_t *home);
SU_DLL void *su_alloc(su_home_t *h, int size)
SU_DLL void *su_alloc(su_home_t *h, isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_zalloc(su_home_t *h, int size)
SU_DLL void *su_zalloc(su_home_t *h, isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_salloc(su_home_t *h, int size)
SU_DLL void *su_salloc(su_home_t *h, isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_realloc(su_home_t *h, void *data, int size)
SU_DLL void *su_realloc(su_home_t *h, void *data, isize_t size)
__attribute__((__malloc__));
SU_DLL char *su_strdup(su_home_t *home, char const *s)
__attribute__((__malloc__));
SU_DLL char *su_strcat(su_home_t *home, char const *s1, char const *s2)
__attribute__((__malloc__));
SU_DLL char *su_strndup(su_home_t *home, char const *s, int n)
SU_DLL char *su_strndup(su_home_t *home, char const *s, isize_t n)
__attribute__((__malloc__));
SU_DLL char *su_strcat_all(su_home_t *home, ...)
......
......@@ -60,12 +60,12 @@ typedef struct su_md5_t {
SOFIAPUBFUN void su_md5_init(su_md5_t *context);
SOFIAPUBFUN void su_md5_deinit(su_md5_t *context);
SOFIAPUBFUN void su_md5_update(su_md5_t *context,
void const *buf, unsigned len);
void const *buf, usize_t len);
SOFIAPUBFUN void su_md5_strupdate(su_md5_t *ctx, char const *s);
SOFIAPUBFUN void su_md5_str0update(su_md5_t *ctx, char const *s);
SOFIAPUBFUN void su_md5_iupdate(su_md5_t *context,
void const *buf, unsigned len);
void const *buf, usize_t len);
SOFIAPUBFUN void su_md5_striupdate(su_md5_t *ctx, char const *s);
SOFIAPUBFUN void su_md5_stri0update(su_md5_t *ctx, char const *s);
......
......@@ -87,7 +87,7 @@ SOFIAPUBFUN void su_guid_generate(su_guid_t *guid);
* The function guid_sprintf() returns length of the formatted
* globally unique identifier excluding the final NUL.
*/
SOFIAPUBFUN int su_guid_sprintf(char* buf, size_t len, su_guid_t const *guid);
SOFIAPUBFUN isize_t su_guid_sprintf(char* buf, size_t len, su_guid_t const *guid);
enum {
/** Length of guid in hex format */
......
......@@ -81,7 +81,7 @@ SOFIA_BEGIN_DECLS
#elif SU_HAVE_WINSOCK
#define SU_WAIT_CMP(x, y) ((long)(x) - (long)(y))
#define SU_WAIT_CMP(x, y) ((intptr_t)(x) - (intptr_t)(y))
#define SU_WAIT_IN (FD_READ)
#define SU_WAIT_OUT (FD_WRITE)
......@@ -112,7 +112,13 @@ SOFIA_BEGIN_DECLS
/* ---------------------------------------------------------------------- */
/* Types */
#if SU_HAVE_BSDSOCK
#if 0
typedef struct _pollfd {
su_socket_t fd; /* file descriptor */
short events; /* requested events */
short revents; /* returned events */
} su_wait_t;
#elif SU_HAVE_BSDSOCK
typedef struct pollfd su_wait_t;
#elif SU_HAVE_WINSOCK
typedef HANDLE su_wait_t;
......@@ -421,15 +427,15 @@ SOFIAPUBFUN int su_task_execute(su_task_r const task,
/* Messages */
SOFIAPUBFUN int su_msg_create(su_msg_r msg,
su_task_r const to, su_task_r const from,
su_msg_f wakeup, int size);
su_msg_f wakeup, isize_t size);
SOFIAPUBFUN int su_msg_report(su_msg_r msg, su_msg_f report);
SOFIAPUBFUN int su_msg_reply(su_msg_r reply, su_msg_r const msg,
su_msg_f wakeup, int size);
su_msg_f wakeup, isize_t size);
SOFIAPUBFUN void su_msg_destroy(su_msg_r msg);
SOFIAPUBFUN void su_msg_save(su_msg_r msg, su_msg_r msg0);
SOFIAPUBFUN void su_msg_remove_refs(su_msg_cr msg);
SOFIAPUBFUN su_msg_arg_t *su_msg_data(su_msg_cr msg);
SOFIAPUBFUN int su_msg_size(su_msg_cr msg);
SOFIAPUBFUN isize_t su_msg_size(su_msg_cr msg);
SOFIAPUBFUN _su_task_r su_msg_from(su_msg_cr msg);
SOFIAPUBFUN _su_task_r su_msg_to(su_msg_cr msg);
SOFIAPUBFUN int su_msg_send(su_msg_r msg);
......
......@@ -167,7 +167,7 @@ int su_soerror(su_socket_t s)
int su_setreuseaddr(su_socket_t s, int reuse)
{
return setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
(void *)&reuse, sizeof(reuse));
(void *)&reuse, (socklen_t)sizeof(reuse));
}
......@@ -202,15 +202,16 @@ struct in_addr6 const *su_in6addr_loopback(void)
#if SU_HAVE_WINSOCK
/** Scatter/gather send */
int su_vsend(su_socket_t s, su_iovec_t const iov[], int iovlen, int flags,
su_sockaddr_t const *su, socklen_t sulen)
issize_t su_vsend(su_socket_t s,
su_iovec_t const iov[], isize_t iovlen, int flags,
su_sockaddr_t const *su, socklen_t sulen)
{
int ret;
DWORD bytes_sent = -1;
ret = WSASendTo(s,
(LPWSABUF)iov,
iovlen,
(DWORD)iovlen,
&bytes_sent,
flags,
&su->su_sa,
......@@ -218,40 +219,45 @@ int su_vsend(su_socket_t s, su_iovec_t const iov[], int iovlen, int flags,
NULL,
NULL);
if (ret < 0)
return ret;
return (issize_t)ret;
else
return bytes_sent;
return (issize_t)bytes_sent;
}
/** Scatter/gather recv */
int su_vrecv(su_socket_t s, su_iovec_t iov[], int iovlen, int flags,
su_sockaddr_t *su, socklen_t *sulen)
issize_t su_vrecv(su_socket_t s, su_iovec_t iov[], isize_t iovlen, int flags,
su_sockaddr_t *su, socklen_t *sulen)
{
int ret;
DWORD bytes_recv = -1;
DWORD dflags = flags;
int fromlen = sulen ? *sulen : 0;
ret = WSARecvFrom(s,
(LPWSABUF)iov,
iovlen,
(DWORD)iovlen,
&bytes_recv,
&dflags,
&su->su_sa,
sulen,
sulen ? &fromlen : NULL,
NULL,
NULL);
if (sulen) *sulen = fromlen;
if (ret < 0)
return ret;
return (issize_t)ret;
else
return bytes_recv;
return (issize_t)bytes_recv;
}
#else
int su_vsend(su_socket_t s, su_iovec_t const iov[], int iovlen, int flags,
su_sockaddr_t const *su, socklen_t sulen)
issize_t su_vsend(su_socket_t s,
su_iovec_t const iov[], isize_t iovlen, int flags,
su_sockaddr_t const *su, socklen_t sulen)
{
struct msghdr hdr[1] = {{0}};
......@@ -263,11 +269,11 @@ int su_vsend(su_socket_t s, su_iovec_t const iov[], int iovlen, int flags,
return sendmsg(s, hdr, flags);
}
int su_vrecv(su_socket_t s, su_iovec_t iov[], int iovlen, int flags,
su_sockaddr_t *su, socklen_t *sulen)
issize_t su_vrecv(su_socket_t s, su_iovec_t iov[], isize_t iovlen, int flags,
su_sockaddr_t *su, socklen_t *sulen)
{
struct msghdr hdr[1] = {{0}};
int retval;
issize_t retval;
hdr->msg_name = (void *)su;
if (su && sulen)
......
......@@ -205,7 +205,7 @@ void (*su_home_mutex_unlocker)(void *mutex);
#define MEMCHECK 1
#define MEMCHECK_EXTRA 0
#elif !defined(MEMCHECK_EXTRA)
#define MEMCHECK_EXTRA sizeof (unsigned)
#define MEMCHECK_EXTRA sizeof (size_t)
#endif
enum {
......@@ -217,12 +217,13 @@ enum {
};
#define ALIGNMENT (8)
#define ALIGN(n) (((n) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1))
#define SIZEBITS (sizeof (unsigned) * 8 - 1)
#define ALIGN(n) (size_t)(((n) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1))
#define SIZEBITS (sizeof (size_t) * 8 - 1)
typedef struct {
unsigned long sua_size:SIZEBITS; /**< Size of the block */
size_t sua_size:SIZEBITS; /**< Size of the block */
unsigned sua_home:1; /**< Is this another home? */
unsigned :0;
void *sua_data; /**< Data pointer */
} su_alloc_t;
......@@ -248,9 +249,9 @@ struct su_block_s {
static void su_home_check_blocks(su_block_t const *b);
static void su_home_stats_alloc(su_block_t *, void *p, void *preload,
unsigned size, int zero);
size_t size, int zero);
static void su_home_stats_free(su_block_t *sub, void *p, void *preload,
unsigned size);
size_t size);
static void _su_home_deinit(su_home_t *home);
......@@ -282,7 +283,7 @@ static inline su_alloc_t *su_block_find(su_block_t *b, void *p)
assert(p != NULL);
h = h0 = ((unsigned long)p) % b->sub_n;
h = h0 = (unsigned)(uintptr_t)p % b->sub_n;
probe = (b->sub_n > SUB_P) ? SUB_P : 1;
......@@ -310,7 +311,7 @@ static inline su_alloc_t *su_block_add(su_block_t *b, void *p)
assert(p != NULL);
h = ((unsigned long)p) % b->sub_n;
h = (unsigned)(uintptr_t)p % b->sub_n;
probe = (b->sub_n > SUB_P) ? SUB_P : 1;
......@@ -337,13 +338,13 @@ static inline int su_is_preloaded(su_block_t const *sub, char *data)
static inline int su_alloc_check(su_block_t const *sub, su_alloc_t const *sua)
{
#if MEMCHECK_EXTRA
int size, term;
size_t size, term;
assert(sua);
if (sua) {
size = sua->sua_size;
memcpy(&term, (char *)sua->sua_data + size, sizeof (term));
assert(-term == size);
return -term == size;
assert(size - term == 0);
return size - term == 0;
}
else
return 0;
......@@ -389,12 +390,12 @@ enum sub_zero { do_malloc, do_calloc, do_clone };
static
void *sub_alloc(su_home_t *home,
su_block_t *sub,
long size,
size_t size,
enum sub_zero zero)
{
void *data, *preload = NULL;
assert (size >= 0);
assert (size >= 0 && size < (1 << 31));
if (sub == NULL || 3 * sub->sub_used > 2 * sub->sub_n) {
/* Resize the hash table */
......@@ -414,7 +415,7 @@ void *sub_alloc(su_home_t *home,
return NULL;
for (i = 0; i < n; i++) {
if (sub->sub_nodes[i].sua_data)
if (sub->sub_nodes[i].sua_data)
su_block_add(b2, sub->sub_nodes[i].sua_data)[0] = sub->sub_nodes[i];
}
......@@ -461,7 +462,7 @@ void *sub_alloc(su_home_t *home,
su_alloc_t *sua;
#if MEMCHECK_EXTRA
int term = -size;
int term = -(int)size;
memcpy((char *)data + size, &term, sizeof (term));
#endif
......@@ -478,7 +479,7 @@ void *sub_alloc(su_home_t *home,
if (!subhome->suh_blocks)
return (void)free(data), NULL;
subhome->suh_size = size;
subhome->suh_size = (unsigned)size;
subhome->suh_blocks->sub_parent = home;
subhome->suh_blocks->sub_ref = 1;
}
......@@ -511,14 +512,16 @@ void *sub_alloc(su_home_t *home,
* This function returns a pointer to an su_home_t object, or NULL upon
* an error.
*/
void *su_home_new(int size)
void *su_home_new(isize_t size)
{
su_home_t *home;
assert(size >= sizeof (*home));
if (size < sizeof (*home))
return NULL;
return (errno = EINVAL), NULL;
else if (size > INT_MAX)
return (errno = ENOMEM), NULL;
home = calloc(1, size);
if (home) {
......@@ -642,14 +645,16 @@ int su_home_unref(su_home_t *home)
* This function returns a pointer to an su_home_t object, or NULL upon
* an error.
*/
void *su_home_clone(su_home_t *parent, int size)
void *su_home_clone(su_home_t *parent, isize_t size)
{
su_home_t *home;
assert(size >= sizeof (*home));
if (size < sizeof (*home))
return NULL;
return (void)(errno = EINVAL), NULL;
else if (size > INT_MAX)
return (void)(errno = ENOMEM), NULL;
if (parent) {
su_block_t *sub = MEMLOCK(parent);
......@@ -683,7 +688,7 @@ int su_home_has_parent(su_home_t const *home)
* This function returns a pointer to the allocated memory block or
* NULL if an error occurred.
*/
void *su_alloc(su_home_t *home, int size)
void *su_alloc(su_home_t *home, isize_t size)
{
void *data;
......@@ -1032,7 +1037,7 @@ int su_home_move(su_home_t *dst, su_home_t *src)
*
* The function su_home_preload() preloads a memory home.
*/
void su_home_preload(su_home_t *home, int n, int isize)
void su_home_preload(su_home_t *home, isize_t n, isize_t isize)
{
su_block_t *sub;
......@@ -1044,17 +1049,17 @@ void su_home_preload(su_home_t *home, int n, int isize)
sub = MEMLOCK(home);
if (!sub->sub_preload) {
int size;
size_t size;
void *preload;
size = n * ALIGN(isize);
if (size > USHRT_MAX)
size = USHRT_MAX & (ALIGNMENT - 1);
if (size > 65535) /* We have 16 bits... */
size = 65535 & (ALIGNMENT - 1);
preload = malloc(size);
home->suh_blocks->sub_preload = preload;
home->suh_blocks->sub_prsize = size;
home->suh_blocks->sub_prsize = (unsigned short)size;
}
UNLOCK(home);
}
......@@ -1064,7 +1069,7 @@ void su_home_preload(su_home_t *home, int n, int isize)
* The function su_home_auto() initalizes a memory home using an area
* allocated from stack. Poor mans alloca().
*/
su_home_t *su_home_auto(void *area, int size)
su_home_t *su_home_auto(void *area, isize_t size)
{
su_home_t *home;
su_block_t *sub;
......@@ -1085,9 +1090,12 @@ su_home_t *su_home_auto(void *area, int size)
sub = memset(p + homesize, 0, subsize);
home->suh_blocks = sub;
if (size > prepsize + 65535)
size = prepsize + 65535;
sub->sub_n = SUB_N_AUTO;
sub->sub_preload = p + prepsize;
sub->sub_prsize = size - prepsize;
sub->sub_prsize = (unsigned short)(size - prepsize);
sub->sub_preauto = 1;
sub->sub_auto = 1;
sub->sub_auto_all = 1;
......@@ -1112,12 +1120,12 @@ su_home_t *su_home_auto(void *area, int size)
* This function returns a pointer to the allocated memory block or
* NULL if an error occurred.
*/
void *su_realloc(su_home_t *home, void *data, int size)
void *su_realloc(su_home_t *home, void *data, isize_t size)
{
void *ndata;
su_alloc_t *sua;
su_block_t *sub;
int p;
size_t p;
int term = -size;
if (!home)
......@@ -1250,7 +1258,7 @@ void *su_realloc(su_home_t *home, void *data, int size)
* The function su_zalloc() returns a pointer to the allocated memory block,
* or NULL upon an error.
*/
void *su_zalloc(su_home_t *home, int size)
void *su_zalloc(su_home_t *home, isize_t size)
{
void *data;
......@@ -1270,7 +1278,7 @@ void *su_zalloc(su_home_t *home, int size)
*
* The function su_salloc() allocates a structure with a given size, zeros
* it, and initializes the size field to the given size. The size field
* is the first in the structure.
* is the first in the structure. It has type of int.
*
* @param home pointer to memory pool object
* @param size size of the structure
......@@ -1288,23 +1296,23 @@ void *su_zalloc(su_home_t *home, int size)
* ...
* t = su_salloc(home, sizeof (*t));
* assert(t && t->t_size == sizeof (*t));
* t->name
*
* @endcode
* After calling su_salloc() we get a pointer t to a struct test,
* initialized to zero except the
*
* initialized to zero except the tst_size field, which is initialized to
* sizeof (*t).
*
* @return This function returns a pointer to the allocated structure, or
* NULL upon an error.
* @return A pointer to the allocated structure, or NULL upon an error.
*/
void *su_salloc(su_home_t *home, int size)
void *su_salloc(su_home_t *home, isize_t size)
{
struct { int size; } *retval;
if (size < sizeof (*retval))
size = sizeof (*retval);
assert (size >= 0);
if (size > INT_MAX)
return (void)(errno = ENOMEM), NULL;
if (home) {
retval = sub_alloc(home, MEMLOCK(home), size, 1);
......@@ -1360,6 +1368,7 @@ int su_home_mutex_unlock(su_home_t *home)
return 0;
}
/** Initialize statistics structure */
void su_home_init_stats(su_home_t *home)
{
......@@ -1420,11 +1429,11 @@ void su_home_get_stats(su_home_t *home, int include_clones,
static
void su_home_stats_alloc(su_block_t *sub, void *p, void *preload,
unsigned size, int zero)
size_t size, int zero)
{
su_home_stat_t *hs = sub->sub_stats;
unsigned rsize = ALIGN(size);
size_t rsize = ALIGN(size);
hs->hs_rehash += (sub->sub_n != hs->hs_blocksize);
hs->hs_blocksize = sub->sub_n;
......@@ -1448,11 +1457,11 @@ void su_home_stats_alloc(su_block_t *sub, void *p, void *preload,
}
static
void su_home_stats_free(su_block_t *sub, void *p, void *preload, unsigned size)
void su_home_stats_free(su_block_t *sub, void *p, void *preload, size_t size)
{
su_home_stat_t *hs = sub->sub_stats;
unsigned rsize = ALIGN(size);
size_t rsize = ALIGN(size);
if (preload) {
hs->hs_frees.hsf_preload++;
......
......@@ -285,7 +285,7 @@ char const *su_gli_strerror(int error)
*/
su_localinfo_t *su_copylocalinfo(su_localinfo_t const *li0)
{
int n;
size_t n;
su_localinfo_t *li, *retval = NULL, **lli = &retval;
# define SLEN(s) ((s) ? strlen(s) + 1 : 0)
......
......@@ -131,7 +131,7 @@ void su_md5_deinit(su_md5_t *context)
void
su_md5_update(su_md5_t *ctx,
void const *b,
unsigned len)
usize_t len)
{
unsigned char const *buf = (unsigned char const *)b;
uint32_t t;
......@@ -200,7 +200,7 @@ void mem_i_cpy(unsigned char *d, unsigned char const *s, int len)
void
su_md5_iupdate(su_md5_t *ctx,
void const *b,
unsigned len)
usize_t len)
{
unsigned char const *buf = (unsigned char const *)b;
uint32_t t;
......
......@@ -69,7 +69,7 @@ SOFIA_BEGIN_DECLS
/** Message */
struct su_msg_s {
int sum_size;
isize_t sum_size;
su_msg_t *sum_next;
su_task_r sum_to;
su_task_r sum_from;
......
......@@ -1387,16 +1387,17 @@ int su_msg_create(su_msg_r rmsg,
su_task_r const to,
su_task_r const from,
su_msg_f wakeup,
int size)
isize_t size)
{
su_port_t *port = to->sut_port;
su_msg_t *msg;
SU_PORT_LOCK(port, su_msg_create);
msg = su_salloc(NULL /*port->sup_home*/, sizeof(*msg) + size);
msg = su_zalloc(NULL /*port->sup_home*/, sizeof(*msg) + size);
SU_PORT_UNLOCK(port, su_msg_create);
if (msg) {
msg->sum_size = sizeof(*msg) + size;
SU_TASK_COPY(msg->sum_to, to, su_msg_create);
SU_TASK_COPY(msg->sum_from, from, su_msg_create);
msg->sum_func = wakeup;
......@@ -1439,7 +1440,7 @@ int su_msg_report(su_msg_r msg,
*/
int su_msg_reply(su_msg_r reply, su_msg_r const msg,
su_msg_f wakeup, int size)
su_msg_f wakeup, isize_t size)
{
su_msg_r msg0;
......@@ -1537,7 +1538,7 @@ su_msg_arg_t *su_msg_data(su_msg_cr rmsg)
}
/** Get size of message data area. */
int su_msg_size(su_msg_cr rmsg)
isize_t su_msg_size(su_msg_cr rmsg)
{
return rmsg[0] ? rmsg[0]->sum_size - sizeof(su_msg_t) : 0;
}
......
......@@ -38,6 +38,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#if defined(va_copy)
/* Xyzzy */
......@@ -66,19 +67,19 @@
*/
char *su_vsprintf(su_home_t *home, char const *fmt, va_list ap)
{
int n, len;
int n;
size_t len;
char *rv, s[128];
va_list aq;
va_copy(aq, ap);
len = vsnprintf(s, sizeof(s), fmt, aq) + 1;
n = vsnprintf(s, sizeof(s), fmt, aq);
va_end(aq);
if (len > 0 && len < sizeof(s))
if (n >= 0 && n + 1 < sizeof(s))
return su_strdup(home, s);
if (len == 0)
len = 2 * sizeof(s);
len = n > 0 ? n + 1 : 2 * sizeof(s);
for (rv = su_alloc(home, len);
rv;
......@@ -91,7 +92,10 @@ char *su_vsprintf(su_home_t *home, char const *fmt, va_list ap)
if (n > -1) /* glibc >2.1 */
len = n + 1;
else /* glibc 2.0 */
len *= 2;
len *= 2;
if (len > INT_MAX)
return (void)su_free(home, rv), NULL;
}
return rv;
......
......@@ -51,7 +51,7 @@
char *su_strdup(su_home_t *home, char const *s)
{
if (s) {
int n = strlen(s);
size_t n = strlen(s);
char *retval = su_alloc(home, n + 1);
if (retval)
strncpy(retval, s, n)[n] = 0;
......@@ -76,14 +76,14 @@ char *su_strdup(su_home_t *home, char const *s)
*/
char *su_strcat(su_home_t *home, char const *s1, char const *s2)
{
int n1, n2;
size_t n1, n2;
char *retval;
if (s1 == NULL)
return su_strdup(home, s2);
else if (s2 == NULL)
return su_strdup(home, s1);
n1 = strlen(s1); n2 = strlen(s2);
retval = su_alloc(home, n1 + n2 + 1);
if (retval) {
......@@ -156,7 +156,7 @@ char *su_strcat_all(su_home_t *home, ...)
* @return The function su_strndup() returns pointer to the newly created
* string, or @c NULL upon an error.
*/
char *su_strndup(su_home_t *home, char const *s, int n)
char *su_strndup(su_home_t *home, char const *s, isize_t n)
{
if (s) {
char *retval = su_alloc(home, n + 1);
......
......@@ -98,9 +98,9 @@ enum { N = 8 };
struct su_strlst_s