
Dear E Robertson,
In message 200901261453.10434.e.robertson.svg@gmail.com you wrote:
It seems that sprintf() is modifying at least two bytes from the source and I have duplicate this with different varibles. For instance, I have a mac address defined as unsigned char [6]: Doing the following sets the environment variable correctly, however bytes [0] and [1], are modified at the source.
sprintf(env_ethaddr,"%02X:%02X:%02X:%02X:%02X:%02X", MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3], MACAddress[4], MACAddress[5]);
Has anyone noticed this before? I don't think the machine matters but I am building for an arm at91.
Hmm... I think I wouldbe surprised. What exactly does your test code look like?
I tried this one:
... unsigned char buf[128]; unsigned char a[6] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, }; int i; ... printf ("Before: "); for (i=0; i<6; ++i) printf (" %02X",a[i]); putc ('\n'); sprintf (buf, "%02X:%02X:%02X:%02X:%02X:%02X", a[0], a[1], a[2], a[3], a[4], a[5]); printf ("After: "); for (i=0; i<6; ++i) printf (" %02X",a[i]); putc ('\n'); printf ("buf="%s"\n", buf); ...
And this is what I got:
Before: 11 22 33 44 55 66 After: 11 22 33 44 55 66 buf="11:22:33:44:55:66"
Looks sane to me...
Best regards,
Wolfgang Denk