Hi,
I have an project that use snprintf to convert float to string. The project works perfectly. But when I place line: const unsigned int Protect __attribute__((at (0x1FC))) = 0x12345678; the snprintf crashes. I replaced the function for two snprintf of integer to string and that's all right. The stack and heap are sufficient and how i don't have the source code of function, i don't get to debug. Sorry for my bad english.
But when I place line:
const unsigned int Protect __attribute__((at (0x1FC))) = 0x12345678;
the snprintf crashes.
Well, so don't do that!
But this line is necessary for protect my system from firmware copy !
Maybe you should provide (your) source code for the snprintf() line.
This is the function:
unsigned char FLT_FloatToStr(float valor, unsigned char **str, unsigned char *strsize) { char tmp[44],ret; ret = 0; *strsize = snprintf(tmp,sizeof(tmp), "%0.2f", valor); if (*strsize) { *str = (unsigned char *) malloc(*strsize); if (*str) { memcpy(*str,tmp,*strsize); ret = 1; } } return(ret); }
Note that snprintf() returns the number of printer characters _excluding_ the terminating '\0'.
So your function will deliver a character array that does not contain any terminating zero.
No problem because my function returns size too. Others funtions works with this size.