diff mbox

[U-Boot] net: tftp: silence a subscript above array bounds compile time warning

Message ID 20170628195607.7384-1-vz@mleia.com
State Accepted
Commit 0c17b1b79c3014f3abfe3fee1fa513ad271f4944
Delegated to: Joe Hershberger
Headers show

Commit Message

Vladimir Zapolskiy June 28, 2017, 7:56 p.m. UTC
For strncpy() select a minimal string length of destination and source
strings, here DEFAULT_NAME_LEN is preferable to MAX_LEN.

Due to the NUL-terminated contents of default_string the change is
a noop, however it removes a compilation warning if SH2/3/4 platform
specific strncpy() function is used:

  In file included from include/linux/string.h:21:0,
                   from include/common.h:28,
                   from net/tftp.c:9:

  net/tftp.c: In function 'tftp_start':
  arch/sh/include/asm/string.h:52:42: warning: array subscript is above array bounds [-Warray-bounds]
     : "0" (__dest), "1" (__src), "r" (__src+__n)

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
---
 net/tftp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Joe Hershberger July 27, 2017, 9:40 p.m. UTC | #1
On Wed, Jun 28, 2017 at 2:56 PM, Vladimir Zapolskiy <vz@mleia.com> wrote:
> For strncpy() select a minimal string length of destination and source
> strings, here DEFAULT_NAME_LEN is preferable to MAX_LEN.
>
> Due to the NUL-terminated contents of default_string the change is
> a noop, however it removes a compilation warning if SH2/3/4 platform
> specific strncpy() function is used:
>
>   In file included from include/linux/string.h:21:0,
>                    from include/common.h:28,
>                    from net/tftp.c:9:
>
>   net/tftp.c: In function 'tftp_start':
>   arch/sh/include/asm/string.h:52:42: warning: array subscript is above array bounds [-Warray-bounds]
>      : "0" (__dest), "1" (__src), "r" (__src+__n)
>
> Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger Aug. 7, 2017, 8:32 p.m. UTC | #2
Hi Vladimir,

https://patchwork.ozlabs.org/patch/781896/ was applied to u-boot-net.git.

Thanks!
-Joe
diff mbox

Patch

diff --git a/net/tftp.c b/net/tftp.c
index ced45ec..61e1671 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -742,8 +742,8 @@  void tftp_start(enum proto_t protocol)
 			(net_ip.s_addr >> 16) & 0xFF,
 			(net_ip.s_addr >> 24) & 0xFF);
 
-		strncpy(tftp_filename, default_filename, MAX_LEN);
-		tftp_filename[MAX_LEN - 1] = 0;
+		strncpy(tftp_filename, default_filename, DEFAULT_NAME_LEN);
+		tftp_filename[DEFAULT_NAME_LEN - 1] = 0;
 
 		printf("*** Warning: no boot file name; using '%s'\n",
 		       tftp_filename);