I’ve been going through a lot of the 3 million lines of Anarchy Online code the past months, and seen several bits that make me, as a programmer, laugh. These are completely unfunny for non-programmers, of course. And they aren’t representative for most of the AO code, because that runs pretty well these days.
Here’s a good one, from the just-in-case department:
return this?m_nValue:0;
Found the same one in the Miranda MSN plugin. Note the informative comment.
if ( this == NULL ) // :) return 0;
Then there’s the gratuituos memory leak (props to André who showed me this one today):
void foo(const char * s, int v, std::map& amap) { char * p = strcpy(malloc(sizeof(s)+1), s); amap[p] = x; }
Here’s a redundancy that I wasn’t certain about, but I checked the standard, delete NULL is allowed:
if (p) delete p;
My favourite though:
void foo(int i) { char b[11]; sprintf(b, "%d", i); ... }
This bombed. Signed integers require 12 chars to represent, including the trailing space. But that’s not the funny part. The funny part is that I checked who did it, and it turns out the previous person that touched the code must have found a similar error. The diff he comitted was this:
- char b[10]; + char b[11];
How long should we wait?
WaitForSingleObject( MyThread_c::GetInstance()->m_hThread, INFINITE ); // wait max 2 seconds
Like I said, none of this is funny if you’re not a programmer. And I probably forgot some of the better ones. So, have you got any code stories of your own?