[U-Boot] [BUG] build warnings for tools/mtk_image.c

Heinrich Schuchardt xypron.glpk at gmx.de
Tue Dec 11 19:33:54 UTC 2018


Hello Ryder,

commit 3b975a147c3c ("tools: MediaTek: add MTK boot header generation to
mkimage") leads to build warnings:

In function ‘mtk_image_set_gen_header’,
    inlined from ‘mtk_image_set_header’ at tools/mtk_image.c:733:3:
tools/mtk_image.c:659:2: warning: ‘strncpy’ specified bound 12 equals
destination size [-Wstringop-truncation]
  strncpy(hdr->boot.name, bootname, sizeof(hdr->boot.name));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘mtk_brom_parse_imagename’,
    inlined from ‘mtk_image_check_params’ at tools/mtk_image.c:388:9:
tools/mtk_image.c:325:5: warning: ‘strncpy’ specified bound 32 equals
destination size [-Wstringop-truncation]
     strncpy(lk_name, val, sizeof(lk_name));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

with gcc 8.2.0.

Please, provide a fix that avoids build warnings as these will be
regarded as errors on Travis.

If lg_name and htr->boot shall be \0 terminated you could make a change
like:


-                           strncpy(lk_name, val, sizeof(lk_name));
+                           strncpy(lk_name, val, sizeof(lk_name) - 1);

-       strncpy(hdr->boot.name, bootname, sizeof(hdr->boot.name));
+       strncpy(hdr->boot.name, bootname, sizeof(hdr->boot.name) - 1);

Best regards

Heinrich


More information about the U-Boot mailing list