From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202410 header.b=MzFRzOku; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 3C9415A004E for ; Fri, 25 Oct 2024 02:52:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1729817532; bh=1JoRG6wGrV3gnu8PHd8JabYaA/cakMjTCTh3+nNiOAg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MzFRzOkuD3pjlWBQ9sYHixN4Z83QUB3nmoM/fj9uAppnSgOoEsLDiLRhJa591XUqp fdr6KolydIWYYLWUqieh00gPN57cpcHh3V4TMpYzUXn7lJWkPm9SxqDhrnFANfKchr E5TMPRaJsPkde71Fgxne7sOLxi+3p0lax7EdqlcL9j3Rx9PPiP97iRCTklo0rtv/zE VNANlLs3wJszuOeVfD2yWnZmjXfP0xY9mXKvaj03Xc4nWLc8RHbmw0m1OplJ+c6alD 6NcsspOK29PWitTCYUNmAVTpIo+JUK3k3LJMmHiOQCCb1pBS/awMVIJZkFb6jaC8UO 5SV0kQNoj2RGg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XZPPm3ZJ0z4w2K; Fri, 25 Oct 2024 11:52:12 +1100 (AEDT) Date: Fri, 25 Oct 2024 11:52:05 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 3/8] treewide: Silence cert-err33-c clang-tidy warnings for fprintf() Message-ID: References: <20241024230438.3192725-1-sbrivio@redhat.com> <20241024230438.3192725-4-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="POLUk+uiFbkuzP9W" Content-Disposition: inline In-Reply-To: <20241024230438.3192725-4-sbrivio@redhat.com> Message-ID-Hash: U4D2ZUPJ3GHAM2R7LJMNSJST7UQCQUAO X-Message-ID-Hash: U4D2ZUPJ3GHAM2R7LJMNSJST7UQCQUAO X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --POLUk+uiFbkuzP9W Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 25, 2024 at 01:04:33AM +0200, Stefano Brivio wrote: > We use fprintf() to print to standard output or standard error > streams. If something gets truncated or there's an output error, we > don't really want to try and report that, and at the same time it's > not abnormal behaviour upon which we should terminate, either. >=20 > Just silence the warning with an ugly FPRINTF() variadic macro casting > the fprintf() expressions to void. Again, not sure why I'm not seeing this with my clang version, but regardle= ss: Reviewed-by: David Gibson >=20 > Signed-off-by: Stefano Brivio > --- > conf.c | 46 +++++++++++++++++++++++----------------------- > log.c | 6 +++--- > util.h | 3 +++ > 3 files changed, 29 insertions(+), 26 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 2122600..9af15fe 100644 > --- a/conf.c > +++ b/conf.c > @@ -731,19 +731,19 @@ static unsigned int conf_ip6(unsigned int ifi, stru= ct ip6_ctx *ip6) > static void usage(const char *name, FILE *f, int status) > { > if (strstr(name, "pasta")) { > - fprintf(f, "Usage: %s [OPTION]... [COMMAND] [ARGS]...\n", name); > - fprintf(f, " %s [OPTION]... PID\n", name); > - fprintf(f, " %s [OPTION]... --netns [PATH|NAME]\n", name); > - fprintf(f, > + FPRINTF(f, "Usage: %s [OPTION]... [COMMAND] [ARGS]...\n", name); > + FPRINTF(f, " %s [OPTION]... PID\n", name); > + FPRINTF(f, " %s [OPTION]... --netns [PATH|NAME]\n", name); > + FPRINTF(f, > "\n" > "Without PID or --netns, run the given command or a\n" > "default shell in a new network and user namespace, and\n" > "connect it via pasta.\n"); > } else { > - fprintf(f, "Usage: %s [OPTION]...\n", name); > + FPRINTF(f, "Usage: %s [OPTION]...\n", name); > } > =20 > - fprintf(f, > + FPRINTF(f, > "\n" > " -d, --debug Be verbose\n" > " --trace Be extra verbose, implies --debug\n" > @@ -760,17 +760,17 @@ static void usage(const char *name, FILE *f, int st= atus) > " --version Show version and exit\n"); > =20 > if (strstr(name, "pasta")) { > - fprintf(f, > + FPRINTF(f, > " -I, --ns-ifname NAME namespace interface name\n" > " default: same interface name as external one\n"); > } else { > - fprintf(f, > + FPRINTF(f, > " -s, --socket PATH UNIX domain socket path\n" > " default: probe free path starting from " > UNIX_SOCK_PATH "\n", 1); > } > =20 > - fprintf(f, > + FPRINTF(f, > " -F, --fd FD Use FD as pre-opened connected socket\n" > " -p, --pcap FILE Log tap-facing traffic to pcap file\n" > " -P, --pid FILE Write own PID to the given file\n" > @@ -801,28 +801,28 @@ static void usage(const char *name, FILE *f, int st= atus) > " can be specified multiple times\n" > " a single, empty option disables DNS information\n"); > if (strstr(name, "pasta")) > - fprintf(f, " default: don't use any addresses\n"); > + FPRINTF(f, " default: don't use any addresses\n"); > else > - fprintf(f, " default: use addresses from /etc/resolv.conf\n"); > - fprintf(f, > + FPRINTF(f, " default: use addresses from /etc/resolv.conf\n"); > + FPRINTF(f, > " -S, --search LIST Space-separated list, search domains\n" > " a single, empty option disables the DNS search list\n"); > if (strstr(name, "pasta")) > - fprintf(f, " default: don't use any search list\n"); > + FPRINTF(f, " default: don't use any search list\n"); > else > - fprintf(f, " default: use search list from /etc/resolv.conf\n"); > + FPRINTF(f, " default: use search list from /etc/resolv.conf\n"); > =20 > if (strstr(name, "pasta")) > - fprintf(f, " --dhcp-dns \tPass DNS list via DHCP/DHCPv6/NDP\n"); > + FPRINTF(f, " --dhcp-dns \tPass DNS list via DHCP/DHCPv6/NDP\n"); > else > - fprintf(f, " --no-dhcp-dns No DNS list in DHCP/DHCPv6/NDP\n"); > + FPRINTF(f, " --no-dhcp-dns No DNS list in DHCP/DHCPv6/NDP\n"); > =20 > if (strstr(name, "pasta")) > - fprintf(f, " --dhcp-search Pass list via DHCP/DHCPv6/NDP\n"); > + FPRINTF(f, " --dhcp-search Pass list via DHCP/DHCPv6/NDP\n"); > else > - fprintf(f, " --no-dhcp-search No list in DHCP/DHCPv6/NDP\n"); > + FPRINTF(f, " --no-dhcp-search No list in DHCP/DHCPv6/NDP\n"); > =20 > - fprintf(f, > + FPRINTF(f, > " --map-host-loopback ADDR Translate ADDR to refer to host\n" > " can be specified zero to two times (for IPv4 and IPv6)\n" > " default: gateway address\n" > @@ -850,7 +850,7 @@ static void usage(const char *name, FILE *f, int stat= us) > if (strstr(name, "pasta")) > goto pasta_opts; > =20 > - fprintf(f, > + FPRINTF(f, > " -1, --one-off Quit after handling one single client\n" > " -t, --tcp-ports SPEC TCP port forwarding to guest\n" > " can be specified multiple times\n" > @@ -881,7 +881,7 @@ static void usage(const char *name, FILE *f, int stat= us) > =20 > pasta_opts: > =20 > - fprintf(f, > + FPRINTF(f, > " -t, --tcp-ports SPEC TCP port forwarding to namespace\n" > " can be specified multiple times\n" > " SPEC can be:\n" > @@ -1419,9 +1419,9 @@ void conf(struct ctx *c, int argc, char **argv) > =20 > break; > case 14: > - fprintf(stdout, > + FPRINTF(stdout, > c->mode =3D=3D MODE_PASTA ? "pasta " : "passt "); > - fprintf(stdout, VERSION_BLOB); > + FPRINTF(stdout, VERSION_BLOB); > exit(EXIT_SUCCESS); > case 15: > ret =3D snprintf(c->ip4.ifname_out, > diff --git a/log.c b/log.c > index a61468e..6932885 100644 > --- a/log.c > +++ b/log.c > @@ -274,7 +274,7 @@ void vlogmsg(bool newline, bool cont, int pri, const = char *format, va_list ap) > char timestr[LOGTIME_STRLEN]; > =20 > logtime_fmt(timestr, sizeof(timestr), now); > - fprintf(stderr, "%s: ", timestr); > + FPRINTF(stderr, "%s: ", timestr); > } > =20 > if ((log_mask & LOG_MASK(LOG_PRI(pri))) || !log_conf_parsed) { > @@ -293,7 +293,7 @@ void vlogmsg(bool newline, bool cont, int pri, const = char *format, va_list ap) > (log_stderr && (log_mask & LOG_MASK(LOG_PRI(pri))))) { > (void)vfprintf(stderr, format, ap); > if (newline && format[strlen(format)] !=3D '\n') > - fprintf(stderr, "\n"); > + FPRINTF(stderr, "\n"); > } > } > =20 > @@ -399,7 +399,7 @@ void passt_vsyslog(bool newline, int pri, const char = *format, va_list ap) > n +=3D snprintf(buf + n, BUFSIZ - n, "\n"); > =20 > if (log_sock >=3D 0 && send(log_sock, buf, n, 0) !=3D n && log_stderr) > - fprintf(stderr, "Failed to send %i bytes to syslog\n", n); > + FPRINTF(stderr, "Failed to send %i bytes to syslog\n", n); > } > =20 > /** > diff --git a/util.h b/util.h > index 8449d00..d614094 100644 > --- a/util.h > +++ b/util.h > @@ -270,6 +270,9 @@ static inline bool mod_between(unsigned x, unsigned i= , unsigned j, unsigned m) > return mod_sub(x, i, m) < mod_sub(j, i, m); > } > =20 > +/* FPRINTF() intentionally silences cert-err33-c clang-tidy warnings */ > +#define FPRINTF(f, ...) (void)fprintf(f, __VA_ARGS__) > + > /* > * Workarounds for https://github.com/llvm/llvm-project/issues/58992 > * --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --POLUk+uiFbkuzP9W Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIyBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmca67QACgkQzQJF27ox 2Ge7aQ/4/y1g82TRL9C2VeQMKGThghb7MDt/wJ2oeqvWD8BkgX10269oe8qzpLwk 1HvSqm1q3ZO41Yf6+d/+JBOZq/3LRMHU5BKuhxbJAYOJmG+HhhDnxfJXSKr8F04z NAtlzgWeJsghZP0lmCA0xGymOZ36ZglpZoKVfeO2Y6GpiDutUqcmuMNbCc2sps2Y 2n4H/QH40/lO+xzXcuI5EDus2DxxRsPaeTfUIjRXb2oYsbzH9dMEWBqw2uOGAIRa 7TrmoUkTWWUQhh6wP+1zxh3g/Jd4Vm6Pix80dqdA7NSIaLh2+86Azwdtn6oxW8ab UiYQxJKdz1BO4GU1C0b0n1egIYQ54jH6ofJSCtIcClWH4W/7g6ISzIHl7HF6IzKv H11t11z2VRJw1ARYzs7OeizgdgesPr49PwbM0tfXWBwPXGJ3/AVPC+tnnFWCgo2j bpgLwgM0f1OR1AXrqLuXCtIruhzSL0564gM9Y2syuN6FY2p26+S4D+v/BOv1fEQM Nb1Jblhl170fRzxO7K3V441cYu15pcSzm3a0fyULQYGOQ4CqTVGvhYONSJfFWjHc LPZQRbxMXfzz7pREsIJZxmUWi+No9Woylrl1OLvGc98DUAbL8YXTkCJuyfZbpLAR Wi5D5K5hUgTBUru0LV3iw1vAMnGSBrD5E+1nxSF8WHOVMCSU4Q== =FoOz -----END PGP SIGNATURE----- --POLUk+uiFbkuzP9W--