public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: Laine Stump <laine@redhat.com>
Subject: [PATCH] conf, tap: Silence two false positive invalidFunctionArg from cppcheck
Date: Thu, 16 Feb 2023 19:22:10 +0100	[thread overview]
Message-ID: <20230216182210.2290008-1-sbrivio@redhat.com> (raw)

The newly introduced die() calls exit(), but cppcheck doesn't see it
and warns about possibly invalid arguments used after the check which
triggers die(). Add return statements to silence the warnings.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 conf.c | 3 +++
 tap.c  | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/conf.c b/conf.c
index 675d961..5426c9b 100644
--- a/conf.c
+++ b/conf.c
@@ -1036,6 +1036,9 @@ static void conf_ugid(char *runas, uid_t *uid, gid_t *gid)
 	if ((fd = open("/proc/self/uid_map", O_RDONLY | O_CLOEXEC)) < 0) {
 		die("Can't determine if we're in init namespace: %s",
 		    strerror(errno));
+
+		/* Silence cppcheck's invalidFunctionArg for 'fd' in read() */
+		return;
 	}
 
 	if (read(fd, buf, BUFSIZ) != sizeof(root_uid_map) ||
diff --git a/tap.c b/tap.c
index 88eed88..d6f962e 100644
--- a/tap.c
+++ b/tap.c
@@ -1037,9 +1037,13 @@ static void tap_sock_unix_init(struct ctx *c)
 			snprintf(path, UNIX_PATH_MAX - 1, UNIX_SOCK_PATH, i);
 
 		ex = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
-		if (ex < 0)
+		if (ex < 0) {
 			die("UNIX domain socket check: %s", strerror(errno));
 
+			/* Silence cppcheck's invalidFunctionArg for 'ex' */
+			return;
+		}
+
 		ret = connect(ex, (const struct sockaddr *)&addr, sizeof(addr));
 		if (!ret || (errno != ENOENT && errno != ECONNREFUSED &&
 			     errno != EACCES)) {
-- 
@@ -1037,9 +1037,13 @@ static void tap_sock_unix_init(struct ctx *c)
 			snprintf(path, UNIX_PATH_MAX - 1, UNIX_SOCK_PATH, i);
 
 		ex = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
-		if (ex < 0)
+		if (ex < 0) {
 			die("UNIX domain socket check: %s", strerror(errno));
 
+			/* Silence cppcheck's invalidFunctionArg for 'ex' */
+			return;
+		}
+
 		ret = connect(ex, (const struct sockaddr *)&addr, sizeof(addr));
 		if (!ret || (errno != ENOENT && errno != ECONNREFUSED &&
 			     errno != EACCES)) {
-- 
2.35.1


             reply	other threads:[~2023-02-16 18:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16 18:22 Stefano Brivio [this message]
2023-02-16 22:53 ` [PATCH] conf, tap: Silence two false positive invalidFunctionArg from cppcheck David Gibson
2023-02-17  8:04   ` Stefano Brivio
2023-02-17  9:10     ` David Gibson
2023-02-17 14:29   ` Laine Stump
2023-02-17 14:37     ` Stefano Brivio

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=20230216182210.2290008-1-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=laine@redhat.com \
    --cc=passt-dev@passt.top \
    /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).