Skip to content

Commit b886690

Browse files
andy-shevsergey-senozhatsky
authored andcommitted
lib/vsprintf: Replace hidden BUILD_BUG_ON() with static_assert()
First of all, there is no compile time check for the SMALL to be ' ' (0x20, i.e. space). Second, for ZEROPAD the check is hidden in the code. For better maintenance replace BUILD_BUG_ON() with static_assert() for ZEROPAD and move it closer to the definition. While at it, introduce check for SMALL. Signed-off-by: Andy Shevchenko <[email protected]> Reviewed-by: Steven Rostedt (VMware) <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sergey Senozhatsky <[email protected]>
1 parent b4a461e commit b886690

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/vsprintf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ int num_to_str(char *buf, int size, unsigned long long num, unsigned int width)
381381
#define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */
382382
#define SPECIAL 64 /* prefix hex with "0x", octal with "0" */
383383

384+
static_assert(ZEROPAD == ('0' - ' '));
385+
static_assert(SMALL == ' ');
386+
384387
enum format_type {
385388
FORMAT_TYPE_NONE, /* Just a string part */
386389
FORMAT_TYPE_WIDTH,
@@ -507,7 +510,7 @@ char *number(char *buf, char *end, unsigned long long num,
507510
/* zero or space padding */
508511
if (!(spec.flags & LEFT)) {
509512
char c = ' ' + (spec.flags & ZEROPAD);
510-
BUILD_BUG_ON(' ' + ZEROPAD != '0');
513+
511514
while (--field_width >= 0) {
512515
if (buf < end)
513516
*buf = c;

0 commit comments

Comments
 (0)