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 */
static int UnixNew(UnixCommand * this)
{
struct sockaddr_un addr;
- int len;
+ socklen_t len;
int ret;
int on = 1;
char sockettarget[PATH_MAX];
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);
json_error_t jerror;
int client;
int client_version;
- int ret;
+ ssize_t ret;
UnixClient *uclient = NULL;
/* accept client socket */
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) {
json_t *server_msg, void *data)
{
SCEnter();
- int uptime;
+ time_t uptime;
UnixCommand *ucmd = (UnixCommand *)data;
uptime = time(NULL) - ucmd->start_timestamp;
{
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);
}
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);
}
return -1;
}
- return (endptr - ptr);
+ return (int)(endptr - ptr);
}
int ByteExtractStringUint64(uint64_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)
{
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]);
{
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;
* 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";
}
}
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;
}
*/
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)
*/
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;
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;
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])))
typedef struct JA3Buffer_ {
char *data;
- size_t size;
- size_t used;
+ uint32_t size;
+ uint32_t used;
} JA3Buffer;
JA3Buffer *Ja3BufferInit(void);
#include "util-landlock.h"
#include "util-mem.h"
#include "util-path.h"
+#include "util-validate.h"
#ifndef HAVE_LINUX_LANDLOCK_H
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
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
* 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)) {
}
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;
}
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");
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;
}
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;
}
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");
}
/* 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;
* 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)
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;
}
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;
}
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) {
{
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]);
{
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;
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,
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);
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,
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,
*/
} 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);
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,
/* 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;
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);
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;
}
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) {
// 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,
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);
}
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.
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);
}
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);
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;
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;
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;
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;
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,
#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,
{
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;
return 1;
}
- int r = strftime(buffer, sizeof(buffer), pattern, tp);
+ size_t r = strftime(buffer, sizeof(buffer), pattern, tp);
if (r == 0) {
return 1;
}
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);
}