[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/4] error: Strip trailing '\n' from error strin
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 1/4] error: Strip trailing '\n' from error string arguments (again) |
Date: |
Thu, 4 Aug 2016 14:47:37 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
On 08/03/2016 05:37 AM, Markus Armbruster wrote:
> Commit 9af9e0f, 6daf194d, be62a2eb and 312fd5f got rid of a bunch, but
> they keep coming back. checkpatch.pl tries to flag them since commit
> 5d596c2, but it's not very good at it. Offenders tracked down with
> Coccinelle script scripts/coccinelle/err-bad-newline.cocci, an updated
> version of the script from commit 312fd5f.
>
> Signed-off-by: Markus Armbruster <address@hidden>
> ---
> +++ b/scripts/coccinelle/err-bad-newline.cocci
> @@ -0,0 +1,29 @@
> +// Error messages should not contain newlines. This script finds
> +// messages that do. Fixing them is manual.
> address@hidden@
> +expression errp, eno, cls, fmt;
> +position p;
> +@@
> +(
> +error_report(fmt, ...)@p
So you use Coccinelle to find error messages...
> address@hidden:python@
> +fmt << r.fmt;
> +p << r.p;
> +@@
> +if "\\n" in str(fmt):
> + print "%s:%s:%s:%s" % (p[0].file, p[0].line, p[0].column, fmt)
...and python to then parse the format string and flag violations.
Slick. Does it still work across formats like "foo %" PRIdMAX "\n"?
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature