On (27/08/14 17:21), Pavel Reichl wrote:
On 08/27/2014 05:12 PM, Lukas Slebodnik wrote:
>On (27/08/14 17:10), Pavel Reichl wrote:
>>On 08/27/2014 10:09 AM, Lukas Slebodnik wrote:
>>>warning reported by coverity
>>>patch is attached
>>As I understand the code there is no way that 0 could be passed as second
>>argument to the realloc call, right? Because that would lead to freeing same
>>Would it be more defensive approach to test for zero argument explicitly?
>>What do you think Lukas?
>NULL can be returned if there is not memory for allocation (ENOMEM).
>For example you will try to allocate 2^31 bytes
NULL can be also returned if you pass 0 as the size parameter, which would in
our case lead to calling free on the same pointer twice, which is baaaad!
If you are explicitly interested in ENOMEM case, you may consider checking
value of errno.
Still I think it is better to test value of size parameter.
I do not agree.
Documentation of getgrouplist is clear.
If the number of groups of which user is a member *is less than or equal*
to *ngroups, then the value *ngroups is returned.
If the user is a member of more than *ngroups groups, then getgrou‐
plist() returns -1. In this case, the value returned in *ngroups can
be used to resize the buffer passed to a further call getgrouplist().
And the initial value of ngroups is 32. It means it cannot be lower.