DM-Crypt Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Arno Wagner <arno@wagner.name>
To: dm-crypt@saout.de
Subject: Re: [dm-crypt] goto patch for cryptsetup?
Date: Fri, 7 Mar 2014 13:11:16 +0100	[thread overview]
Message-ID: <20140307121116.GA28388@tansi.org> (raw)
In-Reply-To: <5319A4DC.6080806@tu-ilmenau.de>

On Fri, Mar 07, 2014 at 11:52:12 CET, Lars Winterfeld wrote:
> 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;

Urgh. That is exceedingly ugly and even less readable than 
with goto, as it misuses a loop as goto.Pleas do not do such
things, the cure is worse than the disease.
 
> 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;

And there you will get scoping problems and need to put stuff in 
structs just so you can pass them as argument. Not good.
 
> 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.

Not me. Both your examples are harder to read. I do not
think getting rid of goto helps in any way as long as
goto is used competently and with restraint. In this
case, it is often superiour to other constructs.
 
Arno

> It's up to you. I would do the work. What do you think?
> 
> Cheers,
> Lars
> 
> 



> _______________________________________________
> dm-crypt mailing list
> dm-crypt@saout.de
> http://www.saout.de/mailman/listinfo/dm-crypt


-- 
Arno Wagner,     Dr. sc. techn., Dipl. Inform.,    Email: arno@wagner.name
GnuPG: ID: CB5D9718  FP: 12D6 C03B 1B30 33BB 13CF  B774 E35C 5FA1 CB5D 9718
----
A good decision is based on knowledge and not on numbers. -  Plato

  reply	other threads:[~2014-03-07 12:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-06 20:39 [dm-crypt] goto patch for cryptsetup? Lars Winterfeld
2014-03-06 23:27 ` Arno Wagner
2014-03-07  5:23 ` Milan Broz
2014-03-07 10:52   ` Lars Winterfeld
2014-03-07 12:11     ` Arno Wagner [this message]
2014-03-07 12:16     ` .. ink ..
2014-03-07 16:11     ` Milan Broz
2014-03-08 16:20       ` Arno Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140307121116.GA28388@tansi.org \
    --to=arno@wagner.name \
    --cc=dm-crypt@saout.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox