This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with snprintf with float and at attribute

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.

Parents
  • 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);
    }
    

Reply
  • 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);
    }
    

Children