News for hackers. Stuff that matters.
Re:strcpy: A niche function you don't need by cperciva on Friday July 30, 2021 @11:22PM (#28014974)
If asprintf() terminated the program when it failed instead of leading on to undefined behaviour when unchecked, I'd call that trivially safe in a more pragmatic way.

Ugh. Maybe in some contexts that's ok, but some of us write code which handles memory allocation failures with a bit more finesse than abort().

Re:strcpy: A niche function you don't need by pcwalton on Friday July 30, 2021 @11:55PM (#28015143)
In most contexts aborting on malloc failure is OK, and preferable to trying to handle it gracefully, which has caused lots of problems, including security problems. On Linux you need to be running in a non-default configuration for malloc to be fallible in the first place (other than in trivial circumstances like attempting to request exabytes of memory in a single call).
Re:strcpy: A niche function you don't need by cperciva on Saturday July 31, 2021 @12:10AM (#28015219)
Yeah, that's one of the things I don't like about Linux.
Re:strcpy: A niche function you don't need by jlokier on Saturday July 31, 2021 @12:47PM (#28019722)
And some of us includes me.

But at the point where you're able to handle all memory allocation failures usefully, you're almost certainly doing something non-trivial to recover.

For example aborting some requested transaction, pruning items from your program's caches, delaying a subtask to release its temporary memory, or compressing some structures. At that point there's nothing "trivially" safe about a memory allocation.

Probably there are bugs in those recovery actions too. Even the obviously most simple recovery action of propagating an error return to abort a request: If that's a network request, just returning the error "sorry out of memory" is potentially going to fail. So you need recovery from the recovery path failing.