[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v5 3/8] kern/misc: Add a format specifier GUIDs.
From: |
Daniel Kiper |
Subject: |
Re: [PATCH v5 3/8] kern/misc: Add a format specifier GUIDs. |
Date: |
Wed, 5 Apr 2023 17:23:53 +0200 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Thu, Mar 30, 2023 at 01:18:08PM +0200, Oliver Steffen wrote:
> Extend the printf format specifier for pointers (%p) to accept a suffix
> specifier G to print GUIDs: %pG can be used to print grub_guid structs.
> This does not interfere with the -Wformat checking of gcc. Note that
> the data type is not checked though (%p accepts void*).
>
> Signed-off-by: Oliver Steffen <osteffen@redhat.com>
> ---
> grub-core/kern/misc.c | 86 ++++++++++++++++++++++++++++++++-----------
> 1 file changed, 65 insertions(+), 21 deletions(-)
>
> diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
> index dfae4f9d7..1a8aff543 100644
> --- a/grub-core/kern/misc.c
> +++ b/grub-core/kern/misc.c
> @@ -24,6 +24,7 @@
> #include <grub/term.h>
> #include <grub/env.h>
> #include <grub/i18n.h>
> +#include <grub/types.h>
>
> union printf_arg
> {
> @@ -34,7 +35,8 @@ union printf_arg
> {
> INT, LONG, LONGLONG,
> UNSIGNED_INT = 3, UNSIGNED_LONG, UNSIGNED_LONGLONG,
> - STRING
> + STRING,
> + GUID
> } type;
> long long ll;
> };
> @@ -772,6 +774,9 @@ parse_printf_arg_fmt (const char *fmt0, struct
> printf_args *args,
> switch (c)
> {
> case 'p':
> + if (*(fmt) == 'G')
> + ++fmt;
> + /* Fall through. */
> case 'x':
> case 'X':
> case 'u':
> @@ -885,6 +890,10 @@ parse_printf_arg_fmt (const char *fmt0, struct
> printf_args *args,
> args->ptr[curn].type = UNSIGNED_LONGLONG;
> else
> args->ptr[curn].type = UNSIGNED_INT;
> + if (*(fmt) == 'G') {
> + args->ptr[curn].type = GUID;
> + ++fmt;
> + }
> break;
> case 's':
> args->ptr[curn].type = STRING;
> @@ -931,6 +940,12 @@ parse_printf_args (const char *fmt0, struct printf_args
> *args, va_list args_in)
> else
> args->ptr[n].ll = va_arg (args_in, unsigned int);
> break;
> + case GUID:
> + if (sizeof (void *) == sizeof (long long))
> + args->ptr[n].ll = va_arg (args_in, long long);
> + else
> + args->ptr[n].ll = va_arg (args_in, unsigned int);
> + break;
You duplicate code for the STRING. Why not
case STRING:
case GUID: ?
Daniel
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [PATCH v5 3/8] kern/misc: Add a format specifier GUIDs.,
Daniel Kiper <=