[U-Boot] 4xx warnings on cmd_elf.c

So when I build a 4xx config I see:
cmd_elf.c: In function 'do_bootvx': cmd_elf.c:173: warning: array subscript is below array bounds cmd_elf.c:176: warning: array subscript is below array bounds cmd_elf.c:181: warning: array subscript is below array bounds
sprintf (build_buf, "ibmEmac(0,0)");
if ((tmp = getenv ("hostname")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "host:%s ", tmp); } else { sprintf (&build_buf[strlen (build_buf - 1)], ": "); }
if ((tmp = getenv ("ipaddr")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "e=%s ", tmp); }
these seem suspect.. should this be &build_buf[strlen(build_buf) - 1] ?
- k

On Friday 31 October 2008, Kumar Gala wrote:
So when I build a 4xx config I see:
cmd_elf.c: In function 'do_bootvx': cmd_elf.c:173: warning: array subscript is below array bounds cmd_elf.c:176: warning: array subscript is below array bounds cmd_elf.c:181: warning: array subscript is below array bounds
sprintf (build_buf, "ibmEmac(0,0)"); if ((tmp = getenv ("hostname")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "host:%s ", tmp); } else { sprintf (&build_buf[strlen (build_buf - 1)], ": "); } if ((tmp = getenv ("ipaddr")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "e=%s ", tmp); }
these seem suspect.. should this be &build_buf[strlen(build_buf) - 1] ?
I haven't seen those warnings before. Triggered by your newer gcc most likely. But you seem to be correct. The current code is definitely wrong. And I think that your version is wrong as well. This should do the "right thing":
&build_buf[strlen(build_buf)]
I have no VxWorks platform to test this though.
Best regards, Stefan
===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de =====================================================================

Stefan Roese wrote:
On Friday 31 October 2008, Kumar Gala wrote:
So when I build a 4xx config I see:
cmd_elf.c: In function 'do_bootvx': cmd_elf.c:173: warning: array subscript is below array bounds cmd_elf.c:176: warning: array subscript is below array bounds cmd_elf.c:181: warning: array subscript is below array bounds
sprintf (build_buf, "ibmEmac(0,0)"); if ((tmp = getenv ("hostname")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "host:%s ", tmp); } else { sprintf (&build_buf[strlen (build_buf - 1)], ": "); } if ((tmp = getenv ("ipaddr")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "e=%s ", tmp); }
these seem suspect.. should this be &build_buf[strlen(build_buf) - 1] ?
I haven't seen those warnings before. Triggered by your newer gcc most likely. But you seem to be correct. The current code is definitely wrong. And I think that your version is wrong as well. This should do the "right thing":
&build_buf[strlen(build_buf)]
You are definitely right. But the code is broken in several ways as it does no generate a correct bootline which can be interpreted by vxWorks
I have no VxWorks platform to test this though.
A patch (tested) on my HCUx platform will follow soon.
Best regards, Stefan
Best regards
Niklaus
participants (3)
-
Kumar Gala
-
Niklaus Giger
-
Stefan Roese