From 9e64555c5e3a683652e756db5d283f000a8c5166 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 22 May 2025 14:59:16 +0200 Subject: [PATCH] util: fix -Wshorten-64-to-32 warnings for afpacket Ticket: #6186 --- src/runmode-af-packet.c | 10 +++++----- src/source-af-packet.c | 2 +- src/threads.h | 13 +++++++------ src/util-systemd.c | 3 ++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index 93746a2fbe..940eece3a0 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -597,12 +597,12 @@ static void *ParseAFPConfig(const char *iface) } if ((SCConfGetChildValueIntWithDefault(if_root, if_default, "buffer-size", &value)) == 1) { - aconf->buffer_size = value; + aconf->buffer_size = (int)value; } else { aconf->buffer_size = 0; } if ((SCConfGetChildValueIntWithDefault(if_root, if_default, "ring-size", &value)) == 1) { - aconf->ring_size = value; + aconf->ring_size = (int)value; } if ((SCConfGetChildValueIntWithDefault(if_root, if_default, "block-size", &value)) == 1) { @@ -610,12 +610,12 @@ static void *ParseAFPConfig(const char *iface) SCLogWarning("%s: block-size %" PRIuMAX " must be a multiple of pagesize (%u).", iface, value, getpagesize()); } else { - aconf->block_size = value; + aconf->block_size = (int)value; } } if ((SCConfGetChildValueIntWithDefault(if_root, if_default, "block-timeout", &value)) == 1) { - aconf->block_timeout = value; + aconf->block_timeout = (int)value; } else { aconf->block_timeout = 10; } @@ -625,7 +625,7 @@ static void *ParseAFPConfig(const char *iface) SCLogWarning("%s: v2-block-size %" PRIuMAX " must be a multiple of pagesize (%u).", iface, value, getpagesize()); } else { - aconf->v2_block_size = value; + aconf->v2_block_size = (int)value; } } diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 427c9f717f..e5c2c23fc4 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -2744,7 +2744,7 @@ static void UpdateRawDataForVLANHdr(Packet *p) { if (p->afp_v.vlan_tci != 0) { uint8_t *pstart = GET_PKT_DATA(p) - VLAN_HEADER_LEN; - size_t plen = GET_PKT_LEN(p) + VLAN_HEADER_LEN; + uint32_t plen = GET_PKT_LEN(p) + VLAN_HEADER_LEN; /* move ethernet addresses */ memmove(pstart, GET_PKT_DATA(p), 2 * ETH_ALEN); /* write vlan info */ diff --git a/src/threads.h b/src/threads.h index e2b0daa07c..b16848f034 100644 --- a/src/threads.h +++ b/src/threads.h @@ -252,12 +252,13 @@ enum { }) #else -#define SCGetThreadIdLong(...) ({ \ - pid_t tmpthid; \ - tmpthid = syscall(SYS_gettid); \ - unsigned long _scgetthread_tid = (unsigned long)tmpthid; \ - _scgetthread_tid; \ -}) +#define SCGetThreadIdLong(...) \ + ({ \ + pid_t tmpthid; \ + tmpthid = (pid_t)syscall(SYS_gettid); \ + unsigned long _scgetthread_tid = (unsigned long)tmpthid; \ + _scgetthread_tid; \ + }) #endif /* OS FREEBSD */ extern thread_local char t_thread_name[THREAD_NAME_LEN + 1]; diff --git a/src/util-systemd.c b/src/util-systemd.c index ad2b0ae4fa..cfa51c0c4a 100644 --- a/src/util-systemd.c +++ b/src/util-systemd.c @@ -74,7 +74,8 @@ static int Notify(const char *message) if (fd < 0) return -errno; - if (connect(fd, &socket_addr.sa, offsetof(struct sockaddr_un, sun_path) + path_length) != 0) + if (connect(fd, &socket_addr.sa, + offsetof(struct sockaddr_un, sun_path) + (uint32_t)path_length) != 0) return -errno; ssize_t written = write(fd, message, message_length); -- 2.47.3