by Matt3o12_ · 8y ago · 0 comments
if (!access_ok(VERIFY_WRITE, infop, sizeof(*infop)))
goto Efault;
Why doesn’t the if use curly brackets? I thought it has been established that it is best practices to always use curly brackets even if they are explicit, especially after Apple's infamous goto bug[1].Secondly, why does it use goto at all? I thought it has also been established not to use goto unless it is the only performant solution (and performance is important in that case). Sure Efault with probably kill the program but wouldn’t it still be better to use a function call considering that the desired resolution should be the same?
[1]: https://www.imperialviolet.org/2014/02/22/applebug.html
> Do not unnecessarily use braces where a single statement will do.
2. There is no built-in exception handling in C. `goto ERROR_HANDLING_CODE` is a common and well established pattern to handle exceptions in C, see e.g. [2].
[1] https://www.kernel.org/doc/html/v4.10/process/coding-style.h... [2] https://news.ycombinator.com/item?id=3883310
“Established” by whom? Certainly not by kernel developers — `goto` is very common in all kernels I have looked at (xnu, Linux, bsd)
By the way, gcc now has -Wmisleading-indentation, which is activated by default if you enable -Wall: https://news.ycombinator.com/item?id=10875449
https://www.kernel.org/doc/html/v4.10/process/coding-style.h...
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...