|
printf bug - beware!
Well, perhaps not exactly a bug, but at minimum, a land mine.
If you code
prinft("some long string of more than 80 bytes.....\n");
you'll likely begin to have errors elsewhere in your program that are hard to explain or find. This is because the "long string" is copied from program memory (where the compiler puts constant strings) to a ram buffer of 80 bytes, but no length checking is done on the source string. If it exceeds the size of the targer buffer, it is copied in its entirety anyway, trampling other variables in the process.
I modified IFI's printf_lib.c to check for this problem and print an error rather than trampling memory. Anyone who wants the source, I'll be happy to share it.
If you don't want my fix and don't want to do your own, at least be warned that long print strings can lead to really hard to find bugs.....
Bill
|