• Brahmajit Das's avatar
    fs/proc: fix build with GCC 15 due to -Werror=unterminated-string-initialization · 5778ace0
    Brahmajit Das authored
    show show_smap_vma_flags() has been a using misspelled initializer in
    mnemonics[] - it needed to initialize 2 element array of char and it used
    NUL-padded 2 character string literals (i.e.  3-element initializer).
    
    This has been spotted by gcc-15[*]; prior to that gcc quietly dropped the
    3rd eleemnt of initializers.  To fix this we are increasing the size of
    mnemonics[] (from mnemonics[BITS_PER_LONG][2] to
    mnemonics[BITS_PER_LONG][3]) to accomodate the NUL-padded string literals.
    
    This also helps us in simplyfying the logic for printing of the flags as
    instead of printing each character from the mnemonics[], we can just print
    the mnemonics[] using seq_printf.
    
    [*]: fs/proc/task_mmu.c:917:49: error: initializer-string for array of `char' is too long [-Werror=unterminate d-string-initialization]
      917 |                 [0 ... (BITS_PER_LONG-1)] = "??",
          |                                                 ^~~~
    fs/proc/task_mmu.c:917:49: error: initializer-string for array of `char' is too long [-Werror=unterminate d-string-initialization]
    fs/proc/task_mmu.c:917:49: error: initializer-string for array of `char' is too long [-Werror=unterminate d-string-initialization]
    fs/proc/task_mmu.c:917:49: error: initializer-string for array of `char' is too long [-Werror=unterminate d-string-initialization]
    fs/proc/task_mmu.c:917:49: error: initializer-string for array of `char' is too long [-Werror=unterminate d-string-initialization]
    fs/proc/task_mmu.c:917:49: error: initializer-string for array of `char' is too long [-Werror=unterminate d-string-initialization]
    ...
    
    
    Stephen pointed out:
    
    : The C standard explicitly allows for a string initializer to be too long
    : due to the NUL byte at the end ...  so this warning may be overzealous.
    
    but let's make the warning go away anwyay.
    
    Link: https://lkml.kernel.org/r/20241005063700.2241027-1-brahmajit.xyz@gmail.com
    Link: https://lkml.kernel.org/r/20241003093040.47c08382@canb.auug.org.auSigned-off-by: default avatarBrahmajit Das <brahmajit.xyz@gmail.com>
    Cc: Cyrill Gorcunov <gorcunov@openvz.org>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Stephen Rothwell <sfr@canb.auug.org.au>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    5778ace0
task_mmu.c 75.2 KB