* [PATCH-for-5.1? v2] qapi/error: Check format string argument in error_*prepend()
@ 2020-07-23 17:12 Philippe Mathieu-Daudé
2020-07-24 8:03 ` Markus Armbruster
2020-07-24 11:44 ` Markus Armbruster
0 siblings, 2 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-23 17:12 UTC (permalink / raw)
To: qemu-devel
Cc: Stefan Weil, Philippe Mathieu-Daudé,
Michael Roth, Markus Armbruster
error_propagate_prepend() "behaves like error_prepend()", and
error_prepend() uses "formatting @fmt, ... like printf()".
error_prepend() checks its format string argument, but
error_propagate_prepend() does not. Fix by addint the format
attribute to error_propagate_prepend() and error_vprepend().
This would have caught the bug fixed in the previous commit:
CC hw/sd/milkymist-memcard.o
hw/sd/milkymist-memcard.c: In function ‘milkymist_memcard_realize’:
hw/sd/milkymist-memcard.c:284:70: error: format ‘%s’ expects a matching ‘char *’ argument [-Werror=format=]
284 | error_propagate_prepend(errp, err, "failed to init SD card: %s");
| ~^
| |
| char *
Missed in commit 4b5766488f "error: Fix use of error_prepend() with
&error_fatal, &error_abort".
Inspired-by: Stefan Weil <sw@weilnetz.de>
Suggested-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
Since v1:
- Reword (Markus)
- Add error_vprepend (Stefan)
- Use local style to add the attribute *after* the declaration,
which is invalid on definition where we get (depending on the
toolchain):
. error: attributes should be specified before the declarator in a function definition
. error: attributes are not allowed on a function-definition
Supersedes: <20200723091309.18690-1-philmd@redhat.com>
---
include/qapi/error.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/qapi/error.h b/include/qapi/error.h
index 7932594dce..eaa05c4837 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -382,13 +382,15 @@ void error_propagate(Error **dst_errp, Error *local_err);
* Please use ERRP_GUARD() and error_prepend() instead when possible.
*/
void error_propagate_prepend(Error **dst_errp, Error *local_err,
- const char *fmt, ...);
+ const char *fmt, ...)
+ GCC_FMT_ATTR(3, 4);
/*
* Prepend some text to @errp's human-readable error message.
* The text is made by formatting @fmt, @ap like vprintf().
*/
-void error_vprepend(Error *const *errp, const char *fmt, va_list ap);
+void error_vprepend(Error *const *errp, const char *fmt, va_list ap)
+ GCC_FMT_ATTR(2, 0);
/*
* Prepend some text to @errp's human-readable error message.
--
2.21.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH-for-5.1? v2] qapi/error: Check format string argument in error_*prepend()
2020-07-23 17:12 [PATCH-for-5.1? v2] qapi/error: Check format string argument in error_*prepend() Philippe Mathieu-Daudé
@ 2020-07-24 8:03 ` Markus Armbruster
2020-07-24 9:33 ` Philippe Mathieu-Daudé
2020-07-24 11:44 ` Markus Armbruster
1 sibling, 1 reply; 4+ messages in thread
From: Markus Armbruster @ 2020-07-24 8:03 UTC (permalink / raw)
To: Philippe Mathieu-Daudé; +Cc: Stefan Weil, qemu-devel, Michael Roth
Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> error_propagate_prepend() "behaves like error_prepend()", and
> error_prepend() uses "formatting @fmt, ... like printf()".
> error_prepend() checks its format string argument, but
> error_propagate_prepend() does not. Fix by addint the format
s/addint/adding/
> attribute to error_propagate_prepend() and error_vprepend().
>
> This would have caught the bug fixed in the previous commit:
>
> CC hw/sd/milkymist-memcard.o
> hw/sd/milkymist-memcard.c: In function ‘milkymist_memcard_realize’:
> hw/sd/milkymist-memcard.c:284:70: error: format ‘%s’ expects a matching ‘char *’ argument [-Werror=format=]
> 284 | error_propagate_prepend(errp, err, "failed to init SD card: %s");
> | ~^
> | |
> | char *
I see no need to repeat the details here. If you agree, I'll drop them
in my tree.
> Missed in commit 4b5766488f "error: Fix use of error_prepend() with
> &error_fatal, &error_abort".
>
> Inspired-by: Stefan Weil <sw@weilnetz.de>
> Suggested-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH-for-5.1? v2] qapi/error: Check format string argument in error_*prepend()
2020-07-24 8:03 ` Markus Armbruster
@ 2020-07-24 9:33 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-24 9:33 UTC (permalink / raw)
To: Markus Armbruster; +Cc: Stefan Weil, qemu-devel, Michael Roth
On 7/24/20 10:03 AM, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>
>> error_propagate_prepend() "behaves like error_prepend()", and
>> error_prepend() uses "formatting @fmt, ... like printf()".
>> error_prepend() checks its format string argument, but
>> error_propagate_prepend() does not. Fix by addint the format
>
> s/addint/adding/
>
>> attribute to error_propagate_prepend() and error_vprepend().
>>
>> This would have caught the bug fixed in the previous commit:
>>
>> CC hw/sd/milkymist-memcard.o
>> hw/sd/milkymist-memcard.c: In function ‘milkymist_memcard_realize’:
>> hw/sd/milkymist-memcard.c:284:70: error: format ‘%s’ expects a matching ‘char *’ argument [-Werror=format=]
>> 284 | error_propagate_prepend(errp, err, "failed to init SD card: %s");
>> | ~^
>> | |
>> | char *
>
> I see no need to repeat the details here. If you agree, I'll drop them
> in my tree.
OK, thanks.
>
>> Missed in commit 4b5766488f "error: Fix use of error_prepend() with
>> &error_fatal, &error_abort".
>>
>> Inspired-by: Stefan Weil <sw@weilnetz.de>
>> Suggested-by: Eric Blake <eblake@redhat.com>
>> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH-for-5.1? v2] qapi/error: Check format string argument in error_*prepend()
2020-07-23 17:12 [PATCH-for-5.1? v2] qapi/error: Check format string argument in error_*prepend() Philippe Mathieu-Daudé
2020-07-24 8:03 ` Markus Armbruster
@ 2020-07-24 11:44 ` Markus Armbruster
1 sibling, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2020-07-24 11:44 UTC (permalink / raw)
To: Philippe Mathieu-Daudé; +Cc: Stefan Weil, qemu-devel, Michael Roth
Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> error_propagate_prepend() "behaves like error_prepend()", and
> error_prepend() uses "formatting @fmt, ... like printf()".
> error_prepend() checks its format string argument, but
> error_propagate_prepend() does not. Fix by addint the format
> attribute to error_propagate_prepend() and error_vprepend().
>
> This would have caught the bug fixed in the previous commit:
>
> CC hw/sd/milkymist-memcard.o
> hw/sd/milkymist-memcard.c: In function ‘milkymist_memcard_realize’:
> hw/sd/milkymist-memcard.c:284:70: error: format ‘%s’ expects a matching ‘char *’ argument [-Werror=format=]
> 284 | error_propagate_prepend(errp, err, "failed to init SD card: %s");
> | ~^
> | |
> | char *
>
> Missed in commit 4b5766488f "error: Fix use of error_prepend() with
> &error_fatal, &error_abort".
>
> Inspired-by: Stefan Weil <sw@weilnetz.de>
> Suggested-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> Since v1:
> - Reword (Markus)
> - Add error_vprepend (Stefan)
> - Use local style to add the attribute *after* the declaration,
> which is invalid on definition where we get (depending on the
> toolchain):
>
> . error: attributes should be specified before the declarator in a function definition
>
> . error: attributes are not allowed on a function-definition
>
> Supersedes: <20200723091309.18690-1-philmd@redhat.com>
Queued with Stefan's R-by from v1. Hope what's okay. Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-24 11:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 17:12 [PATCH-for-5.1? v2] qapi/error: Check format string argument in error_*prepend() Philippe Mathieu-Daudé
2020-07-24 8:03 ` Markus Armbruster
2020-07-24 9:33 ` Philippe Mathieu-Daudé
2020-07-24 11:44 ` Markus Armbruster
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.