]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
super-intel.c: fix format overflow error
authorMartin Wilck <mwilck@suse.com>
Tue, 20 Jan 2026 17:00:11 +0000 (18:00 +0100)
committerXiaoNi87 <xni@redhat.com>
Tue, 27 Jan 2026 10:41:08 +0000 (18:41 +0800)
The following compile error has been observed with gcc 16:

super-intel.c: In function 'imsm_process_update':
super-intel.c:10069:43: error: '%d' directive writing between 1 and 11 bytes into a region of size 7 [-Werror=format-overflow=]
10069 |                                 " MISSING_%d", du->index);
      |                                           ^~
In function 'apply_takeover_update',
    inlined from 'imsm_process_update' at super-intel.c:10168:7:
super-intel.c:10069:33: note: directive argument in the range [-21474836472147483647]
10069 |                                 " MISSING_%d", du->index);
      |                                 ^~~~~~~~~~~~~
In file included from /usr/include/stdio.h:970,
                 from mdadm.h:42,
                 from super-intel.c:21:
In function 'sprintf',
    inlined from 'apply_takeover_update' at super-intel.c:10068:4,
    inlined from 'imsm_process_update' at super-intel.c:10168:7:
/usr/include/bits/stdio2.h:30:10: note: '__builtin_sprintf' output between 11 and 21 bytes into a destination of size 16
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~

Fix it by using an unsigned type for the index variable. This works
because map->num_members is an unsigned short.

Suggested-by: Mariusz Tkaczyk <mtkaczyk@kernel.org>
Signed-off-by: Martin Wilck <mwilck@suse.com>
super-intel.c

index 835ca6fb9db03f0ace274be79941db299a0be68e..e9fce12c35c7c22fa20388d19b19e44ae3e9b4f3 100644 (file)
@@ -10003,7 +10003,7 @@ static int apply_takeover_update(struct imsm_update_takeover *u,
        struct imsm_dev *dev_new;
        struct imsm_map *map;
        struct dl *dm, *du;
-       int i;
+       unsigned int i;
 
        for (dv = super->devlist; dv; dv = dv->next)
                if (dv->index == (unsigned int)u->subarray) {