On Wed, 15 Apr 2026 17:42:41 +0300
Andy Shevchenko <[email protected]> wrote:

> On Wed, Apr 15, 2026 at 02:25:43PM +0200, Thorsten Blum wrote:
> > kasprintf_strarray() returns an array of N strings and kfree_strarray()
> > also frees N entries.  However, kasprintf_strarray() currently allocates
> > N+1 char pointers.  Allocate exactly N pointers instead of N+1.
> > 
> > Also update the kernel-doc for @n.  
> 
> Have you checked all current users that they do not rely on the NULL 
> terminated
> array?
> 
> Note, that was done on purpose that once allocated it can allow user
> to drop the track of the number of strings and rely on NULL terminator.
> I.o.w.  the number of strings may be just a local variable somewhere
> where kasprintf_strarray() is called.
> 
> I tend to NAK this change, rather you can update kernel-doc to explain
> why it's done this way (see above).
> 

It isn't as though it is going to make much difference to the memory
footprint.
Allocating an extra trailing NULL is just a bit safer.

        David

 

Reply via email to