Reply to post: reformat, compile, and write three test cases first

Linus Torvalds fires off angry 'compiler-masturbation' rant

Anonymous Coward
Anonymous Coward

reformat, compile, and write three test cases first

First of all * has lower precedence than -> so it will mercifully not even compile without parentheses around the second *s.

There are three routes to exit_init. Instead of reserving all the goto statements for failure cases and only dropping through for success, confusion is assured by executing the second goto when both allocations succeed, but disguising it as another failure case by returning whatever errno happens to contain. In the drop-through case it has failed to allocate, but returns zero suggesting success rather than an actual error number.

There is no test coverage for any of the three routes. Nevertheless, it does appear either to allocate correctly, or fail without leaking. Until one day someone will notice an unexpected return value, decide to go ahead and fix it without writing and running any tests, add a supposedly missing exclamation mark to the second test, and thereby manage to break two out of the three previously working exit cases, including the all important success case.

[Anonymous to save me having to turn down a flood of job offers to work with such fine C code, or in case my analysis is not quite correct.]

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon