UB status of snprintf on invalid ptr+size combination?

Vincent Lefevre vincent@vinc17.net
Mon Mar 20 04:10:57 GMT 2023


On 2023-03-20 00:24:51 +0100, Andreas Schwab wrote:
> On Mär 19 2023, Vincent Lefevre wrote:
> 
> > On 2023-03-18 16:01:07 +0100, Andreas Schwab wrote:
> >> On Mär 18 2023, Vincent Lefevre wrote:
> >> 
> >> > However, I'm wondering whether such a change is intentional. BTW,
> >> > this description is even wrong: this is certainly not equivalent!
> >> > If the untruncated output is larger than n, then the call is UB
> >> > with sprintf(), while the output is truncated with snprintf().
> >> 
> >> Which makes them equivalent in all situations where sprintf is defined,
> >> so there is no discrepancy here.
> >
> > The conditions under which the function is defined or not are part of
> > the equivalence.
> 
> No, it isn't.  Equivalent is not the same as identical.
> 
> > For instance, I would not say that memcpy and memmove are equivalent,
> > even though they are equivalent when memcpy is defined.
> 
> But they are.  You can use either memcpy or memove in all situations
> where memcpy is defined.  Outside of the domain of memcpy there is no
> relation at all.

POSIX specifies _exit() by:

  The _Exit() and _exit() functions shall be functionally equivalent.

So, you mean that _exit() may have undefined behavior while _Exit()
has a well-defined behavior? (as this would match your definition
of equivalence.)

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the Libc-alpha mailing list