littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
5.18k stars 794 forks source link

GCC Warning - 'strncpy' output truncated before terminating nul copying #789

Closed baldhead69 closed 9 months ago

baldhead69 commented 1 year ago

Hi,

Just for information, if littlefs project team want to fix the code.

../src/config/default/system/fs/src/sys_fs_littlefs_interface.c: In function 'LITTLEFS_stat':
../src/config/default/system/fs/src/sys_fs_littlefs_interface.c:411:13: warning: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
             strncpy (stat->lfname, info.name, fileLen);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/config/default/system/fs/src/sys_fs_littlefs_interface.c:400:15: note: length computed here
     fileLen = strlen (info.name);
               ^~~~~~~~~~~~~~~~~~
geky commented 1 year ago

Hi @baldhead69, thanks for raising an issue.

This actually looks like it's in a higher-level wrapper than the codebase here. Are you using a framework such as Mbed/Zephyr/Arduino?

baldhead69 commented 1 year ago

Hi @baldhead69, thanks for raising an issue.

This actually looks like it's in a higher-level wrapper than the codebase here. Are you using a framework such as Mbed/Zephyr/Arduino?

Hi @geky ,

I am using microchip mplab code configurator( MCC ) to generate the code for a pic32mz chip.

https://github.com/MicrochipTech/littlefs

/// Version info ///

// Software library version
// Major (top-nibble), incremented on backwards incompatible changes
// Minor (bottom-nibble), incremented on feature additions
#define LFS_VERSION 0x00020005
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >>  0))

// Version of On-disk data structures
// Major (top-nibble), incremented on backwards incompatible changes
// Minor (bottom-nibble), incremented on feature additions
#define LFS_DISK_VERSION 0x00020000
#define LFS_DISK_VERSION_MAJOR (0xffff & (LFS_DISK_VERSION >> 16))
#define LFS_DISK_VERSION_MINOR (0xffff & (LFS_DISK_VERSION >>  0))