[Cryptography] GnuTLS -- time to look at the diff.

Patrick Chkoreff patrick at rayservers.net
Fri Mar 7 15:04:47 EST 2014


Harald Koch wrote, On 03/07/2014 01:49 PM:

> Anyone hung up on goto should learn that you can write the same code with:
> 
>     do {
>        if (something fails) {
>           break;
>        }
> 
>        ...
> 
>     } while (false);
> 
>     /* cleanup code goes here */
> 
> 
> This has no goto, but it has exactly the same failure modes as the
> goto-laden code (btw, if you're looking for a "goto cleanup;" equivalent
> in Java, this is how you do it).


Yes, I like that.  It's a highly malleable technique, in the sense that
you can easily nest it or move it into a separate routine.

It's almost like a code block which returns a value -- a feature that C
doesn't actually have.  Instead of a return value, you can declare some
auto variables before the "do", and have the loop body set those
variables fully, or partially in the case of a break.  If you make sure
to initialize the auto vars to 0, which is easy to do in C, then the
presence of 0 values can itself indicate certain failure modes in the
code below the "while", after the (one-shot) loop ends.


-- Patrick



More information about the cryptography mailing list