public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH 0/3] cppcheck-2.19.1 fixes
@ 2026-01-13  3:54 David Gibson
  2026-01-13  3:54 ` [PATCH 1/3] treewide: Fix more pointers which can be const David Gibson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Gibson @ 2026-01-13  3:54 UTC (permalink / raw)
  To: passt-dev, Stefano Brivio; +Cc: David Gibson

Here are some more fixes for cppcheck warnings that I'm seeing with
cppcheck-2.19.1.  One looks like it might, at least theoretically be a
real bug.

I'm not certain if all of these are due to a new cppcheck version, or
if some are just due to things merged recently that hadn't previously
been checked with a recent-ish version.

David Gibson (3):
  treewide: Fix more pointers which can be const
  epoll_ctl: Move u64 variant first for safer initialisation
  igmp: Remove apparently unneeded suppression

 conf.c       | 2 +-
 dhcpv6.c     | 3 ++-
 epoll_ctl.h  | 4 ++--
 igmp.c       | 1 -
 vhost_user.c | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] treewide: Fix more pointers which can be const
  2026-01-13  3:54 [PATCH 0/3] cppcheck-2.19.1 fixes David Gibson
@ 2026-01-13  3:54 ` David Gibson
  2026-01-13  3:54 ` [PATCH 2/3] epoll_ctl: Move u64 variant first for safer initialisation David Gibson
  2026-01-13  3:54 ` [PATCH 3/3] igmp: Remove apparently unneeded suppression David Gibson
  2 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2026-01-13  3:54 UTC (permalink / raw)
  To: passt-dev, Stefano Brivio; +Cc: David Gibson

Here are some more pointers which can be const, as reported by cppcheck
2.19.1.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 conf.c       | 2 +-
 dhcpv6.c     | 3 ++-
 vhost_user.c | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/conf.c b/conf.c
index b1fc4b9f..a242fda1 100644
--- a/conf.c
+++ b/conf.c
@@ -1224,7 +1224,7 @@ dns6:
  *
  * Return: 0 on success, negative error code on failure
  */
