News for hackers. Stuff that matters.
Re:Generalizing Printf in C by lelanthran on Saturday November 29, 2025 @01:15AM (#46085517)
If you really hit the pathological edge case of needed sprintf at runtime with runtime-only buffer sizes, you can still work out the size safely, albeit slowly.

I've done it to make a "safe" sprintf function that allocates the destination buffer, so that the caller cannot overrun it: https://github.com/lelanthran/libds/blob/56d6e18c8970b84c9fa...

Re:Generalizing Printf in C by theamk on Saturday November 29, 2025 @03:20PM (#46090415)
btw, what you did is called "asprintf" in many stdlibs