Re: net/8021q/vlan.c:241:46: warning: '%.4i' directive output may be truncated writing between 4 and 5 bytes into a region of size between 0 and 15

From: Waiman Long
Date: Mon Feb 10 2025 - 09:25:19 EST


On 2/9/25 11:44 PM, kernel test robot wrote:
Hi Waiman,

FYI, the error/warning still remains.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: a64dcfb451e254085a7daee5fe51bf22959d52d3
commit: 925da92ba5cb0c82d07cdd5049a07e40f54e9c44 rcu: Avoid unneeded function call in rcu_read_unlock()
date: 3 years, 5 months ago
config: sparc-randconfig-r122-20240116 (https://download.01.org/0day-ci/archive/20250210/202502101253.TDZbCYh6-lkp@xxxxxxxxx/config)
compiler: sparc-linux-gcc (GCC) 12.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250210/202502101253.TDZbCYh6-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502101253.TDZbCYh6-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

net/8021q/vlan.c: In function 'vlan_ioctl_handler':
net/8021q/vlan.c:253:46: warning: '%i' directive output may be truncated writing between 1 and 5 bytes into a region of size between 0 and 15 [-Wformat-truncation=]
253 | snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
| ^~
In function 'register_vlan_device',
inlined from 'vlan_ioctl_handler' at net/8021q/vlan.c:628:9:
net/8021q/vlan.c:253:42: note: directive argument in the range [0, 65535]
253 | snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
| ^~~~~~~
net/8021q/vlan.c:253:17: note: 'snprintf' output between 3 and 22 bytes into a destination of size 16
253 | snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/8021q/vlan.c: In function 'vlan_ioctl_handler':
net/8021q/vlan.c:241:46: warning: '%.4i' directive output may be truncated writing between 4 and 5 bytes into a region of size between 0 and 15 [-Wformat-truncation=]
241 | snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
| ^~~~
In function 'register_vlan_device',
inlined from 'vlan_ioctl_handler' at net/8021q/vlan.c:628:9:
net/8021q/vlan.c:241:42: note: directive argument in the range [0, 65535]
241 | snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
| ^~~~~~~~~
net/8021q/vlan.c:241:17: note: 'snprintf' output between 6 and 22 bytes into a destination of size 16
241 | snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +241 net/8021q/vlan.c

Why me? I have never touched net/8021q/vlan.c and I don't believe commit 925da92ba5cb ("rcu: Avoid unneeded function call in rcu_read_unlock()") has anything to do with the snprintf format warnings.

Regards,
Longman