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

sprintf() function behaving strange...

Hi,

I'm using uVision IDE V4.53.0.0 and the sprintf() function behaves strange... my piece of code:

_disable_irq();

len = sprintf((char*)myBuf,"%+2.2fV  %+1.3fA",9.13788,-0.004069);

_enable_irq();

This will create a string in myBuf:

"+9.14V -0.004A"

This code is called each 500ms. Suddenly after a minute or so it generates:

"-7265617330774872000000/0/0000000.000000000/0/000000000.00V +17574296777337024000/0/0000.000A"

where /0/ stands for "about 40 zero's"

Also 'len' contains a value of 66 (in stead of 15) which is the position of the first '.' in the resulting string.

As all interrupts are disabled the variables cannot be overwritten by some interrupt handler.

Does anybody know?

Thanks,

Henk

Parents
  • A simple way to catch a stack overflow is to put a data-access breakpoint just beyond the "expected" end of the stack; then, if that breakpoint ever "fires", you know you've got an overflow.

    Except, of course, if the stack overflows by a giant leap right across your trap, instead of walking nice and slowly into it...

Reply
  • A simple way to catch a stack overflow is to put a data-access breakpoint just beyond the "expected" end of the stack; then, if that breakpoint ever "fires", you know you've got an overflow.

    Except, of course, if the stack overflows by a giant leap right across your trap, instead of walking nice and slowly into it...

Children
No data