Rich Bair

sprintf concerns (floating point)

Discussion created by Rich Bair on Aug 11, 2006
Latest reply on Aug 16, 2006 by CompilerGuru
In regards to this code below:
 
Code:
    volatile int cnt;    char flt_buf[15] = {0};    /* Load the float into a string */    __DI();    if (dp == 1U) {        /* Showing tenths */        cnt = sprintf(&flt_buf[0], "%-5.1f", val);        /* Override term! */        term = 0U;    }    else {        /* No tenths */        cnt = sprintf(&flt_buf[0], "%-5.0f", val);    }    __EI();

 
1) Is it necessary to protect ansilibb (banked) library calls from interrupts as shown...I seem to have (odd COP resets otherwise)?
2) Is ansilibb reentrant (if isr code calls a ansilibb function [could be same function] will this fail)?
3) I'm a bit concerned that the width specifier is a "minimum" value and this could be overrun...what are some good ideas to protect against this other that oversizing the buffer?
 
Thanks!
 

Outcomes