Part Number: LAUNCHCC3220MODASF
Hello everyone,
I use the CCS11 and the SDK 5.30.
I have two questions about the snprintf function coming with the compiler in CCS11.
1. Multithreading
As far as I know snprintf is thread safe in the very most implementation.
I inspected that the snprintf calls the function _PRINTFI that also uses only locale variables.
I also found the following comment in the description of _PRINTFI.
/* For multi-threaded applications, when this function is called on */
/* behalf of fprintf, printf, vfprintf, or vprintf, the call site should */
/* be enclosed in a critical section that guarantees single-threaded */
/* access to the file stream.
So I assume that TI implementation for snprintf is thread safe too.
I am right?
2. Null pointer as destination buffer
The following lines shows a sampe code, that reads, writes the address zero and calls snprintf with a NULL pointer as destination buffer.
{
#define ADR0 (*(volatile uint32_t *)(0x0000))
uint32_t u32_Value = ADR0;
LOG_INFO( "read adr 0: 0x%x", u32_Value );
ADR0 = 0x12345678;
u32_Value = ADR0;
LOG_INFO( "read adr 0 after write 0x12345678: 0x%x", u32_Value );
ADR0 = 0x12345678;
i32_Result = snprintf( (char*)NULL, (size_t)64, "TestString" ); // strlen = 10
LOG_INFO( "format 0: returns %d", i32_Result );
}
Result:
read adr 0: 0x20004000
read adr 0 after write 0x12345678: 0x20004000
format 0: returns 10
As far as I know the behavior ot the snprintf is conform to C99.
But I am wondering that the writes, starting at address NULL really takes place (see picture).
The address NULL seems to be the mapped first ROM address containing the start of the stack.
I assume that the writes to address NULL are ignored because the memory protection is not active.
Was it planned in that way?
Will that behavior be the same in TIRTOS 7?
Best regards,
Roman