From: Pierre Habouzit Date: Mon, 6 Oct 2008 08:46:31 +0000 (+0200) Subject: 64bits fixes. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=59b8220d0227fe68537a563b3e5fa2e63e26bc0d;p=apps%2Fpfixtools.git 64bits fixes. On 64bits platforms, ssize_t is an int64_t. Given the average string length pfixtools will handle, a 32bits integer is enough, let's use int everywhere. Also a pointer difference is an ptrdiff_t which is also a 64bits integer, so when used as the width specifier of a %.*s format, it must be cast into an int. Signed-off-by: Pierre Habouzit --- diff --git a/common/buffer.c b/common/buffer.c index bfd8ba0..0ef465c 100644 --- a/common/buffer.c +++ b/common/buffer.c @@ -40,9 +40,9 @@ #include "mem.h" #include "buffer.h" -ssize_t buffer_addvf(buffer_t *buf, const char *fmt, va_list ap) +int buffer_addvf(buffer_t *buf, const char *fmt, va_list ap) { - ssize_t len, avail = buf->size - buf->len; + int len, avail = buf->size - buf->len; va_list ap2; va_copy(ap2, ap); @@ -59,12 +59,12 @@ ssize_t buffer_addvf(buffer_t *buf, const char *fmt, va_list ap) return len; } -void buffer_consume(buffer_t *buf, ssize_t len) +void buffer_consume(buffer_t *buf, int len) { if (len <= 0) return; - if (len >= (ssize_t)buf->len) { + if (len >= (int)buf->len) { buffer_reset(buf); return; } @@ -73,9 +73,9 @@ void buffer_consume(buffer_t *buf, ssize_t len) buf->len -= len; } -ssize_t buffer_read(buffer_t *buf, int fd, ssize_t count) +int buffer_read(buffer_t *buf, int fd, int count) { - ssize_t res; + int res; if (count < 0) count = BUFSIZ; @@ -92,9 +92,9 @@ ssize_t buffer_read(buffer_t *buf, int fd, ssize_t count) return res; } -ssize_t buffer_write(buffer_t *buf, int fd) +int buffer_write(buffer_t *buf, int fd) { - ssize_t res = write(fd, buf->data, buf->len); + int res = write(fd, buf->data, buf->len); if (res < 0) { return errno == EINTR || errno == EAGAIN ? 0 : -1; } diff --git a/common/buffer.h b/common/buffer.h index c6c11c6..c3e1adf 100644 --- a/common/buffer.h +++ b/common/buffer.h @@ -66,18 +66,18 @@ static inline char *buffer_unwrap(buffer_t **buf) { #define buffer_resize(buffer, newsize) \ array_ensure_exact_capacity(*(buffer), (newsize) + 1) -static inline void buffer_ensure(buffer_t *buf, ssize_t extra) { +static inline void buffer_ensure(buffer_t *buf, int extra) { assert (extra >= 0); if (buf->len + extra >= buf->size) { buffer_resize(buf, buf->len + extra); } } -static inline void buffer_extend(buffer_t *buf, ssize_t extra) { +static inline void buffer_extend(buffer_t *buf, int extra) { buffer_ensure(buf, extra); buf->len += extra; buf->data[buf->len] = '\0'; } -static inline void buffer_extendch(buffer_t *buf, ssize_t extra, int c) { +static inline void buffer_extendch(buffer_t *buf, int extra, int c) { buffer_ensure(buf, extra); memset(buf->data + buf->len, c, extra); buf->len += extra; @@ -85,7 +85,7 @@ static inline void buffer_extendch(buffer_t *buf, ssize_t extra, int c) { } -static inline void buffer_add(buffer_t *buf, const void *data, ssize_t len) { +static inline void buffer_add(buffer_t *buf, const void *data, int len) { buffer_ensure(buf, len); memcpy(buf->data + buf->len, data, len); buf->len += len; @@ -102,12 +102,12 @@ static inline void buffer_addch(buffer_t *buf, int c) { } __attribute__((format(printf,2,0))) -ssize_t buffer_addvf(buffer_t *, const char *fmt, va_list); +int buffer_addvf(buffer_t *, const char *fmt, va_list); static inline __attribute__((format(printf,2,3))) -ssize_t buffer_addf(buffer_t *buf, const char *fmt, ...) +int buffer_addf(buffer_t *buf, const char *fmt, ...) { - ssize_t res; + int res; va_list args; va_start(args, fmt); res = buffer_addvf(buf, fmt, args); @@ -115,9 +115,9 @@ ssize_t buffer_addf(buffer_t *buf, const char *fmt, ...) return res; } -void buffer_consume(buffer_t *buf, ssize_t len); +void buffer_consume(buffer_t *buf, int len); -ssize_t buffer_read(buffer_t *buf, int fd, ssize_t count); -ssize_t buffer_write(buffer_t *buf, int fd); +int buffer_read(buffer_t *buf, int fd, int count); +int buffer_write(buffer_t *buf, int fd); #endif /* PFIXTOOLS_BUFFER_H */ diff --git a/common/trie.c b/common/trie.c index f16f0a6..ea60f63 100644 --- a/common/trie.c +++ b/common/trie.c @@ -399,7 +399,7 @@ static inline void trie_entry_inspect(const trie_t *trie, bool show_content, printf("Number of leaves: %d\n", leaves); printf("Max depth: %d\n", max_depth); printf("Average leaf depth: %d\n", depth_sum / leaves); - printf("Memory used: %d\n", (trie->entries.size * sizeof(trie_entry_t)) + printf("Memory used: %zd\n", (trie->entries.size * sizeof(trie_entry_t)) + (trie->c.size) + sizeof(trie_t)); } } diff --git a/postlicyd/config.c b/postlicyd/config.c index f2b8dbe..672faca 100644 --- a/postlicyd/config.c +++ b/postlicyd/config.c @@ -188,7 +188,7 @@ static bool config_load(config_t *config) char key[BUFSIZ]; char value[BUFSIZ]; - ssize_t key_len, value_len; + int key_len, value_len; if (!file_map_open(&map, config->filename, false)) { return false; @@ -200,7 +200,7 @@ static bool config_load(config_t *config) #define READ_LOG(Lev, Fmt, ...) \ __log(LOG_ ## Lev, "config file %s:%d:%d: " Fmt, config->filename, \ - line + 1, p - linep + 1, ##__VA_ARGS__) + line + 1, (int)(p - linep + 1), ##__VA_ARGS__) #define READ_ERROR(Fmt, ...) \ do { \ READ_LOG(ERR, Fmt, ##__VA_ARGS__); \ diff --git a/postlicyd/filter.c b/postlicyd/filter.c index d277542..7aba638 100644 --- a/postlicyd/filter.c +++ b/postlicyd/filter.c @@ -197,19 +197,19 @@ bool filter_test(const filter_t *filter, const query_t *query, filter_result_t r return !!(runners[filter->type](filter, query) == result); } -void filter_set_name(filter_t *filter, const char *name, ssize_t len) +void filter_set_name(filter_t *filter, const char *name, int len) { filter->name = p_dupstr(name, len); } -bool filter_set_type(filter_t *filter, const char *type, ssize_t len) +bool filter_set_type(filter_t *filter, const char *type, int len) { filter->type = filter_tokenize(type, len); return filter->type != FTK_UNKNOWN; } -bool filter_add_param(filter_t *filter, const char *name, ssize_t name_len, - const char *value, ssize_t value_len) +bool filter_add_param(filter_t *filter, const char *name, int name_len, + const char *value, int value_len) { filter_param_t param; param.type = param_tokenize(name, name_len); @@ -228,8 +228,8 @@ bool filter_add_param(filter_t *filter, const char *name, ssize_t name_len, return true; } -bool filter_add_hook(filter_t *filter, const char *name, ssize_t name_len, - const char *value, ssize_t value_len) +bool filter_add_hook(filter_t *filter, const char *name, int name_len, + const char *value, int value_len) { filter_hook_t hook; hook.type = hook_tokenize(name, name_len); diff --git a/postlicyd/filter.h b/postlicyd/filter.h index 1d44586..3047803 100644 --- a/postlicyd/filter.h +++ b/postlicyd/filter.h @@ -58,8 +58,8 @@ ARRAY(filter_hook_t) typedef struct filter_param_t { filter_param_id_t type; - char *value; - ssize_t value_len; + char *value; + int value_len; } filter_param_t; ARRAY(filter_param_t) @@ -112,18 +112,18 @@ static inline void filter_init(filter_t *filter) } __attribute__((nonnull(1,2))) -void filter_set_name(filter_t *filter, const char *name, ssize_t len); +void filter_set_name(filter_t *filter, const char *name, int len); __attribute__((nonnull(1,2))) -bool filter_set_type(filter_t *filter, const char *type, ssize_t len); +bool filter_set_type(filter_t *filter, const char *type, int len); __attribute__((nonnull(1,2,4))) -bool filter_add_param(filter_t *filter, const char *name, ssize_t name_len, - const char *value, ssize_t value_len); +bool filter_add_param(filter_t *filter, const char *name, int name_len, + const char *value, int value_len); __attribute__((nonnull(1,2,4))) -bool filter_add_hook(filter_t *filter, const char *name, ssize_t name_len, - const char *value, ssize_t value_len); +bool filter_add_hook(filter_t *filter, const char *name, int name_len, + const char *value, int value_len); __attribute__((nonnull(1))) bool filter_build(filter_t *filter); diff --git a/postlicyd/iplist.c b/postlicyd/iplist.c index 5337dca..a1f49eb 100644 --- a/postlicyd/iplist.c +++ b/postlicyd/iplist.c @@ -299,7 +299,7 @@ static bool rbl_filter_constructor(filter_t *filter) lock = false; } else { PARSE_CHECK(false, "illegal locking state %.*s", - p - current, current); + (int)(p - current), current); } break; @@ -307,7 +307,7 @@ static bool rbl_filter_constructor(filter_t *filter) weight = strtol(current, &next, 10); PARSE_CHECK(next == p && weight >= 0 && weight <= 1024, "illegal weight value %.*s", - (p - current), current); + (int)(p - current), current); break; case 2: @@ -342,7 +342,7 @@ static bool rbl_filter_constructor(filter_t *filter) weight = strtol(current, &next, 10); PARSE_CHECK(next == p && weight >= 0 && weight <= 1024, "illegal weight value %.*s", - (p - current), current); + (int)(p - current), current); break; case 1: diff --git a/postlicyd/main-postlicyd.c b/postlicyd/main-postlicyd.c index 9ff1bc5..9bdc391 100644 --- a/postlicyd/main-postlicyd.c +++ b/postlicyd/main-postlicyd.c @@ -117,7 +117,7 @@ static bool policy_process(server_t *pcy, const config_t *config) static int policy_run(server_t *pcy, void* vconfig) { - ssize_t search_offs = MAX(0, (ssize_t)(pcy->ibuf.len - 1)); + int search_offs = MAX(0, (int)(pcy->ibuf.len - 1)); int nb = buffer_read(&pcy->ibuf, pcy->fd, -1); const char *eoq; query_t *query = pcy->data; diff --git a/postlicyd/match.c b/postlicyd/match.c index 1b02cc2..d50b12a 100644 --- a/postlicyd/match.c +++ b/postlicyd/match.c @@ -133,7 +133,7 @@ static bool match_filter_constructor(filter_t *filter) condition.field = policy_tokenize(p, n - p); PARSE_CHECK(condition.field >= PTK_HELO_NAME && condition.field < PTK_SMTPD_ACCESS_POLICY, - "invalid field name %.*s", n - p, p); + "invalid field name %.*s", (int)(n - p), p); p = skipspaces(n); n = p + 1; PARSE_CHECK(IS_OP_START(*p) && IS_OP_END(*n), diff --git a/postlicyd/strlist.c b/postlicyd/strlist.c index c350f22..0c790cb 100644 --- a/postlicyd/strlist.c +++ b/postlicyd/strlist.c @@ -285,7 +285,7 @@ static bool strlist_filter_constructor(filter_t *filter) lock = false; } else { PARSE_CHECK(false, "illegal locking state %.*s", - p - current, current); + (int)(p - current), current); } break; @@ -301,7 +301,7 @@ static bool strlist_filter_constructor(filter_t *filter) reverse = false; } else { PARSE_CHECK(false, "illegal character order value %.*s", - p - current, current); + (int)(p - current), current); } break; @@ -309,7 +309,7 @@ static bool strlist_filter_constructor(filter_t *filter) weight = strtol(current, &next, 10); PARSE_CHECK(next == p && weight >= 0 && weight <= 1024, "illegal weight value %.*s", - (p - current), current); + (int)(p - current), current); break; case 3: @@ -358,7 +358,7 @@ static bool strlist_filter_constructor(filter_t *filter) lock = false; } else { PARSE_CHECK(false, "illegal locking state %.*s", - p - current, current); + (int)(p - current), current); } break; @@ -366,7 +366,7 @@ static bool strlist_filter_constructor(filter_t *filter) weight = strtol(current, &next, 10); PARSE_CHECK(next == p && weight >= 0 && weight <= 1024, "illegal weight value %.*s", - (p - current), current); + (int)(p - current), current); break; case 2: @@ -412,7 +412,7 @@ static bool strlist_filter_constructor(filter_t *filter) weight = strtol(current, &next, 10); PARSE_CHECK(next == p && weight >= 0 && weight <= 1024, "illegal weight value %.*s", - (p - current), current); + (int)(p - current), current); break; case 1: @@ -470,7 +470,7 @@ static bool strlist_filter_constructor(filter_t *filter) CASE(RECIPIENT, recipient, email); #undef CASE default: - PARSE_CHECK(false, "unknown field %.*s", p - current, current); + PARSE_CHECK(false, "unknown field %.*s", (int)(p - current), current); break; } if (!*p) {