Re: [RFC v1 0/3] Add and use seprintf() instead of less ergonomic APIs

From: Rasmus Villemoes
Date: Tue Jul 08 2025 - 02:45:12 EST


On Sat, Jul 05 2025, Alejandro Colomar <alx@xxxxxxxxxx> wrote:

> On top of that, I have a question about the functions I'm adding,
> and the existing kernel snprintf(3): The standard snprintf(3)
> can fail (return -1), but the kernel one doesn't seem to return <0 ever.
> Should I assume that snprintf(3) doesn't fail here?

Yes. Just because the standard says it may return an error, as a QoI
thing the kernel's implementation never fails. That also means that we
do not ever do memory allocation or similar in the guts of vsnsprintf
(that would anyway be a mine field of locking bugs).

If we hit some invalid or unsupported format specifier (i.e. a bug in
the caller), we return early, but still report what we wrote until
hitting that.

Rasmus