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

safe sprintf

Hi,

Unfortunately it seems that Keil brings only the standard version of sprintf which ist not safe against Buffer Overflows.
So I am looking for a safe version (like snprintf from libsafe).

Can anybody give me a hint where to find sources or even better did anybody already write a snprintf and is willing to share his code with me?

Best regards,
Marcus

Parents Reply Children
  • "Seriously, Google found it in a jiffy"

    Another very helpful answer... Board would take half the size...
    Anyway, I know Google finds a lot of stuff, and I also already looked through the sources of my Linux Implementation.
    But most of that code is plattform dependant using other extensions of the libc.

    My Intention was to spare some time for porting Code in case others already did that. Obviously it is not the case so just close this thread.

    @Drew: Thanks for the hint. But I now create my own stdio-lib.

  • You're joking, right?

    Google for "snprintf.c"

    "Anyway, I know Google finds a lot of stuff ... But most of that code is plattform dependant using other extensions of the libc."

    1. Nope, not the first reference.
    2. Nope, not the second reference.
    3. Nope, not the third reference.
    4. Nope, not the fourth reference.
    5. ...

  • ok ok, you are right and there are independant implementations ^^.
    What I meant is that they simply contain lots of stuff for various other plattforms I do not need. I know its not the problem, most of the code will not be used if you do not define what you don't need, but I would have to clean it up anyway. And I also do not need most of the supported specifiers. %s, c, d, u are sufficient. No long, long long, precision or whatever. I just needed a small and simple code saving implementation.