[dm-crypt] goto patch for cryptsetup?

Lars Winterfeld lars.winterfeld at tu-ilmenau.de
Fri Mar 7 11:52:12 CET 2014

Am 03/07/2014 06:23 AM, schrieb Milan Broz:
> On 03/06/2014 09:39 PM, Lars Winterfeld wrote:
>> Hi,
>> in light of the latest "goto fail"s out there, would you reject a patch
>> replacing all 328 gotos with their semantic equivalents from structured
>> C programming?
> cryptsetup code uss goto for only one purpose: to have only one exit
> place from a function (with check for errors, release memory).
> Replacing it with anything else means duplicating of lot of code.

I agree that code duplication is undesirable. I can think of two
alternatives to goto that do not duplicate code. The first is to
introduce a one-time loop like this:

do {
// foo
if(a) break; // was: goto out;
// bar
if(b) break; // was: goto out;
// "all good" code
return 0;
} while(0);
// was: out:
// "on error" code
return -1;

The second alternative would be to introduce a new function like

int foo_failed(struct bar* p) {
	// clean p
	return -1;

and then inside the "int foo()":
if(a) return foo_failed(p);
instead of
if(a) goto fail;

Like with indentation, I think this is just a question of coding style.
Changes there don't make the program better, it just makes the code
nicer to read in the eyes of some people.

It's up to you. I would do the work. What do you think?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://www.saout.de/pipermail/dm-crypt/attachments/20140307/b95bf596/attachment.asc>

More information about the dm-crypt mailing list