Hello,
I think I have found a bug in the sprintf function of the C51 run-time library:
If I call sprintf to substitute an integer ("%d", "%u" or "%i") from a one byte variable sprintf will write garbage into the array.
Here a simple example:
unsigned char xdata testArray[5] = ""; // testArray = {0x00, 0x00, 0x00, 0x00, 0x00}
unsigned char xdata oneByteVariable = 1;
sprintf(testArray, "%d", oneByteVariable); // testArray = {0x32, 0x35, 0x36, 0x00, 0x00} ASCII: "256"
If I use instead of a one byte a two byte variable, sprintf will work correctly:
unsigned int xdata twoByteVariable = 1; sprintf(testArray, "%d", twoByteVariable); // testArray = {0x31, 0x00, 0x00, 0x00, 0x00} ASCII: "1"
I am using a silicon labs 8051 with the latest C51 development tools (version 9.55).
Can someone confirm this bug?
Best Regards, Andreas Hornsteiner