Re: [PATCH] Add NULL checks for getugroups grouplist argument

Rx <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <[email protected]>
19.08.2026 19:15, Paul Eggert wrote:
> On 2026-08-19 08:24, Sergey Zhidkih wrote:
>> So if this is the case, then there's no need for explicit NULL check
>> for grouplist. This inconsistency creates questions which are detected
>> by static analyzers.
>
> The other option would be adding _GL_ATTRIBUTE_NONNULL_IF_NONZERO to 
> the header declaring getugroups.
I think that would work as well, but in that case, explicit NULL check 
would be redundant.
>  Not sure I see the use case for a null pointer and a nonzero count.

For example, if the user doesn't have an allocated buffer yet but has 
strict memory constraints, they may need to know how many groups there 
are before allocating the buffer. They could pass NULL as grouplist and 
maxcount as an upper bound for the buffer size. Then, when the function 
returns the count, it would provide a size that is guaranteed to fit 
within the user's memory constraints.

But I agree that this use case is too niche.  I will send another patch.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.