• Dominique Martinet's avatar
    9p/net: xen: fix false positive printf format overflow warning · 39763480
    Dominique Martinet authored
    Use the constant to make the compiler happy about this warning:
    net/9p/trans_xen.c: In function ‘xen_9pfs_front_changed’:
    net/9p/trans_xen.c:444:39: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 8 [-Wformat-overflow=]
      444 |                 sprintf(str, "ring-ref%d", i);
          |                                       ^~
    In function ‘xen_9pfs_front_init’,
        inlined from ‘xen_9pfs_front_changed’ at net/9p/trans_xen.c:516:8,
        inlined from ‘xen_9pfs_front_changed’ at net/9p/trans_xen.c:504:13:
    net/9p/trans_xen.c:444:30: note: directive argument in the range [-2147483644, 2147483646]
      444 |                 sprintf(str, "ring-ref%d", i);
          |                              ^~~~~~~~~~~~
    net/9p/trans_xen.c:444:17: note: ‘sprintf’ output between 10 and 20 bytes into a destination of size 16
      444 |                 sprintf(str, "ring-ref%d", i);
          |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    net/9p/trans_xen.c: In function ‘xen_9pfs_front_changed’:
    net/9p/trans_xen.c:450:45: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 2 [-Wformat-overflow=]
      450 |                 sprintf(str, "event-channel-%d", i);
          |                                             ^~
    In function ‘xen_9pfs_front_init’,
        inlined from ‘xen_9pfs_front_changed’ at net/9p/trans_xen.c:516:8,
        inlined from ‘xen_9pfs_front_changed’ at net/9p/trans_xen.c:504:13:
    net/9p/trans_xen.c:450:30: note: directive argument in the range [-2147483644, 2147483646]
      450 |                 sprintf(str, "event-channel-%d", i);
          |                              ^~~~~~~~~~~~~~~~~~
    net/9p/trans_xen.c:450:17: note: ‘sprintf’ output between 16 and 26 bytes into a destination of size 16
      450 |                 sprintf(str, "event-channel-%d", i);
          |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    There is no change in logic: there only are a constant number of rings,
    and there also already is a BUILD_BUG_ON that checks if that constant
    goes over 9 as anything bigger would no longer fit the event-channel-%d
    destination size.
    
    In theory having that size as part of the struct means it could be
    modified by another thread and makes the compiler lose track of possible
    values for 'i' here, using the constant directly here makes it work.
    Signed-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
    Message-ID: <20231025103445.1248103-3-asmadeus@codewreck.org>
    Reviewed-by: default avatarChristian Schoenebeck <linux_oss@crudebyte.com>
    39763480
trans_xen.c 13.4 KB