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?


I've used newlib's sprintf quite extensively without trouble. As a
general rule, I would suggest using snprintf instead of sprintf in
case some unexepected set of conditions is causing you to overflow
your output buffer.

If newlib's sprintf implementation uses the heap (i.e. malloc) -- I
don't know if it does, but it doesn't seem unlikely -- you may have
mucked up your heap (heap/stack collision or any one of the myriad
ways to muck one's heap).

Sorry that the advice is pretty general, but so is the question!

Cheers,
Shaun

On 9/22/06, Matt Gessner <mgessner@avidyne.com> wrote:
Hi, all,

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.

As you can imagine, this can be quite difficult to debug, partly because
I have no interactive debugger, but mostly because I can sometimes leave
the system to run for literally days on end with no problems, but a
restart can sometimes leave me in a spot where the system just dies
after a few minutes.

I'm wondering if perhaps I've not defined everything I need to.  I have
a write_r() (which calls my own write()), open_r (which calls my open),
close_r (yada yada yada).  The rest of my functions like isatty are from
what was in the manual.

To the point: have I forgotten something that would cause fvwrite (which
is memmove's caller) to mistakenly decide to do something else with the
buffer that I otherwise wouldn't want?

I hope this is clear.  If it's not, I'd be happy to give some more
details.

Regards,

Matt Gessner


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