[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/3] tools/golang: When returning pointers, actually allocate structrues



On Fri, Apr 19, 2024 at 4:27 PM Nick Rosbrook <rosbrookn@xxxxxxxxx> wrote:
>
> On Fri, Apr 19, 2024 at 10:00 AM George Dunlap <george.dunlap@xxxxxxxxx> 
> wrote:
> >
> > In a handful of cases, it was decided to return a pointer to a
> > structure rather than the plain structure itself, due to the size.
> > However, in these cases the structure was never allocated, leading to
> > a nil pointer exception when calling the relevant `fromC` method.
> >
> > Allocate structures before attempting to fill them in.
> >
> > Fixes: 453713b1750 ("golang/xenlight: Add host-related functionality")
> > Reported-by: Tobias Fitschen <tobias.fitschen@xxxxxxxxx>
> > Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxx>
> > Tested-by: Tobias Fitschen <tobias.fitschen@xxxxxxxxx>
>
> Acked-by: Nick Rosbrook <rosbrookn@xxxxxxxxx>
>
> This is one of the reasons I don't like using named return values (if
> you can help it) and naked returns. When you declare the variable
> explicitly you are less likely to explicitly initialize it to nil. Or,
> it's a compile time error if you forget all together.

Yes, after having more experience in golang I wouldn't be opposed to
getting rid of all those now.  But as I'm hoping to backport this as a
bug fix, that would be a subsequent patch. :-)

Thanks,
 -George



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.