From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v2 5/6] cppcheck: Suppress variable scope warnings in dhcpv6()
Date: Thu, 2 Oct 2025 14:50:11 +1000 [thread overview]
Message-ID: <20251002045012.4047974-6-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20251002045012.4047974-1-david@gibson.dropbear.id.au>
At least some cppcheck versions (2.18.3 for me) complain that the _storage
variables in dhcpv6() could be reduced in scope. That's not actually the
case, because although we don't reference the variables, we may touch
their memory via pointers after the blocks in question. There's no
reasonable way for cppcheck to determine that, though, so suppress its
warnings.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
dhcpv6.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/dhcpv6.c b/dhcpv6.c
index c1a27aba..e4df0db5 100644
--- a/dhcpv6.c
+++ b/dhcpv6.c
@@ -550,10 +550,18 @@ int dhcpv6(struct ctx *c, struct iov_tail *data,
{
const struct opt_server_id *server_id = NULL;
const struct opt_hdr *client_id = NULL;
+ /* The _storage variables can't be local to the blocks they're used in,
+ * because IOV_*_HEADER() may return pointers to them which are
+ * dereferenced afterwards. Since we don't have Rust-like lifetime
+ * tracking, cppcheck can't reasonably determine that, so we must
+ * suppress its warnings. */
+ /* cppcheck-suppress [variableScope,unmatchedSuppression] */
struct opt_server_id server_id_storage;
struct iov_tail opt, client_id_base;
const struct opt_ia_na *ia = NULL;
+ /* cppcheck-suppress [variableScope,unmatchedSuppression] */
struct opt_hdr client_id_storage;
+ /* cppcheck-suppress [variableScope,unmatchedSuppression] */
struct opt_ia_na ia_storage;
const struct in6_addr *src;
struct msg_hdr mh_storage;
--
2.51.0
next prev parent reply other threads:[~2025-10-02 4:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-02 4:50 [PATCH v2 0/6] Test and linter fixups David Gibson
2025-10-02 4:50 ` [PATCH v2 1/6] test: Add linting of Python test scripts David Gibson
2025-10-02 4:50 ` [PATCH v2 2/6] clang-tidy: Suppress redundant expression warning David Gibson
2025-10-02 4:50 ` [PATCH v2 3/6] cppcheck: Suppress the suppression of a suppression David Gibson
2025-10-02 4:50 ` [PATCH v2 4/6] cppcheck: Suppress a buggy cppcheck warning David Gibson
2025-10-02 4:50 ` David Gibson [this message]
2025-10-02 4:50 ` [PATCH v2 6/6] test: Don't delete exetool on make clean David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251002045012.4047974-6-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).