Apple's goto fail is a dead class of bugs (was: mutt_buffer_concat_path is broken [PATCH: 1/1])

Alejandro Colomar via Mutt-dev <[email protected]> Thu, 7 May 2026 17:44:56 +0200
Newsgroups gmane.mail.mutt.devel
Message-ID <afywvo2RkxD-akRg@devuan>
Hi Derek,

On 2026-05-07T11:21:35-0400, Derek Martin wrote:
> > Also please match the formatting style used in Mutt, i.e. Allman curly brace
> > style, being free to omit the braces for single lines if you like.
> 
> Due to past experience, I don't do this unless the conditional statement fits
> comfortably on the same line as the conditional.  It tends to lead to
> bugs where someone expands what is done conditionally (or tries), but
> they forget to add the braces, leading to a hard-to-see logic error.

This is not a real problem, and has not been a real problem for many
years (if not decades).  -Wmisleading-indentation exists since GCC 6
(released in 2015), and is part of -Wall, and it precludes the
possibility of such logic errors.

	alx@devuan:~/tmp$ cat braces.c 
	#include <stdio.h>

	int
	main(void)
	{
		if (1)
			puts("foo");
			puts("bar");
	}
	alx@devuan:~/tmp$ gcc -Wall braces.c 
	braces.c: In function ‘main’:
	braces.c:6:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
	    6 |         if (1)
	      |         ^~
	braces.c:8:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
	    8 |                 puts("bar");
	      |                 ^~~~
	alx@devuan:~/tmp$ clang -Wall braces.c 
	braces.c:8:3: warning: misleading indentation; statement is not
	      part of the previous 'if' [-Wmisleading-indentation]
	    8 |                 puts("bar");
	      |                 ^
	braces.c:6:2: note: previous statement is here
	    6 |         if (1)
	      |         ^
	1 warning generated.

That is, the famous Apple bug[1] (discovered in 2012) was because these
compiler diagnostics weren't available yet.  It's pretty much impossible
to repeat such a bug accidentally today.  Tools have improved vastly.

You should optimize for readability, and leave safety to compilers.


[1]:  <https://dwheeler.com/essays/apple-goto-fail.html>


Cheers,
Alex

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmn8s3IACgkQ64mZXMKQ
wqnffQ/9ECBNVrE0LqVVkG7ThAL2QPmk6PdgnIKrP5oNLNT/EFRtWIiSpj5lmLzA
GoyPQJghb8+cllECpgrzFCPpPoltzL6Kj+jII7EzWEMgqjeUcbxqwjOa5hgPjGiH
E/WDDQgAcdva119ggFHNO4/wKUTKmSD8z7CSZREP6C+BhIm8F4wLFWMf+vKmJqlO
1fdLfmd842terGb2otEIhHdyvy9WCkU9iljUVtdSDLZUcgjlBzr7a7Xh5OHIn8eY
kz6amADpnb3vgneBPtgBkscciTqeWq7vFwujOQMW4YgpajOLYphQOLonXKsKMUAC
WOuxDX8LPKhedd26gVH06u0JW45ueG+cE5VsOfD4vCB8w/chOieQdlniRpxjiO8e
u1Mx2sLy6KdZumMONXELmmqva2S/W0oBJs2bQpC+YKNARUGpF6ivG+AC1i4+C1CT
GubXkGDeg0w0mau+mo/XjcHj02WgGVUXwvxQHdcROha9t8I/yi6rGTIP71AJAq5o
Bxi+7fJ42kU2kmKozdyUBu0GvkV2HrKt13c8HnA3uqsaDDe6weDVHNo1d2RLeAWL
FtCxokWL4Y9IWgYrT/0kp3XAsRZqrwSFhaT4MqF1dnmtRlb9QP2QbBbVHCvqCWU7
4+PxVb+l61YNn/jfebYbCoXCDo2+I9YBnNJ/mVsICZutaEdNz8g=
=TWLc
-----END PGP SIGNATURE-----