Re: Added checks for alloc return value in several place.
Samuel Thibault <[email protected]> Fri, 31 Jul 2026 01:41:29 +0200
| Newsgroups | gmane.os.hurd.bugs |
|---|---|
| Organization | I am not organized |
| Message-ID | <amvhKfL8zjzmfP-t@end> |
Hello, Mikhail Karpov, le sam. 25 juil. 2026 12:53:46 +0700, a ecrit: > On Sat, 25 Jul 2026 02:30:07 Samuel Thibault wrote: > > I'd rather return errno rather than hardcoding ENOMEM whenever possible, > > in case malloc may have other issues, better report them precisely. > > > > (but take care that an intermediate function call may overwrite errno so > > in some case you need to save it). > > Are there any recommendations for when to return errno instead of ENOMEM? Oh, I hadn't realized that a lot of existing code was returning ENOMEM... I don't know exactly what the rationale is behind doing this. > If the function is static and only checks for an error, then I don't > think there's any point in changing ENOMEM to errno. Am I correct in > assuming this primarily applies to library callbacks? I guess that when we are returning an error code to other source code, we should be returning ENOMEM, so that other source code can possibly behave properly, faced to something that is similar to memory exhaustion anyway. When we know that we are handling the error ourself in the code by printing it to the user, better keep the real errno, to tell the user the real reason. Sorry for the mis-review on this, Samuel