MSP430X Printf Bug Fix

incoherent wrote on Wednesday, June 08, 2011:

There is a bug in printf-stdarg.c when compiling for the large data model.

Line 150:

register char *s = (char *)va_arg( args, int );

Should change to:

register char *s = (char *)va_arg( args, char * );

edwards3 wrote on Wednesday, June 08, 2011:

I think there are three supported compilers, which one needs the change?

incoherent wrote on Wednesday, June 08, 2011:

I’ve tested this on CCS4.2.3, however it is probably relevant to all three (if they support the large data model).

With the large data model, data pointers (e.g. char *) are 32 bits, whereas the same pointers are 16 bits in the small memory model.  In both cases ints are 16 bits, so when the va_arg is incremented it ends up pointing at the high word of the char pointer, rather than pointing to the next argument.

This should fail on any platform in which pointers are not the same size as ints (assuming TI’s va_arg implementation is correct).