Message ID | 20210405155713.29754-9-julien@xen.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Use const whether we point to literal strings (take 1) | expand |
On Mon, Apr 05, 2021 at 04:57:07PM +0100, Julien Grall wrote: > From: Julien Grall <jgrall@amazon.com> > > __bug() and __assert_failed() are not meant to modify the string > parameters. So mark them as const. > > Signed-off-by: Julien Grall <jgrall@amazon.com> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com> While looking at this I think we should also make the line parameter unsigned, but again doesn't need to be part of this patch. Thanks, Roger.
Hi Roger, On 06/04/2021 08:29, Roger Pau Monné wrote: > On Mon, Apr 05, 2021 at 04:57:07PM +0100, Julien Grall wrote: >> From: Julien Grall <jgrall@amazon.com> >> >> __bug() and __assert_failed() are not meant to modify the string >> parameters. So mark them as const. >> >> Signed-off-by: Julien Grall <jgrall@amazon.com> > > Reviewed-by: Roger Pau Monné <roger.pau@citrix.com> Thanks! > > While looking at this I think we should also make the line parameter > unsigned, but again doesn't need to be part of this patch. I would prefer if this is done in a follow-up patch. Cheers,
diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c index 7da144b0bb15..581b35e5cfb5 100644 --- a/tools/firmware/hvmloader/util.c +++ b/tools/firmware/hvmloader/util.c @@ -722,14 +722,14 @@ static void __attribute__((noreturn)) crash(void) asm volatile ( "hlt" ); } -void __assert_failed(char *assertion, char *file, int line) +void __assert_failed(const char *assertion, const char *file, int line) { printf("*** HVMLoader assertion '%s' failed at %s:%d\n", assertion, file, line); crash(); } -void __bug(char *file, int line) +void __bug(const char *file, int line) { printf("*** HVMLoader bug at %s:%d\n", file, line); crash(); diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h index 4f0baade0e6c..8d95eab28a65 100644 --- a/tools/firmware/hvmloader/util.h +++ b/tools/firmware/hvmloader/util.h @@ -34,11 +34,11 @@ enum { #undef NULL #define NULL ((void*)0) -void __assert_failed(char *assertion, char *file, int line) +void __assert_failed(const char *assertion, const char *file, int line) __attribute__((noreturn)); #define ASSERT(p) \ do { if (!(p)) __assert_failed(#p, __FILE__, __LINE__); } while (0) -void __bug(char *file, int line) __attribute__((noreturn)); +void __bug(const char *file, int line) __attribute__((noreturn)); #define BUG() __bug(__FILE__, __LINE__) #define BUG_ON(p) do { if (p) BUG(); } while (0) #define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))