Error on winc.c module when compiling sources

Hi,
I own an OpenMV Cam H7 Plus and I’m trying to compile the firmware (make TARGET=OPENMV4) but I get the following error when the winc.c module is reached:

CC src/winc.c
src/winc.c: In function 'wifi_callback_sta':
src/winc.c:392:13: error: 'strncpy' output may be truncated copying 32 bytes from a string of length 32 [-Werror=stringop-truncation]
  392 |             strncpy((char*) wscan_result.ssid, (const char *) scan_result->au8SSID, WINC_MAX_SSID_LEN-1);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/winc.c:356:13: error: 'strncpy' output may be truncated copying 32 bytes from a string of length 32 [-Werror=stringop-truncation]
  356 |             strncpy(netinfo->ssid, con_info->acSSID, WINC_MAX_SSID_LEN-1);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:20: /home/lb/repositories/openmv/src/build/winc1500/src/winc.o] Error 1
make: *** [Makefile:605: FIRMWARE_OBJS] Error 2

I have an Ubuntu 20.04 LTS running on VM-ware player 15.
I’ve followed the procedure described on the Firmware Guide section without any major problems, except that the installation of gcc-arm-embedded is no longer supported through PPA, thus I had to install it “manually” as described here: apt - How to install arm-none-eabi-gdb on Ubuntu 20.04 LTS (Focal Fossa) - Ask Ubuntu
No issue when compiling the mpy-cross.

Have you got any suggestion on how to solve this?

Thanks in advance,
Luca

Yes… this is an error that our older version of GCC copies without issues. Fix the string length argument by removing the -1.

Thanks for the prompt answer.
Removing the “-1” worked fine.
Now I have a new one though…Any suggesiton here?

main.c: In function '__fatal_error':
main.c:208:9: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  208 |     if (f_open(&vfs_fat->fatfs, &fp, "ERROR.LOG",
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209 |                FA_WRITE|FA_CREATE_ALWAYS) == FR_OK) {
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c: In function 'f_touch':
main.c:245:9: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  245 |     if (f_stat(&vfs_fat->fatfs, path, NULL) != FR_OK) {
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c:246:9: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  246 |         f_open(&vfs_fat->fatfs, &fp, path, FA_WRITE | FA_CREATE_ALWAYS);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c: In function 'make_flash_fs':
main.c:259:9: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  259 |     if (f_mkfs(&vfs_fat->fatfs, FM_FAT, 0, working_buf, sizeof(working_buf)) != FR_OK) {
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c:267:5: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  267 |     f_open(&vfs_fat->fatfs, &fp, "/main.py", FA_WRITE | FA_CREATE_ALWAYS);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c:272:5: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  272 |     f_open(&vfs_fat->fatfs, &fp, "/README.txt", FA_WRITE | FA_CREATE_ALWAYS);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c:278:5: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  278 |     f_open(&vfs_fat->fatfs, &fp, "/selftest.py", FA_WRITE | FA_CREATE_ALWAYS);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c: In function 'exec_boot_script':
main.c:353:21: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  353 |     FRESULT f_res = f_stat(&vfs_fat->fatfs, path, NULL);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c:393:9: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  393 |         f_unlink(&vfs_fat->fatfs, path);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c: In function 'main':
main.c:525:23: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  525 |         FRESULT res = f_mount(&vfs_fat->fatfs);
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c:546:23: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  546 |         FRESULT res = f_mount(&vfs_fat->fatfs);
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
main.c:584:5: error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]
  584 |     ini_parse(&vfs_fat->fatfs, "/openmv.config", ini_handler_callback, &openmv_config);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:80:13: note: while referencing '_vfs_buf'
   80 | extern char _vfs_buf;
      |             ^~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:123: /home/lb/repositories/openmv/src/build/omv/main.o] Error 1
make: *** [Makefile:606: FIRMWARE_OBJS] Error 2

Yeah, you’re version of GCC is weird…

error: array subscript 0 is outside array bounds of 'char[1]' [-Werror=array-bounds]

Doesn’t make a lot of sense since that array is a size of 1… and zero indexes that.

I’ve modified the make file CFLAGS as follow:

CFLAGS += -std=gnu99 -Wall -Werror  -Wno-error=array-bounds -mthumb -nostartfiles -fdata-sections -ffunction-sections

and the compile process completes, BUT I get more of the “array-bounds” issues, which seems to make sense in this case.
What do you think?

lepton.c: In function 'HAL_SPI_RxCpltCallback':
lepton.c:39:55: warning: array subscript 1 is outside array bounds of 'uint8_t[1]' {aka 'unsigned char[1]'} [-Warray-bounds]
   39 | #define VOSPI_HEADER_PID(buf)   (((buf[0] << 8) | (buf[1] << 0)) & 0x0FFF)
      |                                                       ^
lepton.c:433:24: note: in expansion of macro 'VOSPI_HEADER_PID'
  433 |         uint32_t pid = VOSPI_HEADER_PID(vospi_packet);
      |                        ^~~~~~~~~~~~~~~~
lepton.c:59:16: note: while referencing '_line_buf'
   59 | extern uint8_t _line_buf;
      |                ^~~~~~~~~
lepton.c:455:34: warning: array subscript 4 is outside array bounds of 'uint8_t[1]' {aka 'unsigned char[1]'} [-Warray-bounds]
  455 |                     vospi_packet + VOSPI_HEADER_SIZE, VOSPI_LINE_SIZE);
      |                                  ^
lepton.c:59:16: note: while referencing '_line_buf'
   59 | extern uint8_t _line_buf;
      |                ^~~~~~~~~
lepton.c:454:13: warning: 'memcpy' forming offset [2, 160] is out of the bounds [0, 1] of object '_vospi_buf' with type 'uint8_t' {aka 'unsigned char'} [-Warray-bounds]
  454 |             memcpy(vospi_buffer + vospi_pid * VOSPI_LINE_SIZE,
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  455 |                     vospi_packet + VOSPI_HEADER_SIZE, VOSPI_LINE_SIZE);
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lepton.c:60:16: note: '_vospi_buf' declared here
   60 | extern uint8_t _vospi_buf;
      |                ^~~~~~~~~~

Yeah, the vospi code is definitely right. It sounds like the gcc version you are using doesn’t understand pointers. Like, that pointer has no length info, thus the compiler can’t know the array bounds, nor should it check that since this is c code…

I also experienced the same issue when compiling on ubuntu20.04 with the latest GCC toolchain.
But after downgraded the GCC with “gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2” and this compile error is gone.

arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The same issue. My gcc version is gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux

Finally, what version do you use?
“gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2” throws

/usr/share/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: /home/kirill/repositories/openmv/src/build/bin/firmware.elf section `.text' will not fit in region `FLASH_TEXT'
/usr/share/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: region `FLASH_TEXT' overflowed by 11736 bytes
collect2: error: ld returned 1 exit status
make: *** [Makefile:490: firmware] Error 1

Hi, we use gcc version 7.3.1 20180622 (7-2018-q2-update) you can get it from here:

https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2