This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: What's needed for sprintf?


On Fri, Sep 22, 2006 at 01:13:59PM -0400, Matt Gessner wrote:
> Very occasionally, a call to sprintf will go off into the weeds... The
> culprit is memmove, which is being given some out-of-range pointers.  

I've seen this too on occation, and still been unable to figure out how
things got that way, even WITH an interactive debugger.

I've always chalked it up to some weird memory errors on our
hand-soldered RAM piggybacked development boards, since it's not easily
replicatable.  and a stripped down version of printf statement that
tumbled into the weeds can run for hundred thousand iterations and be
fine...

int out = 9279;
snprintf(string, 6, "%5.1f", out/100.0);

it always seemed to end up here:

(gdb) bt
#0  _multiply (ptr=0x30a3ce, a=0x35ba34, b=0x353264)
    at /projects/xgcc/newlib-1.12.0/newlib/libc/stdlib/mprec.c:336
#1  0x002aa72c in _pow5mult (ptr=0x30a3ce, b=0x35ba34, k=536870911)
    at /projects/xgcc/newlib-1.12.0/newlib/libc/stdlib/mprec.c:441
#2  0x002a93de in _dtoa_r (ptr=0x30a3ce, _d=70.069999999999993, mode=3,
    ndigits=1, decpt=0x329714, sign=0x2aa536, rve=0x32970c)
    at /projects/xgcc/newlib-1.12.0/newlib/libc/stdlib/dtoa.c:652
#3  0x002a7e42 in _vfprintf_r (data=0x30a3ce, fp=0x329d74, fmt0=0x4051847a "",
    ap=0x329dec)
    at /projects/xgcc/newlib-1.12.0/newlib/libc/stdio/vfprintf.c:1257
#4  0x002a34b4 in snprintf (str=0x353264 "", size=6, fmt=0x2c0c8f "%5.1f")
    at /projects/xgcc/newlib-1.12.0/newlib/libc/stdio/snprintf.c:88

-- 
  Aaron J. Grier  |   Frye Electronics, Tigard, OR   |  aaron@frye.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]