Return-Path: Received: from wega.rz.tu-ilmenau.de (wega.rz.tu-ilmenau.de [141.24.4.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.saout.de (Postfix) with ESMTPS for ; Fri, 7 Mar 2014 11:52:14 +0100 (CET) Message-ID: <5319A4DC.6080806@tu-ilmenau.de> Date: Fri, 07 Mar 2014 11:52:12 +0100 From: Lars Winterfeld MIME-Version: 1.0 References: <5318DCEF.5020004@tu-ilmenau.de> <531957DD.7020401@gmail.com> In-Reply-To: <531957DD.7020401@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="9rp9qfK9l3AD89B7GSia1sw0vwmMgjU7J" Subject: Re: [dm-crypt] goto patch for cryptsetup? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Milan Broz , dm-crypt@saout.de This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --9rp9qfK9l3AD89B7GSia1sw0vwmMgjU7J Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 patc= h >> replacing all 328 gotos with their semantic equivalents from structure= d >> C programming? >=20 > cryptsetup code uss goto for only one purpose: to have only one exit > place from a function (with check for errors, release memory). >=20 > 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? Cheers, Lars --9rp9qfK9l3AD89B7GSia1sw0vwmMgjU7J Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBAgAGBQJTGaTdAAoJEA4jvzLPLJH4HRoP/3lb2VBqqDH1yeksi+BSyX5A n7ZV7Y15B2tkDiZ8dBVHlEizXTqW2gOK1QWwytw7bZYHJNVk9j+5vfNdqnlaA1w1 7QHymL+MD9APDr7Ntb31UYEUG76ZEVPMWLzBl/DC5iBya5oP3kqchNAVjeFvb2JP WGtI8/XOkXWtBMLcPrvUXXFH+p/ANO5bt1V+wgF8IBoCK4Sj+4tVjgWkoOVURF+I J4E1dGtU1ZilBDj+XNL8f10jxafjxy0k7H1RT0UkIlg6J6Pexa6aJRpQNveBhc3O 5o8Ae3mDeU5uswPwh1H9ziv661c0OUVgIDynt5/eecEhxgggiZRGKLMt40RUQiSu BL3VJ4QvmDJPZcSlYh+XOB0Ddx+yz5Wg9AFIyXeIPzAyOFkrQp1DdGMWoSKL94VO y/WI4zlr+2AwemhtcwQHBzREQOtkKfHe5R4ZGPhFL+WvM0tMs5E7rD9L3yjV065L Yp9dy83kpiWjwrxYf/0aQ+0MGGdZEtncbBiC/QC+KQ73av2XMn7q8NqQsEq8W863 qetN079cEEw0B9g5DcvbG5Af+qR9nDpXrofteUXRH3Tutcw2kBsvb935QzU6hv35 26wLYi/ftOxiEAb6T7yRsk4Z6PUNCgA8uXariZsYToc/kJJkFfAsQUPQ9KKSlnzD 4RMAfN/fnY+6vegi4Gou =MY1W -----END PGP SIGNATURE----- --9rp9qfK9l3AD89B7GSia1sw0vwmMgjU7J--