Policy for return by reference values in error cases

Joel Sherrill joel at rtems.org
Tue Mar 23 18:37:27 UTC 2021


On Tue, Mar 23, 2021 at 12:58 PM Sebastian Huber <
sebastian.huber at embedded-brains.de> wrote:

> On 23/03/2021 18:48, Joel Sherrill wrote:
>
> > My first thought is that I don't like covering up for applications
> > that do the wrong thing.
> This topic just came up recently in a discussion about defensive
> programming. We also test for NULL pointers.
> >
> > I'm overall rather ambiguous. It is possible that setting the value at
> > the top of the function could lead to overridden before used issues
> > with warnings and static analysis.
>
> You mean code like this:
>
> void (int *x, int y)
>
> {
>
>    *x = 0;
>
>   if (y) {
>
>     *x = 1;
>
> } else {
>
>   *x = 2;
>
> }
>
> ?
>

Yep. That's a pretty clear case.

Others should speak up but I just don't want the solution pattern
to introduce warnings or static analysis reports. It easily could.



> > I don't want to see every error case assign a value to an output
> > parameter though.
> Yes, I don't like this also.
>

I have my own wish list for error paths eventually if we ever get bored. :)


--joel


>
> --
> embedded brains GmbH
> Herr Sebastian HUBER
> Dornierstr. 4
> 82178 Puchheim
> Germany
> email: sebastian.huber at embedded-brains.de
> phone: +49-89-18 94 741 - 16
> fax:   +49-89-18 94 741 - 08
>
> Registergericht: Amtsgericht München
> Registernummer: HRB 157899
> Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
> Unsere Datenschutzerklärung finden Sie hier:
> https://embedded-brains.de/datenschutzerklaerung/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20210323/d2d60bb0/attachment-0001.html>


More information about the devel mailing list