• Arvind Sankar's avatar
    efi/printf: Refactor code to consolidate padding and output · 6c4bcd8a
    Arvind Sankar authored
    Consolidate the actual output of the formatted text into one place.
    
    Fix a couple of edge cases:
    1. If 0 is printed with a precision of 0, the printf specification says
       that nothing should be output, with one exception (2b).
    2. The specification for octal alternate format (%#o) adds the leading
       zero not as a prefix as the 0x for hexadecimal is, but by increasing
       the precision if necessary to add the zero. This means that
       a. %#.2o turns 8 into "010", but 1 into "01" rather than "001".
       b. %#.o prints 0 as "0" rather than "", unlike the situation for
          decimal, hexadecimal and regular octal format, which all output an
          empty string.
    
    Reduce the space allocated for printing a number to the maximum actually
    required (22 bytes for a 64-bit number in octal), instead of the 66
    bytes previously allocated.
    Signed-off-by: default avatarArvind Sankar <nivedita@alum.mit.edu>
    Link: https://lore.kernel.org/r/20200518190716.751506-15-nivedita@alum.mit.eduSigned-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
    6c4bcd8a
vsprintf.c 9.41 KB