[U-Boot] sprintf side effect, a bug?

Scott Wood scottwood at freescale.com
Tue Jan 27 21:31:52 CET 2009


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?

-Scott


More information about the U-Boot mailing list