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 13/13] qrap: Run static checkers
Date: Tue, 21 Apr 2026 12:43:44 +1000 [thread overview]
Message-ID: <20260421024344.1379633-14-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260421024344.1379633-1-david@gibson.dropbear.id.au>
Run the static checkers on qrap as well as on passt-repair and passt. This
shows a number of minor warnings, which we fix.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
Makefile | 9 +++++++--
qrap.c | 42 ++++++++++++++++++++++++++----------------
2 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
index d29f46d2..7875d23b 100644
--- a/Makefile
+++ b/Makefile
@@ -183,7 +183,7 @@ docs: README.md
CLANG_TIDY = clang-tidy
CLANG_TIDY_FLAGS = -DCLANG_TIDY_58992
-clang-tidy: passt.clang-tidy passt-repair.clang-tidy
+clang-tidy: passt.clang-tidy passt-repair.clang-tidy qrap.clang-tidy
.PHONY: %.clang-tidy
%.clang-tidy:
@@ -191,6 +191,7 @@ clang-tidy: passt.clang-tidy passt-repair.clang-tidy
passt.clang-tidy: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h
passt-repair.clang-tidy: $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS) seccomp_repair.h
+qrap.clang-tidy: $(QRAP_SRCS) $(QRAP_HEADERS)
CPPCHECK = cppcheck
CPPCHECK_FLAGS = --std=c11 --error-exitcode=1 --enable=all --force \
@@ -205,7 +206,7 @@ CPPCHECK_FLAGS = --std=c11 --error-exitcode=1 --enable=all --force \
--suppress=unusedStructMember \
-D CPPCHECK_6936
-cppcheck: passt.cppcheck passt-repair.cppcheck
+cppcheck: passt.cppcheck passt-repair.cppcheck qrap.cppcheck
.PHONY: %.cppcheck
%.cppcheck:
@@ -213,3 +214,7 @@ cppcheck: passt.cppcheck passt-repair.cppcheck
passt.cppcheck: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h
passt-repair.cppcheck: $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS) seccomp_repair.h
+
+qrap.cppcheck: BASE_CPPFLAGS += -DARCH=\"$(TARGET_ARCH)\"
+qrap.cppcheck: CPPCHECK_FLAGS += --suppress=unusedFunction
+qrap.cppcheck: $(QRAP_SRCS) $(QRAP_HEADERS)
diff --git a/qrap.c b/qrap.c
index d5967062..4a01ed83 100644
--- a/qrap.c
+++ b/qrap.c
@@ -46,6 +46,15 @@ static char *qemu_names[] = {
NULL,
};
+#define BUILDARG(s_, ...) \
+ do { \
+ static_assert(sizeof(s_) == ARG_MAX, "Bad buffer size"); \
+ if (snprintf((s_), ARG_MAX, __VA_ARGS__) >= ARG_MAX) { \
+ FPRINTF(stderr, "Arguments too long"); \
+ exit(EXIT_FAILURE); \
+ } \
+ } while (0)
+
/**
* struct drop_arg - Drop matching arguments on command line
* @name: Option name
@@ -120,11 +129,11 @@ static const struct pci_dev {
* usage() - Print usage and exit
* @name: Executable name
*/
-void usage(const char *name)
+static void usage(const char *name)
{
- fprintf(stderr, "Usage: %s [FDNUM QEMU_CMD] [QEMU_ARG]...\n", name);
- fprintf(stderr, "\n");
- fprintf(stderr, "If first and second arguments aren't a socket number\n"
+ FPRINTF(stderr, "Usage: %s [FDNUM QEMU_CMD] [QEMU_ARG]...\n", name);
+ FPRINTF(stderr, "\n");
+ FPRINTF(stderr, "If first and second arguments aren't a socket number\n"
"and a path, %s will try to locate a qemu binary\n"
"and directly patch the command line\n", name);
@@ -202,13 +211,14 @@ int main(int argc, char **argv)
errno = 0;
fd = strtol(argv[1], NULL, 0);
if (fd >= 3 && fd < INT_MAX && !errno && path) {
- char env_path[ARG_MAX + 1], *p, command[ARG_MAX];
+ char env_path[ARG_MAX + 1], command[ARG_MAX];
+ const char *p;
strncpy(env_path, path, ARG_MAX);
/* cppcheck-suppress strtokCalled */
p = strtok(env_path, ":");
while (p) {
- snprintf(command, ARG_MAX, "%s/%s", p, argv[2]);
+ BUILDARG(command, "%s/%s", p, argv[2]);
if (!access(command, X_OK))
goto valid_args;
@@ -281,7 +291,7 @@ int main(int argc, char **argv)
break;
}
if (i == dev->last) {
- fprintf(stderr, "Couldn't find free address for device\n");
+ FPRINTF(stderr, "Couldn't find free address for device\n");
usage(argv[0]);
}
@@ -289,21 +299,21 @@ int main(int argc, char **argv)
qemu_argv[qemu_argc++] = "-device";
if (!has_json) {
if (dev->base == 16) {
- snprintf(dev_str, ARG_MAX,
- "%s,%s%x%s,netdev=hostnet0,x-txburst=4096",
+ BUILDARG(dev_str,
+ "%s,%s%x%s,netdev=hostnet0,x-txburst=4096",
dev->name, dev->template, i, dev->template_post);
} else if (dev->base == 10) {
- snprintf(dev_str, ARG_MAX,
+ BUILDARG(dev_str,
"%s,%s%d%s,netdev=hostnet0,x-txburst=4096",
dev->name, dev->template, i, dev->template_post);
}
} else {
if (dev->base == 16) {
- snprintf(dev_str, ARG_MAX,
+ BUILDARG(dev_str,
"{\"driver\":\"%s\",%s%x\"%s,\"netdev\":\"hostnet0\",\"x-txburst\":4096}",
dev->name, dev->template_json, i, dev->template_json_post);
} else if (dev->base == 10) {
- snprintf(dev_str, ARG_MAX,
+ BUILDARG(dev_str,
"{\"driver\":\"%s\",%s%d\"%s,\"netdev\":\"hostnet0\",\"x-txburst\":4096}",
dev->name, dev->template_json, i, dev->template_json_post);
}
@@ -335,7 +345,7 @@ retry:
if (setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)))
perror("setsockopt SO_SNDTIMEO");
- snprintf(addr.sun_path, UNIX_PATH_MAX, UNIX_SOCK_PATH, i);
+ (void)snprintf(addr.sun_path, UNIX_PATH_MAX, UNIX_SOCK_PATH, i);
errno = 0;
@@ -381,7 +391,7 @@ retry:
goto retry;
}
- fprintf(stderr, "Probe of %s failed\n", addr.sun_path);
+ FPRINTF(stderr, "Probe of %s failed\n", addr.sun_path);
close(s);
}
@@ -397,7 +407,7 @@ retry:
if (setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)))
perror("setsockopt, SO_SNDTIMEO reset");
- fprintf(stderr, "Connected to %s\n", addr.sun_path);
+ FPRINTF(stderr, "Connected to %s\n", addr.sun_path);
if (dup2(s, (int)fd) < 0) {
perror("dup");
@@ -418,7 +428,7 @@ retry:
}
}
if (errno == ENOENT)
- fprintf(stderr, "Couldn't find qemu command\n");
+ FPRINTF(stderr, "Couldn't find qemu command\n");
} else {
execvp(argv[2], argv + 2);
}
--
2.53.0
next prev parent reply other threads:[~2026-04-21 2:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 2:43 [PATCH 00/13] Improvements to static checker invocation David Gibson
2026-04-21 2:43 ` [PATCH 01/13] Makefile: Use make variables for static checker configuration David Gibson
2026-04-21 2:43 ` [PATCH 02/13] cppcheck: Split out essential defines into a BASE_CPPFLAGS variable David Gibson
2026-04-21 2:43 ` [PATCH 03/13] Makefile: Remove preprocessor flags from $(FLAGS) David Gibson
2026-04-21 2:43 ` [PATCH 04/13] Makefile: Remove non-standard $(FLAGS) variable David Gibson
2026-04-21 2:43 ` [PATCH 05/13] Makefile: Make conditional definition of $(BIN) clearer David Gibson
2026-04-21 2:43 ` [PATCH 06/13] Makefile: Use common binary compilation rule David Gibson
2026-04-21 2:43 ` [PATCH 07/13] Makefile: Remove unhelpful $(HEADERS) variable David Gibson
2026-04-21 2:43 ` [PATCH 08/13] Makefile: Add header dependencies for secondary binaries David Gibson
2026-04-21 2:43 ` [PATCH 09/13] Makefile: Split static checker targets David Gibson
2026-04-21 2:43 ` [PATCH 10/13] passt-repair: Split out inotify handling to its own function David Gibson
2026-04-21 2:43 ` [PATCH 11/13] passt-repair: Simplify construction of Unix path from inotify David Gibson
2026-04-21 2:43 ` [PATCH 12/13] passt-repair: Run static checkers David Gibson
2026-04-21 2:43 ` David Gibson [this message]
2026-04-21 3:03 ` [PATCH 00/13] Improvements to static checker invocation 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=20260421024344.1379633-14-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).