Skip to contentSkip to conversation

lib/vsprintf.c: Amend static asserts for format specifier flags

PATCH In review Andy Shevchenko 2 participants 2 messages Oct 26, 2021 – Oct 27, 2021

Subsystems (2)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/1 lib/vsprintf.c: Amend static asserts for format specifier flags

There are couple of improvements to static asserts against the format specifier flags:

- new static assert for SIGN
- fix static assert for SMALL

SMALL is not equal to ASCII code of white space, it equals to the bit difference between capital and small letters (however the value is the same, semantically expression means different things).

---
 lib/vsprintf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/vsprintf.c +2 -1
index f15a49ff6fab..ddfb3d836f38 100644
@@ -407,8 +407,9 @@ int num_to_str(char *buf, int size, unsigned long long num, unsigned int width)
 #define SMALL	32		/* use lowercase in hex (must be 32 == 0x20) */
 #define SPECIAL	64		/* prefix hex with "0x", octal with "0" */
 
+static_assert(SIGN == 1);
 static_assert(ZEROPAD == ('0' - ' '));
-static_assert(SMALL == ' ');
+static_assert(SMALL == ('a' ^ 'A'));
 
 enum format_type {
 	FORMAT_TYPE_NONE, /* Just a string part */
Signature · 1 line
2.33.0
maintainer
#1 lore raw
Quoted 6 lines · Andy Shevchenko

There are couple of improvements to static asserts against the format specifier flags:

- new static assert for SIGN
- fix static assert for SMALL

Quoted 6 lines

SMALL is not equal to ASCII code of white space, it equals to the bit difference between capital and small letters (however the value is the same, semantically expression means different things).

The patch has been committed into printk/linux.git, branch for-5.16.

Best Regards,
Petr