-static int conf_runas(char *opt, unsigned int *uid, unsigned int *gid)
+static int conf_runas(const char *opt, unsigned int *uid, unsigned int *gid)
 {
 	const char *uopt, *gopt = NULL;
 	char *sep = strchr(opt, ':');
diff --git a/dhcpv6.c b/dhcpv6.c
index d94be23a..97c04e2c 100644
--- a/dhcpv6.c
+++ b/dhcpv6.c
@@ -320,7 +320,7 @@ static bool dhcpv6_opt(struct iov_tail *data, uint16_t type)
 static bool dhcpv6_ia_notonlink(struct iov_tail *data,
 				struct in6_addr *la)
 {
-	int ia_types[2] = { OPT_IA_NA, OPT_IA_TA }, *ia_type;
+	int ia_types[2] = { OPT_IA_NA, OPT_IA_TA };
 	struct opt_ia_addr opt_addr_storage;
 	const struct opt_ia_addr *opt_addr;
 	struct iov_tail current, ia_base;
@@ -330,6 +330,7 @@ static bool dhcpv6_ia_notonlink(struct iov_tail *data,
 	struct in6_addr req_addr;
 	struct opt_hdr h_storage;
 	const struct opt_hdr *h;
+	const int *ia_type;
 
 	foreach(ia_type, ia_types) {
 		current = *data;
diff --git a/vhost_user.c b/vhost_user.c
index 1e320bff..9fe12411 100644
--- a/vhost_user.c
+++ b/vhost_user.c
@@ -442,7 +442,7 @@ static bool vu_set_mem_table_exec(struct vu_dev *vdev,
 	for (i = 0; i < vdev->memory.nregions; i++) {
 		struct vhost_user_memory_region *msg_region = &memory->regions[i];
 		struct vu_dev_region *dev_region = &vdev->memory.regions[i];
-		void *mmap_addr;
+		const void *mmap_addr;
 
 		debug("vhost-user region %d", i);
 		debug("    guest_phys_addr: 0x%016"PRIx64,
-- 
2.52.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] epoll_ctl: Move u64 variant first for safer initialisation
  2026-01-13  3:54 [PATCH 0/3] cppcheck-2.19.1 fixes David Gibson
  2026-01-13  3:54 ` [PATCH 1/3] treewide: Fix more pointers which can be const David Gibson
@ 2026-01-13  3:54 ` David Gibson
  2026-01-13  3:54 ` [PATCH 3/3] igmp: Remove apparently unneeded suppression David Gibson
  2 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2026-01-13  3:54 UTC (permalink / raw)
  To: passt-dev, Stefano Brivio; +Cc: David Gibson

cppcheck-2.19.1 pointed out that an initialiser like:
	union epoll_ref foo = { 0 };
doesn't necessarily zero the whole union, because the first variant listed
may not be the full length.  I don't think this is actually broken in
practice, but I'm not 100% certain about that.

In any case, make it more clearly correct, and stop cppcheck complaining
by moving the @u64 variant to be the first one.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 epoll_ctl.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/epoll_ctl.h b/epoll_ctl.h
index 3f802e76..2c103cde 100644
--- a/epoll_ctl.h
+++ b/epoll_ctl.h
@@ -17,6 +17,7 @@
 
 /**
  * union epoll_ref - Breakdown of reference for epoll fd bookkeeping
+ * @u64:	Opaque reference for epoll_ctl() and epoll_wait()
  * @type:	Type of fd (tells us what to do with events)
  * @fd:		File descriptor number (implies < 2^24 total descriptors)
  * @flow:	Index of the flow this fd is linked to
@@ -25,9 +26,9 @@
  * @data:	Data handled by protocol handlers
  * @nsdir_fd:	netns dirfd for fallback timer checking if namespace is gone
  * @queue:	vhost-user queue index for this fd
- * @u64:	Opaque reference for epoll_ctl() and epoll_wait()
  */
 union epoll_ref {
+	uint64_t u64;
 	struct {
 		enum epoll_type type:8;
 		int32_t		  fd:FD_REF_BITS;
@@ -40,7 +41,6 @@ union epoll_ref {
 			int queue;
 		};
 	};
-	uint64_t u64;
 };
 static_assert(sizeof(union epoll_ref) <= sizeof(union epoll_data),
 	      "epoll_ref must have same size as epoll_data");
-- 
2.52.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] igmp: Remove apparently unneeded suppression
  2026-01-13  3:54 [PATCH 0/3] cppcheck-2.19.1 fixes David Gibson
  2026-01-13  3:54 ` [PATCH 1/3] treewide: Fix more pointers which can be const David Gibson
  2026-01-13  3:54 ` [PATCH 2/3] epoll_ctl: Move u64 variant first for safer initialisation David Gibson
@ 2026-01-13  3:54 ` David Gibson
  2 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2026-01-13  3:54 UTC (permalink / raw)
  To: passt-dev, Stefano Brivio; +Cc: David Gibson

cppcheck-2.19.1 complains that the unusedFunction suppression in igmp.c
doesn't match.  That seems like a cppcheck bug, because the function
clearly *is* unused.  The function exists because otherwise the compiler
fails because "ISO C forbids an empty translation unit".

mld.c contains an identical unused definition for the same reason, but
without the suppression.  It doesn't seem to have caused unusedFunction
warnings,  so maybe cppcheck counts the non-empty translation unit
requirement as a "use" of the function?

In any case, since omitting the suppression in mld.c seems to be fine, do
the same in igmp.c to stop the complaints.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 igmp.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/igmp.c b/igmp.c
index 0e775843..a3971fc6 100644
--- a/igmp.c
+++ b/igmp.c
@@ -13,5 +13,4 @@
  */
 
 /* TO BE IMPLEMENTED */
-/* cppcheck-suppress unusedFunction */
 __attribute__((__unused__)) static void unused(void) { }
-- 
2.52.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-13  3:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-13  3:54 [PATCH 0/3] cppcheck-2.19.1 fixes David Gibson
2026-01-13  3:54 ` [PATCH 1/3] treewide: Fix more pointers which can be const David Gibson
2026-01-13  3:54 ` [PATCH 2/3] epoll_ctl: Move u64 variant first for safer initialisation David Gibson
2026-01-13  3:54 ` [PATCH 3/3] igmp: Remove apparently unneeded suppression David Gibson

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).