util: fix -Wshorten-64-to-32 warnings

Ticket: #6186
pull/12653/head
Philippe Antoine 1 year ago committed by Victor Julien
parent d61f36c66f
commit 359f736542

@ -700,7 +700,7 @@ static int SetCPUAffinitySet(cpu_set_t *cs)
int r = thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY,
(void*)cs, THREAD_AFFINITY_POLICY_COUNT);
#else
pid_t tid = syscall(SYS_gettid);
pid_t tid = (pid_t)syscall(SYS_gettid);
int r = sched_setaffinity(tid, sizeof(cpu_set_t), cs);
#endif /* OS_FREEBSD */

@ -106,7 +106,7 @@ typedef struct UnixCommand_ {
static int UnixNew(UnixCommand * this)
{
struct sockaddr_un addr;
int len;
socklen_t len;
int ret;
int on = 1;
char sockettarget[PATH_MAX];
@ -161,7 +161,7 @@ static int UnixNew(UnixCommand * this)
addr.sun_family = AF_UNIX;
strlcpy(addr.sun_path, sockettarget, sizeof(addr.sun_path));
addr.sun_path[sizeof(addr.sun_path) - 1] = 0;
len = strlen(addr.sun_path) + sizeof(addr.sun_family) + 1;
len = (socklen_t)(strlen(addr.sun_path) + sizeof(addr.sun_family) + 1);
/* create socket */
this->socket = socket(AF_UNIX, SOCK_STREAM, 0);
@ -335,7 +335,7 @@ static int UnixCommandAccept(UnixCommand *this)
json_error_t jerror;
int client;
int client_version;
int ret;
ssize_t ret;
UnixClient *uclient = NULL;
/* accept client socket */
@ -537,7 +537,7 @@ error:
static void UnixCommandRun(UnixCommand * this, UnixClient *client)
{
char buffer[4096];
int ret;
ssize_t ret;
if (client->version <= UNIX_PROTO_V1) {
ret = recv(client->fd, buffer, sizeof(buffer) - 1, 0);
if (ret <= 0) {
@ -695,7 +695,7 @@ static TmEcode UnixManagerUptimeCommand(json_t *cmd,
json_t *server_msg, void *data)
{
SCEnter();
int uptime;
time_t uptime;
UnixCommand *ucmd = (UnixCommand *)data;
uptime = time(NULL) - ucmd->start_timestamp;

@ -100,24 +100,24 @@ void BuildCpusetWithCallback(const char *name, ConfNode *node,
{
ConfNode *lnode;
TAILQ_FOREACH(lnode, &node->head, next) {
int i;
long int a,b;
int stop = 0;
int max = UtilCpuGetNumProcessorsOnline() - 1;
uint32_t i;
uint32_t a, b;
uint32_t stop = 0;
uint32_t max = UtilCpuGetNumProcessorsOnline();
if (max > 0) {
max--;
}
if (!strcmp(lnode->val, "all")) {
a = 0;
b = max;
stop = 1;
} else if (strchr(lnode->val, '-') != NULL) {
char *sep = strchr(lnode->val, '-');
char *end;
a = strtoul(lnode->val, &end, 10);
if (end != sep) {
if (StringParseUint32(&a, 10, sep - lnode->val, lnode->val) < 0) {
SCLogError("%s: invalid cpu range (start invalid): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
}
b = strtol(sep + 1, &end, 10);
if (end != sep + strlen(sep)) {
if (StringParseUint32(&b, 10, strlen(sep) - 1, sep + 1) < 0) {
SCLogError("%s: invalid cpu range (end invalid): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
}
@ -126,13 +126,11 @@ void BuildCpusetWithCallback(const char *name, ConfNode *node,
exit(EXIT_FAILURE);
}
if (b > max) {
SCLogError("%s: upper bound (%ld) of cpu set is too high, only %d cpu(s)", name, b,
SCLogError("%s: upper bound (%d) of cpu set is too high, only %d cpu(s)", name, b,
max + 1);
}
} else {
char *end;
a = strtoul(lnode->val, &end, 10);
if (end != lnode->val + strlen(lnode->val)) {
if (StringParseUint32(&a, 10, strlen(lnode->val), lnode->val) < 0) {
SCLogError("%s: invalid cpu range (not an integer): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
}

@ -228,7 +228,7 @@ int ByteExtractString(uint64_t *res, int base, size_t len, const char *str, bool
return -1;
}
return (endptr - ptr);
return (int)(endptr - ptr);
}
int ByteExtractStringUint64(uint64_t *res, int base, size_t len, const char *str)
@ -531,7 +531,7 @@ int ByteExtractStringSigned(int64_t *res, int base, size_t len, const char *str,
//fprintf(stderr, "ByteExtractStringSigned: Extracted base %d: 0x%" PRIx64 "\n", base, *res);
return (endptr - ptr);
return (int)(endptr - ptr);
}
int ByteExtractStringInt64(int64_t *res, int base, size_t len, const char *str)

@ -448,9 +448,9 @@ uint32_t SCClassConfClasstypeHashFunc(HashTable *ht, void *data, uint16_t datale
{
SCClassConfClasstype *ct = (SCClassConfClasstype *)data;
uint32_t hash = 0;
int i = 0;
size_t i = 0;
int len = strlen(ct->classtype);
size_t len = strlen(ct->classtype);
for (i = 0; i < len; i++)
hash += u8_tolower((unsigned char)(ct->classtype)[i]);
@ -478,8 +478,8 @@ char SCClassConfClasstypeHashCompareFunc(void *data1, uint16_t datalen1,
{
SCClassConfClasstype *ct1 = (SCClassConfClasstype *)data1;
SCClassConfClasstype *ct2 = (SCClassConfClasstype *)data2;
int len1 = 0;
int len2 = 0;
size_t len1 = 0;
size_t len2 = 0;
if (ct1 == NULL || ct2 == NULL)
return 0;

@ -286,25 +286,25 @@ static const char *SCTransformModule(const char *module_name, int *dn_len)
* app-layer-*
*/
if (strncmp("tm-", module_name, 3) == 0) {
*dn_len = strlen(module_name) - 3;
*dn_len = (int)strlen(module_name) - 3;
return module_name + 3;
} else if (strncmp("util-", module_name, 5) == 0) {
*dn_len = strlen(module_name) - 5;
*dn_len = (int)strlen(module_name) - 5;
return module_name + 5;
} else if (strncmp("source-pcap-file", module_name, 16) == 0) {
*dn_len = strlen("pcap");
*dn_len = (int)strlen("pcap");
return "pcap";
} else if (strncmp("source-", module_name, 7) == 0) {
*dn_len = strlen(module_name) - 7;
*dn_len = (int)strlen(module_name) - 7;
return module_name + 7;
} else if (strncmp("runmode-", module_name, 8) == 0) {
*dn_len = strlen(module_name) - 8;
*dn_len = (int)strlen(module_name) - 8;
return module_name + 8;
} else if (strncmp("app-layer-", module_name, 10) == 0) {
*dn_len = strlen(module_name);
*dn_len = (int)strlen(module_name);
return module_name;
} else if (strncmp("detect-engine", module_name, 13) == 0) {
*dn_len = strlen("detect");
*dn_len = (int)strlen("detect");
return "detect";
}
@ -319,9 +319,9 @@ static const char *SCTransformModule(const char *module_name, int *dn_len)
}
if (seg_cnt < transform_max_segs)
*dn_len = strlen(module_name);
*dn_len = (int)strlen(module_name);
else
*dn_len = last - module_name;
*dn_len = (int)(last - module_name);
return module_name;
}

@ -117,20 +117,20 @@ static fpos_t SeekFn(void *handler, fpos_t offset, int whence)
*/
static int ReadFn(void *handler, char *buf, int size)
{
size_t count = 0;
int count = 0;
SCFmem *mem = handler;
size_t available = mem->size - mem->pos;
int is_eof = 0;
if (size < 0) return - 1;
if ((size_t)size > available) {
size = available;
if (available < INT_MAX && size > (int)available) {
size = (int)available;
} else {
is_eof = 1;
}
while (count < (size_t)size)
while (count < size)
buf[count++] = mem->buffer[mem->pos++];
if (is_eof == 1)
@ -148,16 +148,16 @@ static int ReadFn(void *handler, char *buf, int size)
*/
static int WriteFn(void *handler, const char *buf, int size)
{
size_t count = 0;
int count = 0;
SCFmem *mem = handler;
size_t available = mem->size - mem->pos;
if (size < 0) return - 1;
if ((size_t)size > available)
size = available;
if (available < INT_MAX && size > (int)available)
size = (int)available;
while (count < (size_t)size)
while (count < size)
mem->buffer[mem->pos++] = buf[count++];
return count;

@ -40,8 +40,8 @@ bool IPv4AddressStringIsValid(const char *str)
memset(&addr, 0, sizeof(addr));
uint32_t len = strlen(str);
uint32_t i = 0;
size_t len = strlen(str);
size_t i = 0;
for (i = 0; i < len; i++) {
if (!(str[i] == '.' || isdigit(str[i]))) {
return false;
@ -85,8 +85,8 @@ bool IPv6AddressStringIsValid(const char *str)
int sep = 0;
bool colon_seen = false;
uint32_t len = strlen(str);
uint32_t i = 0;
size_t len = strlen(str);
size_t i = 0;
for (i = 0; i < len && str[i] != 0; i++) {
if (!(str[i] == '.' || str[i] == ':' ||
isxdigit(str[i])))

@ -30,8 +30,8 @@
typedef struct JA3Buffer_ {
char *data;
size_t size;
size_t used;
uint32_t size;
uint32_t used;
} JA3Buffer;
JA3Buffer *Ja3BufferInit(void);

@ -28,6 +28,7 @@
#include "util-landlock.h"
#include "util-mem.h"
#include "util-path.h"
#include "util-validate.h"
#ifndef HAVE_LINUX_LANDLOCK_H
@ -43,7 +44,9 @@ void LandlockSandboxing(SCInstance *suri)
static inline int landlock_create_ruleset(
const struct landlock_ruleset_attr *const attr, const size_t size, const __u32 flags)
{
return syscall(__NR_landlock_create_ruleset, attr, size, flags);
long r = syscall(__NR_landlock_create_ruleset, attr, size, flags);
DEBUG_VALIDATE_BUG_ON(r > INT_MAX);
return (int)r;
}
#endif
@ -51,14 +54,18 @@ static inline int landlock_create_ruleset(
static inline int landlock_add_rule(const int ruleset_fd, const enum landlock_rule_type rule_type,
const void *const rule_attr, const __u32 flags)
{
return syscall(__NR_landlock_add_rule, ruleset_fd, rule_type, rule_attr, flags);
long r = syscall(__NR_landlock_add_rule, ruleset_fd, rule_type, rule_attr, flags);
DEBUG_VALIDATE_BUG_ON(r > INT_MAX);
return (int)r;
}
#endif
#ifndef landlock_restrict_self
static inline int landlock_restrict_self(const int ruleset_fd, const __u32 flags)
{
return syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
long r = syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
DEBUG_VALIDATE_BUG_ON(r > INT_MAX);
return (int)r;
}
#endif

@ -785,7 +785,7 @@ static bool LogFileThreadedName(
* for update
*/
dot = strrchr(original_name, '.');
int dotpos = dot - original_name;
ptrdiff_t dotpos = dot - original_name;
tname[dotpos] = '\0';
char *ext = tname + dotpos + 1;
if (strlen(tname) && strlen(ext)) {

@ -74,7 +74,7 @@ static int LuaHashLibSha256Update(lua_State *L)
}
size_t data_len;
const char *data = luaL_checklstring(L, 2, &data_len);
SCSha256Update(*hasher, (const uint8_t *)data, data_len);
SCSha256Update(*hasher, (const uint8_t *)data, (uint32_t)data_len);
return 0;
}
@ -123,7 +123,7 @@ static int LuaHashLibSha256Digest(lua_State *L)
size_t buf_len;
const char *input = luaL_checklstring(L, 1, &buf_len);
size_t output_len = SC_SHA256_LEN;
uint32_t output_len = SC_SHA256_LEN;
uint8_t output[output_len];
if (!SCSha256HashBuffer((uint8_t *)input, (uint32_t)buf_len, output, output_len)) {
return luaL_error(L, "sha256 hashing failed");
@ -178,7 +178,7 @@ static int LuaHashLibSha1Update(lua_State *L)
size_t data_len;
const char *data = luaL_checklstring(L, 2, &data_len);
SCSha1Update(*hasher, (const uint8_t *)data, data_len);
SCSha1Update(*hasher, (const uint8_t *)data, (uint32_t)data_len);
return 0;
}
@ -280,7 +280,7 @@ static int LuaHashLibMd5Update(lua_State *L)
size_t data_len;
const char *data = luaL_checklstring(L, 2, &data_len);
SCMd5Update(*hasher, (const uint8_t *)data, data_len);
SCMd5Update(*hasher, (const uint8_t *)data, (uint32_t)data_len);
return 0;
}
@ -344,7 +344,7 @@ static int LuaHashLibMd5HexDigest(lua_State *L)
const char *input = luaL_checklstring(L, 1, &buf_len);
char output[SC_MD5_HEX_LEN + 1];
if (!SCMd5HashBufferToHex((uint8_t *)input, (size_t)buf_len, output, sizeof(output))) {
if (!SCMd5HashBufferToHex((uint8_t *)input, (uint32_t)buf_len, output, sizeof(output))) {
return luaL_error(L, "md5 hashing failed");
}

@ -47,7 +47,8 @@ typedef struct SCLuaSbState {
/* Execution Limits */
uint64_t instruction_count;
uint64_t instruction_limit;
uint64_t hook_instruction_count;
// used by lua_sethook
int hook_instruction_count;
/* Errors. */
bool blocked_function_error;

@ -361,7 +361,7 @@ static uint32_t ProtoNameHashFunc(HashTable *ht, void *data, uint16_t datalen)
* as the proto number is not used for lookups
*/
ProtoNameHashEntry *p = (ProtoNameHashEntry *)data;
return StringHashDjb2((uint8_t *)p->name, strlen(p->name)) % ht->array_size;
return StringHashDjb2((uint8_t *)p->name, (uint32_t)strlen(p->name)) % ht->array_size;
}
static char ProtoNameHashCompareFunc(void *data1, uint16_t datalen1, void *data2, uint16_t datalen2)
@ -375,8 +375,8 @@ static char ProtoNameHashCompareFunc(void *data1, uint16_t datalen1, void *data2
if (p1->name == NULL || p2->name == NULL)
return 0;
int len1 = strlen(p1->name);
int len2 = strlen(p2->name);
size_t len1 = strlen(p1->name);
size_t len2 = strlen(p2->name);
return len1 == len2 && memcmp(p1->name, p2->name, len1) == 0;
}

@ -38,7 +38,7 @@ static long int RandomGetClock(void)
clock_gettime(CLOCK_REALTIME, &ts);
// coverity[dont_call : FALSE]
srandom(ts.tv_nsec ^ ts.tv_sec);
srandom((unsigned int)(ts.tv_nsec ^ ts.tv_sec));
long int value = random();
return value;
}
@ -103,7 +103,7 @@ long int RandomGet(void)
return 0;
long int value = 0;
int ret = getrandom(&value, sizeof(value), 0);
ssize_t ret = getrandom(&value, sizeof(value), 0);
/* ret should be sizeof(value), but if it is > 0 and < sizeof(value)
* it's still better than nothing so we return what we have */
if (ret <= 0) {

@ -408,9 +408,9 @@ uint32_t SCRConfReferenceHashFunc(HashTable *ht, void *data, uint16_t datalen)
{
SCRConfReference *ref = (SCRConfReference *)data;
uint32_t hash = 0;
int i = 0;
size_t i = 0;
int len = strlen(ref->system);
size_t len = strlen(ref->system);
for (i = 0; i < len; i++)
hash += u8_tolower((unsigned char)ref->system[i]);
@ -438,8 +438,8 @@ char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1,
{
SCRConfReference *ref1 = (SCRConfReference *)data1;
SCRConfReference *ref2 = (SCRConfReference *)data2;
int len1 = 0;
int len2 = 0;
size_t len1 = 0;
size_t len2 = 0;
if (ref1 == NULL || ref2 == NULL)
return 0;

@ -441,7 +441,8 @@ static inline void ConsolidateFwd(StreamingBuffer *sb, const StreamingBufferConf
if (sa->offset == region->stream_offset &&
sa_re > (region->stream_offset + region->buf_offset)) {
DEBUG_VALIDATE_BUG_ON(sa_re < region->stream_offset);
region->buf_offset = sa_re - region->stream_offset;
DEBUG_VALIDATE_BUG_ON(sa_re - region->stream_offset > UINT32_MAX);
region->buf_offset = (uint32_t)(sa_re - region->stream_offset);
SCLogDebug("-> (fwd) tr %p %" PRIu64 "/%u region %p so %" PRIu64
" bo %u sz %u BUF_OFFSET UPDATED",
sa, sa->offset, sa->len, region, region->stream_offset, region->buf_offset,
@ -457,8 +458,10 @@ static inline void ConsolidateFwd(StreamingBuffer *sb, const StreamingBufferConf
sa_re >= tr->offset && sa_re < tr_re) // ends inside
{
// merge. sb->sbb_size includes both so we need to adjust that too.
uint32_t combined_len = sa->len + tr->len;
sa->len = tr_re - sa->offset;
DEBUG_VALIDATE_BUG_ON(sa->len + tr->len > UINT32_MAX);
uint32_t combined_len = (uint32_t)(sa->len + tr->len);
DEBUG_VALIDATE_BUG_ON(tr_re - sa->offset > UINT32_MAX);
sa->len = (uint32_t)(tr_re - sa->offset);
sa_re = sa->offset + sa->len;
SCLogDebug("-> (fwd) tr %p %" PRIu64 "/%u REMOVED MERGED", tr, tr->offset, tr->len);
SBB_RB_REMOVE(tree, tr);
@ -471,7 +474,8 @@ static inline void ConsolidateFwd(StreamingBuffer *sb, const StreamingBufferConf
if (sa->offset == region->stream_offset &&
sa_re > (region->stream_offset + region->buf_offset)) {
DEBUG_VALIDATE_BUG_ON(sa_re < region->stream_offset);
region->buf_offset = sa_re - region->stream_offset;
DEBUG_VALIDATE_BUG_ON(sa_re - region->stream_offset > UINT32_MAX);
region->buf_offset = (uint32_t)(sa_re - region->stream_offset);
SCLogDebug("-> (fwd) tr %p %" PRIu64 "/%u region %p so %" PRIu64
" bo %u sz %u BUF_OFFSET UPDATED",
sa, sa->offset, sa->len, region, region->stream_offset, region->buf_offset,
@ -538,7 +542,8 @@ static inline void ConsolidateBackward(StreamingBuffer *sb, const StreamingBuffe
if (sa->offset == region->stream_offset &&
sa_re > (region->stream_offset + region->buf_offset)) {
DEBUG_VALIDATE_BUG_ON(sa_re < region->stream_offset);
region->buf_offset = sa_re - region->stream_offset;
DEBUG_VALIDATE_BUG_ON(sa_re - region->stream_offset > UINT32_MAX);
region->buf_offset = (uint32_t)(sa_re - region->stream_offset);
SCLogDebug("-> (bwd) tr %p %" PRIu64 "/%u region %p so %" PRIu64
" bo %u sz %u BUF_OFFSET UPDATED",
sa, sa->offset, sa->len, region, region->stream_offset, region->buf_offset,
@ -553,8 +558,10 @@ static inline void ConsolidateBackward(StreamingBuffer *sb, const StreamingBuffe
*/
} else if (sa->offset > tr->offset && sa_re > tr_re && sa->offset <= tr_re) {
// merge. sb->sbb_size includes both so we need to adjust that too.
uint32_t combined_len = sa->len + tr->len;
sa->len = sa_re - tr->offset;
DEBUG_VALIDATE_BUG_ON(sa->len + tr->len > UINT32_MAX);
uint32_t combined_len = (uint32_t)(sa->len + tr->len);
DEBUG_VALIDATE_BUG_ON(sa_re - tr->offset > UINT32_MAX);
sa->len = (uint32_t)(sa_re - tr->offset);
sa->offset = tr->offset;
sa_re = sa->offset + sa->len;
SCLogDebug("-> (bwd) tr %p %" PRIu64 "/%u REMOVED MERGED", tr, tr->offset, tr->len);
@ -570,7 +577,8 @@ static inline void ConsolidateBackward(StreamingBuffer *sb, const StreamingBuffe
if (sa->offset == region->stream_offset &&
sa_re > (region->stream_offset + region->buf_offset)) {
DEBUG_VALIDATE_BUG_ON(sa_re < region->stream_offset);
region->buf_offset = sa_re - region->stream_offset;
DEBUG_VALIDATE_BUG_ON(sa_re - region->stream_offset > UINT32_MAX);
region->buf_offset = (uint32_t)(sa_re - region->stream_offset);
SCLogDebug("-> (bwd) tr %p %" PRIu64 "/%u region %p so %" PRIu64
" bo %u sz %u BUF_OFFSET UPDATED",
sa, sa->offset, sa->len, region, region->stream_offset, region->buf_offset,
@ -656,7 +664,8 @@ static void SBBPrune(StreamingBuffer *sb, const StreamingBufferConfig *cfg)
/* partly before, partly beyond. Adjust */
if (sbb->offset < sb->region.stream_offset &&
sbb->offset + sbb->len > sb->region.stream_offset) {
uint32_t shrink_by = sb->region.stream_offset - sbb->offset;
DEBUG_VALIDATE_BUG_ON(sb->region.stream_offset - sbb->offset > UINT32_MAX);
uint32_t shrink_by = (uint32_t)(sb->region.stream_offset - sbb->offset);
DEBUG_VALIDATE_BUG_ON(shrink_by > sbb->len);
if (sbb->len >= shrink_by) {
sbb->len -= shrink_by;
@ -876,7 +885,8 @@ static inline void StreamingBufferSlideToOffsetWithRegions(
if (to_shift) {
// Do the shift. If new region is exactly at the slide offset we can skip this.
DEBUG_VALIDATE_BUG_ON(to_shift->stream_offset > slide_offset);
const uint32_t s = slide_offset - to_shift->stream_offset;
DEBUG_VALIDATE_BUG_ON(slide_offset - to_shift->stream_offset > UINT32_MAX);
const uint32_t s = (uint32_t)(slide_offset - to_shift->stream_offset);
if (s > 0) {
const uint32_t new_data_size = to_shift->buf_size - s;
uint32_t new_mem_size = ToNextMultipleOf(new_data_size, cfg->buf_size);
@ -891,15 +901,21 @@ static inline void StreamingBufferSlideToOffsetWithRegions(
StreamingBufferRegion *start = to_shift;
StreamingBufferRegion *next = start->next;
const uint64_t next_re = next->stream_offset + next->buf_size;
const uint32_t mem_size = ToNextMultipleOf(next_re - slide_offset, cfg->buf_size);
DEBUG_VALIDATE_BUG_ON(next_re - slide_offset > UINT32_MAX);
const uint32_t mem_size =
ToNextMultipleOf((uint32_t)(next_re - slide_offset), cfg->buf_size);
/* using next as the new main */
if (start->buf_size < next->buf_size) {
SCLogDebug("replace main with the next bigger region");
const uint32_t next_data_offset = next->stream_offset - slide_offset;
DEBUG_VALIDATE_BUG_ON(next->stream_offset - slide_offset > UINT32_MAX);
const uint32_t next_data_offset =
(uint32_t)(next->stream_offset - slide_offset);
const uint32_t prev_buf_size = next->buf_size;
const uint32_t start_data_offset = slide_offset - start->stream_offset;
DEBUG_VALIDATE_BUG_ON(slide_offset - start->stream_offset > UINT32_MAX);
const uint32_t start_data_offset =
(uint32_t)(slide_offset - start->stream_offset);
DEBUG_VALIDATE_BUG_ON(start_data_offset > start->buf_size);
if (start_data_offset > start->buf_size) {
new_mem_size = new_data_size;
@ -1033,7 +1049,8 @@ void StreamingBufferSlideToOffset(
}
if (offset > sb->region.stream_offset) {
const uint32_t slide = offset - sb->region.stream_offset;
DEBUG_VALIDATE_BUG_ON(offset - sb->region.stream_offset > UINT32_MAX);
const uint32_t slide = (uint32_t)(offset - sb->region.stream_offset);
if (sb->head != NULL) {
/* have sbb's, so can't rely on buf_offset for the slide */
if (slide < sb->region.buf_size) {
@ -1273,7 +1290,8 @@ static StreamingBufferRegion *BufferInsertAtRegionConsolidate(StreamingBuffer *s
// 2. resize dst
const uint32_t old_size = dst->buf_size;
const uint32_t dst_copy_offset = dst->stream_offset - dst_offset;
DEBUG_VALIDATE_BUG_ON(dst->stream_offset - dst_offset > UINT32_MAX);
const uint32_t dst_copy_offset = (uint32_t)(dst->stream_offset - dst_offset);
#ifdef DEBUG
const uint32_t old_offset = dst->buf_offset;
SCLogDebug("old_size %u, old_offset %u, dst_copy_offset %u", old_size, old_offset,
@ -1330,7 +1348,8 @@ static StreamingBufferRegion *BufferInsertAtRegionConsolidate(StreamingBuffer *s
r = r->next;
continue;
}
const uint32_t target_offset = r->stream_offset - dst_offset;
DEBUG_VALIDATE_BUG_ON(r->stream_offset - dst_offset > UINT32_MAX);
const uint32_t target_offset = (uint32_t)(r->stream_offset - dst_offset);
SCLogDebug("r %p: target_offset %u", r, target_offset);
DEBUG_VALIDATE_BUG_ON(target_offset > dst->buf_size);
DEBUG_VALIDATE_BUG_ON(target_offset + r->buf_size > dst->buf_size);
@ -1409,8 +1428,9 @@ static StreamingBufferRegion *BufferInsertAtRegionDo(StreamingBuffer *sb,
}
insert_adjusted_re = MAX(insert_adjusted_re, (end->stream_offset + end->buf_size));
uint32_t new_buf_size =
ToNextMultipleOf(insert_adjusted_re - insert_start_offset, cfg->buf_size);
DEBUG_VALIDATE_BUG_ON(insert_adjusted_re - insert_start_offset > UINT32_MAX);
uint32_t new_buf_size = ToNextMultipleOf(
(uint32_t)(insert_adjusted_re - insert_start_offset), cfg->buf_size);
SCLogDebug("new_buf_size %u", new_buf_size);
/* see if our new buf size + cfg->buf_size margin leads to an overlap with the next region.
@ -1419,8 +1439,9 @@ static StreamingBufferRegion *BufferInsertAtRegionDo(StreamingBuffer *sb,
SCLogDebug("adjusted end from %p to %p", end, end->next);
end = end->next;
insert_adjusted_re = MAX(insert_adjusted_re, (end->stream_offset + end->buf_size));
new_buf_size =
ToNextMultipleOf(insert_adjusted_re - insert_start_offset, cfg->buf_size);
DEBUG_VALIDATE_BUG_ON(insert_adjusted_re - insert_start_offset > UINT32_MAX);
new_buf_size = ToNextMultipleOf(
(uint32_t)(insert_adjusted_re - insert_start_offset), cfg->buf_size);
SCLogDebug("new_buf_size %u", new_buf_size);
}
@ -1531,7 +1552,8 @@ int StreamingBufferInsertAt(StreamingBuffer *sb, const StreamingBufferConfig *cf
SCLogDebug("inserting %" PRIu64 "/%u using %s region %p", offset, data_len,
region == &sb->region ? "main" : "aux", region);
uint32_t rel_offset = offset - region->stream_offset;
DEBUG_VALIDATE_BUG_ON(offset - region->stream_offset > UINT32_MAX);
uint32_t rel_offset = (uint32_t)(offset - region->stream_offset);
int r = DataFitsAtOffset(region, data_len, rel_offset);
if (r < 0) {
DEBUG_VALIDATE_BUG_ON(1);
@ -1684,7 +1706,7 @@ void StreamingBufferSBBGetData(const StreamingBuffer *sb,
return;
} else {
SCLogDebug("2");
uint64_t offset = region->stream_offset - sbb->offset;
uint32_t offset = (uint32_t)(region->stream_offset - sbb->offset);
if (offset < sbb->len) {
*data = region->buf;
*data_len = sbb->len - offset;
@ -1713,19 +1735,21 @@ void StreamingBufferSBBGetDataAtOffset(const StreamingBuffer *sb,
const StreamingBufferRegion *region = GetRegionForOffset(sb, offset);
if (region) {
uint32_t sbblen = sbb->len - (offset - sbb->offset);
DEBUG_VALIDATE_BUG_ON(sbb->len - (offset - sbb->offset) > UINT32_MAX);
uint32_t sbblen = (uint32_t)(sbb->len - (offset - sbb->offset));
if (offset >= region->stream_offset) {
uint64_t data_offset = offset - region->stream_offset;
uint32_t data_offset = (uint32_t)(offset - region->stream_offset);
*data = region->buf + data_offset;
if (data_offset + sbblen > region->buf_size)
if (data_offset + sbblen > region->buf_size) {
*data_len = region->buf_size - data_offset;
else
} else {
*data_len = sbblen;
}
DEBUG_VALIDATE_BUG_ON(*data_len > sbblen);
return;
} else {
uint64_t data_offset = region->stream_offset - sbb->offset;
uint32_t data_offset = (uint32_t)(region->stream_offset - sbb->offset);
if (data_offset < sbblen) {
*data = region->buf;
*data_len = sbblen - data_offset;
@ -1746,16 +1770,17 @@ void StreamingBufferSegmentGetData(const StreamingBuffer *sb,
const StreamingBufferRegion *region = GetRegionForOffset(sb, seg->stream_offset);
if (region) {
if (seg->stream_offset >= region->stream_offset) {
uint64_t offset = seg->stream_offset - region->stream_offset;
uint32_t offset = (uint32_t)(seg->stream_offset - region->stream_offset);
*data = region->buf + offset;
if (offset + seg->segment_len > region->buf_size)
if (offset + seg->segment_len > region->buf_size) {
*data_len = region->buf_size - offset;
else
} else {
*data_len = seg->segment_len;
}
SCLogDebug("*data_len %u", *data_len);
return;
} else {
uint64_t offset = region->stream_offset - seg->stream_offset;
uint32_t offset = (uint32_t)(region->stream_offset - seg->stream_offset);
if (offset < seg->segment_len) {
*data = region->buf;
*data_len = seg->segment_len - offset;
@ -1812,7 +1837,8 @@ int StreamingBufferGetDataAtOffset (const StreamingBuffer *sb,
const StreamingBufferRegion *region = GetRegionForOffset(sb, offset);
if (region != NULL && region->buf != NULL && offset >= region->stream_offset &&
offset < (region->stream_offset + region->buf_offset)) {
uint32_t skip = offset - region->stream_offset;
DEBUG_VALIDATE_BUG_ON(offset - region->stream_offset > UINT32_MAX);
uint32_t skip = (uint32_t)(offset - region->stream_offset);
*data = region->buf + skip;
*data_len = region->buf_offset - skip;
return 1;

@ -302,7 +302,7 @@ static int THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
return 0;
}
THashTableContext *THashInit(const char *cnf_prefix, size_t data_size,
THashTableContext *THashInit(const char *cnf_prefix, uint32_t data_size,
int (*DataSet)(void *, void *), void (*DataFree)(void *),
uint32_t (*DataHash)(uint32_t, void *), bool (*DataCompare)(void *, void *),
bool (*DataExpired)(void *, SCTime_t), uint32_t (*DataSize)(void *), bool reset_memcap,

@ -170,7 +170,7 @@ typedef struct THashTableContext_ {
#define THashDecrUsecnt(h) \
(void)SC_ATOMIC_SUB((h)->use_cnt, 1)
THashTableContext *THashInit(const char *cnf_prefix, size_t data_size,
THashTableContext *THashInit(const char *cnf_prefix, uint32_t data_size,
int (*DataSet)(void *dst, void *src), void (*DataFree)(void *),
uint32_t (*DataHash)(uint32_t, void *), bool (*DataCompare)(void *, void *),
bool (*DataExpired)(void *, SCTime_t), uint32_t (*DataSize)(void *), bool reset_memcap,

@ -957,12 +957,12 @@ static int SCThresholdConfLineIsMultiline(char *line)
{
int flag = 0;
char *rline = line;
int len = strlen(line);
size_t len = strlen(line);
while (line < rline + len && *line != '\n') {
/* we have a comment */
if (*line == '\\')
flag = line - rline;
flag = (int)(line - rline);
else
if (!isspace((unsigned char)*line))
flag = 0;

@ -549,7 +549,7 @@ int SCTimeToStringPattern (time_t epoch, const char *pattern, char *str, size_t
return 1;
}
int r = strftime(buffer, sizeof(buffer), pattern, tp);
size_t r = strftime(buffer, sizeof(buffer), pattern, tp);
if (r == 0) {
return 1;
}

@ -329,7 +329,8 @@ uint32_t VarNameStoreLookupByName(const char *name, const enum VarTypes type)
static uint32_t VariableNameHash(HashListTable *ht, void *buf, uint16_t buflen)
{
VariableName *vn = (VariableName *)buf;
uint32_t hash = StringHashDjb2((const uint8_t *)vn->name, strlen(vn->name)) + vn->type;
uint32_t hash =
StringHashDjb2((const uint8_t *)vn->name, (uint32_t)strlen(vn->name)) + vn->type;
return (hash % VARNAME_HASHSIZE);
}

Loading…
Cancel
Save