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.
No problem because my function returns size too. Others funtions works with this size.
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.
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); }
Maybe you should provide (your) source code for the snprintf() line.
But this line is necessary for protect my system from firmware copy !
But when I place line:
const unsigned int Protect __attribute__((at (0x1FC))) = 0x12345678;
the snprintf crashes.
Well, so don't do that!
View all questions in Keil forum