[ovs-dev] [PATCH 1/2] lldp: fix string warnings

Ben Pfaff blp at ovn.org
Thu Jun 14 20:23:50 UTC 2018


On Wed, Jun 13, 2018 at 03:43:03PM -0400, Aaron Conole wrote:
> lib/lldp/lldpd.c: In function :
> lib/lldp/lldpd.c:520:17: warning:  output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
>                 strncat(buffer, cfg->g_protocols[i].name,
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>                 strlen(cfg->g_protocols[i].name));
>                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> lib/lldp/lldpd.c: In function :
> lib/lldp/lldpd.c:519:17: warning:  specified bound 2 equals source length [-Wstringop-overflow=]
>                 strncat(buffer, ", ", 2);
>                 ^~~~~~~~~~~~~~~~~~~~~~~~
> 
> Closer inspection shows that buffer is only used to output protocol names
> when debug logging is enabled, so restructure the code a bit as well.
> 
> Signed-off-by: Aaron Conole <aconole at redhat.com>

Thanks, Aaron.  I made a few further simplifications and applied this to
master.

What version of GCC are you using?  Are you turning up the warning
level explicitly?  I don't get these warnings with OVS default warnings
and GCC 7.2.

Thanks,

Ben.


More information about the dev mailing list