qapi/error: Check format string argument in error_*prepend()
PATCH v2 1/1 qapi/error: Check format string argument in error_*prepend()
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".
---
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: <[email protected]>
--- include/qapi/error.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
include/qapi/error.h +4 -2
@@ -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.
Signature · 1 line
2.21.3
Quoted 4 lines · Philippe Mathieu-Daudé
error_propagate_prepend()"behaves likeerror_prepend()", anderror_prepend()uses "formatting @fmt, ... likeprintf()".error_prepend()checks its format string argument, buterror_propagate_prepend()does not. Fix by addint the format
s/addint/adding/
Quoted 11 lines
attribute to
error_propagate_prepend()anderror_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.
Quoted 7 lines
Missed in commit
4b5766488f"error: Fix use oferror_prepend()with&error_fatal,&error_abort".Inspired-by Stefan Weil <[email protected]>Suggested-by Eric Blake <[email protected]>Reviewed-by Markus Armbruster <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 21 lines · Markus Armbruster
Quoted 4 lines · Philippe Mathieu-Daudé
error_propagate_prepend()"behaves likeerror_prepend()", anderror_prepend()uses "formatting @fmt, ... likeprintf()".error_prepend()checks its format string argument, buterror_propagate_prepend()does not. Fix by addint the formats/addint/adding/
Quoted 11 lines
attribute to
error_propagate_prepend()anderror_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 *
Quoted 2 lines
I see no need to repeat the details here. If you agree, I'll drop them in my tree.
OK, thanks.
Quoted 11 lines
Quoted 8 lines
Missed in commit
4b5766488f"error: Fix use oferror_prepend()with&error_fatal,&error_abort".Inspired-by Stefan Weil <[email protected]>Suggested-by Eric Blake <[email protected]>Reviewed-by Markus Armbruster <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Markus Armbruster <[email protected]>
Markus Armbruster
AppliedQuoted 31 lines · Philippe Mathieu-Daudé
error_propagate_prepend()"behaves likeerror_prepend()", anderror_prepend()uses "formatting @fmt, ... likeprintf()".error_prepend()checks its format string argument, buterror_propagate_prepend()does not. Fix by addint the format attribute toerror_propagate_prepend()anderror_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 oferror_prepend()with&error_fatal,&error_abort".Inspired-by Stefan Weil <[email protected]>Suggested-by Eric Blake <[email protected]>Reviewed-by Markus Armbruster <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Since v1:
- Reword (Markus)
- Adderror_vprepend(Stefan)
- Use local style to add the attribute *after* the declaration, which is invalid on definition where we get (depending on the toolchain):
Quoted 5 lines
. error: attributes should be specified before the declarator in a function definition
. error: attributes are not allowed on a function-definition
Supersedes: <[email protected]>
Queued with Stefan's R-by from v1. Hope what's okay. Thanks!