From mboxrd@z Thu Jan 1 00:00:00 1970 From: E Robertson Date: Tue, 27 Jan 2009 14:57:25 -0600 Subject: [U-Boot] sprintf side effect, a bug? In-Reply-To: <497F6F38.4070604@freescale.com> References: <200901261453.10434.e.robertson.svg@gmail.com> <200901271419.36674.e.robertson.svg@gmail.com> <497F6F38.4070604@freescale.com> Message-ID: <200901271457.30522.e.robertson.svg@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Tuesday 27 January 2009 02:31:52 pm Scott Wood wrote: > E Robertson wrote: > > I did the following: > > memcpy (gd->bd->bi_enetaddr, MACAddress, > > sizeof(gd->bd->bi_enetaddr)); memcpy (dupMACAddress, MACAddress, > > sizeof(dupMACAddress)); > > > > printf("Before %02X:%02X:%02X:%02X:%02X:%02X\n",dupMACAddress[0], > > dupMACAddress[1], > > dupMACAddress[2], dupMACAddress[3], > > dupMACAddress[4], dupMACAddress[5]); > > > > sprintf(env_ethaddr,"%02X:%02X:%02X:%02X:%02X:%02X",dupMACAddress[0], > > dupMACAddress[1], > > dupMACAddress[2], dupMACAddress[3], > > dupMACAddress[4], dupMACAddress[5]); > > printf("After %02X:%02X:%02X:%02X:%02X:%02X\n",dupMACAddress[0], > > dupMACAddress[1], > > dupMACAddress[2], dupMACAddress[3], > > dupMACAddress[4], dupMACAddress[5]); > > printf("ethaddr > > %02X:%02X:%02X:%02X:%02X:%02X\n",gd->bd->bi_enetaddr[0], > > gd->bd->bi_enetaddr[1], > > gd->bd->bi_enetaddr[2], gd->bd->bi_enetaddr[3], > > gd->bd->bi_enetaddr[4], gd->bd->bi_enetaddr[5]); > > > > > > and I got this: > > > > Before 00:04:A6:00:6A:E6 > > After 36:00:A6:00:6A:E6 > > ethaddr 00:04:A6:00:6A:E6 > > Alse env_ethaddr has the correct correct. > > Looks like you're overflowing a buffer -- 0x36 0x00 are the last two > bytes of the sprintf output. Where are env_ethaddr and dupMACaddress > defined? > Ah!! Yes, big user error! I forgot about the string termination. Thanks. > -Scott -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. Url : http://lists.denx.de/pipermail/u-boot/attachments/20090127/01ef3c71/attachment.pgp