BobBuildTool/bob

Reproduction for sandbox-example

sirtapps opened this issue · 1 comments

I try to reproduce the demo project (sandbox) and get the following warnings - may it depends on my build environment (VM Debian bullseye).

$ bob ls -r
/
└── vexpress
    ├── initramfs
    │   ├── busybox
    │   └── toolchain::arm-linux-gnueabihf-rootfs
    ├── linux-image
    ├── sandbox::debian-x86_64
    └── toolchain::arm-linux-gnueabihf-toolchain
	
$ bob build vexpress
>> vexpress/sandbox::debian-x86_64
   CHECKOUT  work/sandbox/debian-x86_64/src/1/workspace 
   BUILD     work/sandbox/debian-x86_64/build/1/workspace
   PACKAGE   work/sandbox/debian-x86_64/dist/1/workspace
>> vexpress/toolchain::arm-linux-gnueabihf-toolchain
   CHECKOUT  work/toolchain/arm-linux-gnueabihf/src/1/workspace 
>> vexpress/initramfs/busybox
   CHECKOUT  work/busybox/src/1/workspace 
>> vexpress/linux-image
   CHECKOUT  work/linux/src/1/workspace 
>> vexpress/initramfs/toolchain::arm-linux-gnueabihf-rootfs
   BUILD     work/toolchain/arm-linux-gnueabihf-toolchain/build/1/workspace
>> vexpress/toolchain::arm-linux-gnueabihf-toolchain
   PACKAGE   work/toolchain/arm-linux-gnueabihf-toolchain/dist/1/workspace
>> vexpress/initramfs/toolchain::arm-linux-gnueabihf-rootfs
   PACKAGE   work/toolchain/arm-linux-gnueabihf-rootfs/dist/1/workspace
>> vexpress/initramfs/busybox
   BUILD     work/busybox/build/1/workspace
 /bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/miscutils/i2c_tools.c: In function 'list_i2c_busses_and_exit':
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/miscutils/i2c_tools.c:1150:32: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 236 [-Wformat-truncation=]
 1150 |   snprintf(path, NAME_MAX, "%s/%s/name",
      |                                ^~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/miscutils/i2c_tools.c:1150:3: note: 'snprintf' output between 25 and 280 bytes into a destination of size 255
 1150 |   snprintf(path, NAME_MAX, "%s/%s/name",
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1151 |     i2cdev_path, de->d_name);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/miscutils/i2c_tools.c:1155:10: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 236 [-Wformat-truncation=]
 1155 |      "%s/%s/device/name",
      |          ^~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/miscutils/i2c_tools.c:1154:4: note: 'snprintf' output between 32 and 287 bytes into a destination of size 255
 1154 |    snprintf(path, NAME_MAX,
      |    ^~~~~~~~~~~~~~~~~~~~~~~~
 1155 |      "%s/%s/device/name",
      |      ~~~~~~~~~~~~~~~~~~~~
 1156 |      i2cdev_path, de->d_name);
      |      ~~~~~~~~~~~~~~~~~~~~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/miscutils/i2c_tools.c:1163:10: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 236 [-Wformat-truncation=]
 1163 |      "%s/%s/device/name",
      |          ^~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/miscutils/i2c_tools.c:1162:4: note: 'snprintf' output between 32 and 287 bytes into a destination of size 255
 1162 |    snprintf(path, NAME_MAX,
      |    ^~~~~~~~~~~~~~~~~~~~~~~~
 1163 |      "%s/%s/device/name",
      |      ~~~~~~~~~~~~~~~~~~~~
 1164 |      i2cdev_path, de->d_name);
      |      ~~~~~~~~~~~~~~~~~~~~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/miscutils/i2c_tools.c:1175:12: warning: '%s' directive output may be truncated writing up to 255 bytes into a region of size 236 [-Wformat-truncation=]
 1175 |        "%s/%s/device/%s/name",
      |            ^~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/miscutils/i2c_tools.c:1174:6: note: 'snprintf' output between 33 and 543 bytes into a destination of size 255
 1174 |      snprintf(path, NAME_MAX,
      |      ^~~~~~~~~~~~~~~~~~~~~~~~
 1175 |        "%s/%s/device/%s/name",
      |        ~~~~~~~~~~~~~~~~~~~~~~~
 1176 |        i2cdev_path, de->d_name,
      |        ~~~~~~~~~~~~~~~~~~~~~~~~
 1177 |        subde->d_name);
      |        ~~~~~~~~~~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/modutils/modutils.c: In function 'filename2modname':
cc1: warning: function may return address of local variable [-Wreturn-local-addr]
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/modutils/modutils.c:94:7: note: declared here
   94 |  char local_modname[MODULE_NAME_LEN];
      |       ^~~~~~~~~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c: In function 'show_bridge':
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c:163:5: warning: array subscript -4 is outside array bounds of 'char[42]' [-Warray-bounds]
  163 |  sfx[-4] = 'f'; sfx[-3] = '\0';
      |  ~~~^~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c:134:7: note: while referencing 'pathbuf'
  134 |  char pathbuf[IFNAMSIZ + sizeof("/bridge/bridge_id") + 8];
      |       ^~~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c:163:20: warning: array subscript -3 is outside array bounds of 'char[42]' [-Warray-bounds]
  163 |  sfx[-4] = 'f'; sfx[-3] = '\0';
      |                 ~~~^~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c:134:7: note: while referencing 'pathbuf'
  134 |  char pathbuf[IFNAMSIZ + sizeof("/bridge/bridge_id") + 8];
      |       ^~~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c: In function 'brctl_main':
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c:479:11: warning: array subscript -4 is outside array bounds of 'char[54]' [-Warray-bounds]
  479 |   sfx[-4] = 'f'; sfx[-3] = '\0';
      |   ~~~~~~~~^~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c:398:7: note: while referencing 'pathbuf'
  398 |  char pathbuf[IFNAMSIZ + sizeof("/bridge/topology_change_timer") + 8];
      |       ^~~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c:479:26: warning: array subscript -3 is outside array bounds of 'char[54]' [-Warray-bounds]
  479 |   sfx[-4] = 'f'; sfx[-3] = '\0';
      |                  ~~~~~~~~^~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/networking/brctl.c:398:7: note: while referencing 'pathbuf'
  398 |  char pathbuf[IFNAMSIZ + sizeof("/bridge/topology_change_timer") + 8];
      |       ^~~~~~~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/procps/powertop.c: In function 'read_cstate_counts':
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/procps/powertop.c:181:20: warning: '%s' directive writing up to 255 bytes into a region of size 171 [-Wformat-overflow=]
  181 |   sprintf(buf, "%s/%s/power", "/proc/acpi/processor", d->d_name);
      |                    ^~
/bob/d1184c1ece9e4494043ef6e92c981e650499699b/workspace/procps/powertop.c:181:3: note: 'sprintf' output between 28 and 283 bytes into a destination of size 192
  181 |   sprintf(buf, "%s/%s/power", "/proc/acpi/processor", d->d_name);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   PACKAGE   work/busybox/dist/1/workspace
>> vexpress/initramfs
   BUILD     work/initramfs/build/1/workspace
   PACKAGE   work/initramfs/dist/1/workspace
5285 blocks
>> vexpress/linux-image
   BUILD     work/linux-image/build/1/workspace
....

After searching for an answer I found the reason for this warning: snprintf may trunc data and this will not checked by programm. There are 2 common ways to resolve this issue:

  1. use compiler flag "-Wno-format-overflow" (may not found other, important issues)
  2. evaluate the result of snprintf (mess up the code)