Skip to contentSkip to conversation

Add %X option to printf functions.

PATCH In review Javier Martinez Canillas 2 participants 5 messages Sep 17, 2019 – Sep 20, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add %X option to printf functions.

From: Paulo Flabiano Smorigo <[email protected]>

---

 grub-core/kern/misc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
grub-core/kern/misc.c +5 -2
index 3b633d51f4c..76e7fb22872 100644
@@ -588,7 +588,7 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r)
 static inline char *
 grub_lltoa (char *str, int c, unsigned long long n)
 {
-  unsigned base = (c == 'x') ? 16 : 10;
+  unsigned base = ((c == 'x') || (c == 'X')) ? 16 : 10;
   char *p;
 
   if ((long long) n < 0 && c == 'd')
@@ -603,7 +603,7 @@ grub_lltoa (char *str, int c, unsigned long long n)
     do
       {
 	unsigned d = (unsigned) (n & 0xf);
-	*p++ = (d > 9) ? d + 'a' - 10 : d + '0';
+	*p++ = (d > 9) ? d + ((c == 'x') ? 'a' : 'A') - 10 : d + '0';
       }
     while (n >>= 4);
   else
@@ -676,6 +676,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args,
 	{
 	case 'p':
 	case 'x':
+	case 'X':
 	case 'u':
 	case 'd':
 	case 'c':
@@ -762,6 +763,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args,
       switch (c)
 	{
 	case 'x':
+	case 'X':
 	case 'u':
 	  args->ptr[curn].type = UNSIGNED_INT + longfmt;
 	  break;
@@ -900,6 +902,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
 	  c = 'x';
 	  /* Fall through. */
 	case 'x':
+	case 'X':
 	case 'u':
 	case 'd':
 	  {
Signature · 1 line
2.21.0
#2 lore raw

Hello Daniel,

Thanks for the quick feedback.

Quoted 9 lines · Daniel Kiper
Quoted 4 lines · Javier Martinez Canillas

From: Paulo Flabiano Smorigo <[email protected]>

May I ask you to add an explanation to the commit message why?
If you do that you can add "Reviewed-by: Daniel Kiper <[email protected]>".

The reason why we had this patch is that a following patch was using this %X format specifier to print IP addresses as uppercase hexadecimal.

But as Vladimir suggested, we could just use %x and grub_toupper(). So If adding an %X format specifier seems unnecessary and would only make grub core bigger, then I'll just change the other patch and drop this one.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat
#3 lore raw
Quoted 11 lines · Javier Martinez Canillas

Hello Daniel,

Thanks for the quick feedback.

Quoted 6 lines · Daniel Kiper
Quoted 4 lines · Javier Martinez Canillas

From: Paulo Flabiano Smorigo <[email protected]>

Quoted 6 lines
Quoted 3 lines

May I ask you to add an explanation to the commit message why?
If you do that you can add "Reviewed-by: Daniel Kiper <[email protected]>".

The reason why we had this patch is that a following patch was using this %X format specifier to print IP addresses as uppercase hexadecimal.

OK but then I would like to see patch using "%X" immediately following this one. So, both have to be posted together.

And please add similar explanation as you did above to the commit message.

Quoted 3 lines

But as Vladimir suggested, we could just use %x and grub_toupper(). So If adding an %X format specifier seems unnecessary and would only make grub core bigger, then I'll just change the other patch and drop this one.

TBH I prefer to have grub_printf() behavior similar to regular printf(). And I do not think that this change will increase core image size much.

Daniel

#4 lore raw
Quoted 16 lines · Daniel Kiper
Quoted 15 lines · Javier Martinez Canillas

Hello Daniel,

Thanks for the quick feedback.

Quoted 9 lines · Daniel Kiper
Quoted 4 lines · Javier Martinez Canillas

From: Paulo Flabiano Smorigo <[email protected]>

May I ask you to add an explanation to the commit message why?
If you do that you can add "Reviewed-by: Daniel Kiper <[email protected]>".

Quoted 7 lines
Quoted 2 lines

The reason why we had this patch is that a following patch was using this %X format specifier to print IP addresses as uppercase hexadecimal.

OK but then I would like to see patch using "%X" immediately following this one. So, both have to be posted together.

And please add similar explanation as you did above to the commit message.

Ok, I'll re-post with a better commit message as a series when posting the other patch that's using the %X specifier then.

Quoted 8 lines
Quoted 4 lines

But as Vladimir suggested, we could just use %x and grub_toupper(). So If adding an %X format specifier seems unnecessary and would only make grub core bigger, then I'll just change the other patch and drop this one.

TBH I prefer to have grub_printf() behavior similar to regular printf(). And I do not think that this change will increase core image size much.

Yes, agreed.

Quoted 2 lines

Daniel

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat