Banishment of goto

Coding practices are not always as robust as they should be. In 2014, a piece of Apple’s OpenSSL code contained an issue with a single spurious goto statement. This was not so much an error with goto, but rather a failure to (i) check the code through and remove the duplicate goto, and (ii) failure to use a compound statement. 

if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
    goto fail;
    goto fail;

Despite the indentation, (this isn’t Python) if the if statement is false, the second goto is always executed thus skipping a load of checks and compromising SSL encryption. The real problem though is the proliferate use of goto statements in Apple’s code base, long considered bad programming practice. So, Apple may have solved the problem by introducing Swift. So far they have not added a goto statement to the language – it has been banished. Let’s hope it stays that way. It is not the first to banish goto, Python doesn’t have a goto, neither does Modula-2 or PL/I.

BLISS was designed without goto, introducing instead a cornucopia of exit statements in the  first version, also eliminating labels. BLISS excluded goto for two reasons: (i) the runtime support needed by unrestricted goto’s, and (ii) the authors feeling that the general goto, because of the “implied violation of program structure”, is a “major villain” in programs. BLISS-11 fixed this by providing an exit by means of a LEAVE statement, which  provided a restricted form of forward branch.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s