Live data from Hacker News

Goto fail

opensource.apple.com

11–20 of 32 posts

Re: Goto fail

#11
What is the point of this post?

In the C programming language, "goto fail" is a perfectly acceptable means of (function local) error handling because of the absence of any kind of exceptions (setjmp doesn't count). Just look at any significant C program, and you'll see that this is used a lot. The alternative for "goto fail" is duplicating the clean up code for each and every error condition that happens in the function.

Blindly following advice like "goto is bad" and applying it everywhere is a bad idea. You should try to understand the reasoning behind it.

You should not use goto for control flow if possible, but it's not bad practice to use "goto fail" for cleaning up on error conditions.

Re: Goto fail

#14
post #8

If you missed it the 35th and 36th occurance of goto fail that really does go directly to fail. if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail; Compulsory bracing of blocks following if/while etc is a piece of syntax Perl got 100% right. Python also got it right in a different way with whitespace. C and C++ really don't have an excuse for not MANDATING compiler warnings at a minimu…

> If you missed it the 35th and 36th occurance of goto fail that really does go directly to fail

Whoa, that was entirely unclear from the submission that this was the point. But then, I guess I still don't see what is the point. Why post this here and not file a bug or something?

Re: Goto fail

#17
post #8

If you missed it the 35th and 36th occurance of goto fail that really does go directly to fail. if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail; Compulsory bracing of blocks following if/while etc is a piece of syntax Perl got 100% right. Python also got it right in a different way with whitespace. C and C++ really don't have an excuse for not MANDATING compiler warnings at a minimu…

> If you missed it the 35th and 36th occurance of goto fail that really does go directly to fail.

Yes, I and many others seem to have missed it. That is a legitimate bug.

I think the post title should highlight this issue. Now it seems like it's just a "goto is bad but apple uses it anyway" post without much point.

Re: Goto fail

#20
post #14
post #8

If you missed it the 35th and 36th occurance of goto fail that really does go directly to fail. if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail; Compulsory bracing of blocks following if/while etc is a piece of syntax Perl got 100% right. Python also got it right in a different way with whitespace. C and C++ really don't have an excuse for not MANDATING compiler warnings at a minimu…

> If you missed it the 35th and 36th occurance of goto fail that really does go directly to fail Whoa, that was entirely unclear from the submission that this was the point. But then, I guess I still don't see what is the point. Why post this here and not file a bug or something?

Not obvious is it. It's only ssl so it's not like it's important. The non-obviousness of it and the spectacularness of the goto fail is, well, in my view, the whole point. C should not still suck this bad. One line un-braced blocks are a standard bug. Why no fixy? Why? What do we have to do?
Post reply on HN