On Wed, 2024-03-06 at 19:55 +0100, Reuben Thomas wrote: > In getcwd.c I find the following comment: > > > In GNU, if BUF is NULL, an array is allocated with 'malloc'; the > > array is SIZE bytes long, unless SIZE == 0, in which case it is as > > big as necessary. > > However, as far as I can see from the code, it always allocates if > BUF is NULL.
I don't think your observation contradicts the comment...is there more to it? Note the use of a semicolon here which means that the second clause is "separate from" the first clause; this could be rewritten as something like: In GNU, if BUF is NULL, an array is allocated with 'malloc'. If allocated, the allocated array is SIZE bytes long, unless SIZE == 0, in which case it is as big as necessary.