Re:Tearing apart printf() (2018)
by eqvinox on Wednesday November 13, 2019 @06:54AM
(#21523090)
> 1. printf may malloc so don't use it in an out of memory situation. Though I think this problem is vanishingly unlikely these days.
I'd like to point out that FreeBSD's printf only does this if:
1. you use a lot of arguments (i.e. a compile-time decision, and quite rare)
2. use wchar_t support (also a compile-time decision and quite rare)
3. the output is to something that buffers/mallocs (i.e. stdio)
4. locale support does it for some reason (I simply haven't checked this)
Which makes it great to use in e.g. crash handlers. It's actually Async-Signal-Safe if you cut out the stdio bits. And it's available under BSD license... and actually a nice read (more on that in a separate post.)
I'd like to point out that FreeBSD's printf only does this if:
1. you use a lot of arguments (i.e. a compile-time decision, and quite rare)
2. use wchar_t support (also a compile-time decision and quite rare)
3. the output is to something that buffers/mallocs (i.e. stdio)
4. locale support does it for some reason (I simply haven't checked this)
Which makes it great to use in e.g. crash handlers. It's actually Async-Signal-Safe if you cut out the stdio bits. And it's available under BSD license... and actually a nice read (more on that in a separate post.)