On 2024-10-30 13:45, Jeffrey Walton wrote:
I don't think ENOMEM is a good error for the condition. I guess you can't return EOVERFLOW or ERANGE? Maybe EINVAL would be better if that's the case.
ENOMEM is more likely to do the right thing for the user in practice. Quite a bit of code tests for errno == ENOMEM (whether rightly or wrongly). That's why other Gnulib functions in a similar situation (e.g., reallocarray) use ENOMEM.
For example, it'd be odd if posix_memalign (&p, 2, SIZE_MAX - 1) returned ENOMEM but posix_memalign (&p, 2, SIZE_MAX) returned EOVERFLOW. That sort of thing doesn't feel useful; it feels more like just another hassle for user code to worry about.
If EOVERFLOW didn't imply ENOMEM things might be different.