- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
This was probably (originally) machine-generated code and never meant for human maintenance.
Admin
This one strikes me as fake.
Admin
hmm? all code is meant for human maintenance.
Admin
maybe he read somewhere that he shouldn't use magic numbers... but that 0 and 1 were generally accepted as exceptions to that rule.
Admin
Indenting was added by the editor?
Damn. I can't even imagine the original. I wonder if it was all on one line.
Admin
Admin
Was he trying to draw some ascii art?
Admin
Admin
Make that OHEXOHOHOHOHOHOHTHREETWO, it's more readable.
Admin
aaargh!
Admin
MENTAL NOTE : Dont pay this guy per hour!
Admin
Pay him per character
Admin
W! T! F!!! [:|]
Best one I've seen in a while...
Admin
Uhhhhhhhhhhh.....
Its obvious the author of this excrement piece of code was just being an asshat. The only excuse for writing code like this is to make life for people behind him or her difficult. Must have known a pink slip was coming down the pike when he/she wrote this.
Admin
What movie is that quote from?!?! "...things...terrible things...unspeakable things..." It's driving me insane.
Admin
Even if you take out all of the crazy "0 + 1 + 1 + 1 ..." garbage, I still cannot figure out what this code is supposed to be doing. It looks to me like the overall design here should be called into question.
The other issue here is that this code takes a number that is passed in as an argument and uses it to produce an index for an array and then tries to access the value of that array index without first checking to see if it is out of range.
Out of sheer curiosity about what this code is doing, I refactored it into something more readable. After which, I looked at it and thought, "WTF!"
Here is the refactored version. All comments are obviously my own.
void RstPccoLv(int curIdx)
{
if (sysobjs[curIdx * 10] == 0x1c && sysobjs[curIdx * 9] > -1) // condition must be true for any other code to execute
{
sysobjs[curIdx * 8] = 0;
if (sysobjs[sysobjs[curIdx * 9] * 13] < 0)
sysobjs[sysobjs[curIdx * 9] * 13] += 4;
// the following two sections check the value of a given index of the array
// it looks like they really could be 'if...else if' statements since they appear
// to be mutually exclusive
///////////////////////////////////////////////////////////////////
// First section - when sysobjs[sysobjs[curIdx * 9] * 10] == 0x18
///////////////////////////////////////////////////////////////////
if (sysobjs[sysobjs[curIdx * 9] * 10] == 0x18)
{
sysobjs[sysobjs[curIdx * 9] * 8] = 0;
XPos2 = sysobjs[curIdx * 9];
if (XPos2 + 1 < nbObj)
{
while (sysobjs[(XPos2 + 1) * 10] == 0x18)
{
sysobjs[(XPos2 + 1) * 8] = 0;
XPos2++;
}
}
}
///////////////////////////////////////////////////////////////////
// Second section - when sysobjs[sysobjs[curIdx * 9] * 10] == 0x1b
///////////////////////////////////////////////////////////////////
if (sysobjs[sysobjs[curIdx * 9] * 10] == 0x1b)
{
if ((sysobjs[curIdx * 11] & (1 << 4)) == 0)
sysobjs[curIdx
else
sysobjs[curIdx
}
}
}
Admin
He probably came from my old student job, a data entry clerk getting paid by the keystroke...
I wouldn't say this is machine generated, the variables have (almost) meaningful names.
Also it can't be for compiler optimisation (assuming x86) where INC is faster than ADD in some cases, 'cos he's doing curIdx*8 instead of curIdx<<3.
It's manipulating a linked list of 8-byte (I'm assuming bytes) structures stored in the byte array sysobjs. The index of the next structure linked is stored in (stucture offset)+1 and it's setting the (structure offset)+0 byte to zero depending on the value of some of the others.
My guess goes to low-level microcontroller code... if this is in a high level system, I say WTF?!
Admin
I would say that even if you fixed the obvious top-level WTF, namely the bizarre numeric constants, the code that remained would be no less of a WTF.
That is quite an achievement.
Admin
A quick google search shows it to apparently be from an episode of Babylon 5 titled "Comes the Inquisitor".
More of the quote: "In the pursuit of my holy cause, I... did things, terrible things, unspeakable things. The world condemned me, but it didn't matter because I believed I was right and the world was wrong."
Admin
Ah, I see that limelight is all over that... didn't post fast enough!
Admin
No way this is C code to do optimizations... the computer is still doing work just to calculate what 0+1 is (fruitless since that doesn't do anything).
I'd hate to see how this guy does a NOP.
Admin
one must replace duplicating code with variables, and it is good if name of the variable explains code it replacing. for example:
zeroPlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOne = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
zeroPlusOnePlusOne = 0 + 1 + 1;
zeroPlusOne = 0 + 1;
one = 1;
zero = 0;
if (sysobjs[curIdx * zeroPlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOne + zeroPlusOnePlusOne] == 0x0000004e - 0x00000032)
{
if (sysobjs[curIdx * zeroPlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOne +zeroPlusOne] > -one)
{
sysobjs[curIdx * zeroPlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOne + zero] = zero;
and so on...
Admin
The person in question was Jack the Ripper who had been employed by the Vorlons.
No, seriously.
Admin
I've fallen victim to this code's entrancing addition and forgot to pay attention to the order of operations. So, after posting my own WTF above, let me try this one more time. Here is a quick refactor of the code with operations in parenthesis for clarity. It now becomes clear that the array contains some kind of eight byte long structures as JohnO pointed out above. Perhaps the designer never heard of a class or struct before? It would be much easier to deal with an array of structs than it would be to deal with this mess.
void RstPccoLv(int curIdx)
{
if (sysobjs[(curIdx * 8) + 2] == 0x1c && sysobjs[(curIdx * 8) + 1] > -1) // condition must be true for any other code to execute
{
sysobjs[(curIdx * 8)] = 0;
if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 5] < 0)
sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 5] += (4);
// the following two sections check the value of a given index of the array
// it looks like they really could be 'if...else if' statements since they appear
// to be mutually exclusive
///////////////////////////////////////////////////////////////////
// First section - when sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x18
///////////////////////////////////////////////////////////////////
if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x18)
{
sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 0] = 0;
XPos2 = sysobjs[(curIdx * 8) + 1];
if ((XPos2 + 1) < nbObj)
{
while (sysobjs[((XPos2 + 1) * 8) + 2] == 0x18)
{
sysobjs[(XPos2 + 1) * 8] = 0;
XPos2++;
}
}
}
///////////////////////////////////////////////////////////////////
// Second section - when sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b
///////////////////////////////////////////////////////////////////
if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b)
{
if ((sysobjs[(curIdx * 8) + 3] & (1 << 4)) == 0)
sysobjs[curIdx
else
sysobjs[curIdx
}
}
}
Admin
Interesting that the 1's are in groups of eight. This is just a spelled-out version of octal notation.
Admin
Of course!!
It's Binary math.
Admin
Obviously this coder has got advance warning of a sneaky plot by those sickos at ANSI to change the default number base for C and C++ from denary to ternary, so he's future-proofing his code. We can mock now, but when every single number in every single line of source code has to be rewritten to conform to the new spec just in order to compile, he'll have the last laugh...
Admin
<FONT face="Courier New" size=2>if this is straight up C, then danger will robinson. but in C++, you can overload the operators, right? maybe they were thinking spelled out bitmasks were easier to understand. of course, why they'd do that and then throw hex values in there seems odd.</FONT>
<FONT face="Courier New" size=2>conclusion: this is a more quiet and shy jed.</FONT>
Admin
There is good Jed and evil Jed. This is Evil Jed.
Admin
My eyes! They bleed!
Admin
They got a monkey to hit a keyboard at random right ? No one with 2 live brain cells will write cr*p like this !
Admin
Wow, what a nice piece of maintainable code! I wonder what they do when they need to add a new field to that 8 byte "structure". That, and RstPccoLv... I mean, WTF is Rest Picco Lev stand for?
Admin
It all makes sense now! I now understand how managers are created, because if this guy had been promoted to management he'd be too busy playing golf to have time to write code...... any code.
Admin
What, a meta-WTF?
Admin
He put creatures in our bodies... made us... do things... terrible things...
Admin
http://www.imdb.com/title/tt0084726/
Admin
This code isn't so bad -- you guy just don't understand the brillance of sysobjs.
Admin
The code is from a J2ME project. While J2ME forces you to do some nasty, ugly, horribly un-Java things to save on jar size, this went above and beyond anything that I or my workmates have ever done.
Admin
You forgot:
zeroXZeroZeroZeroZeroZeroZeroFourE = 0x0000004e
zeroXZeroZeroZeroZeroZeroZeroThirtyTwo = 0x00000032
Because there should be no bias.
Admin
This guy is a pure genius. I am very impressed with that code, it would take a genius to concoct such a thing and make it work.
Only problem is that he is the evil kind of genius :)
Admin
Don’t you think this was run through some sort of obfuscator utility? I doubt he actually wrote that himself.
Admin
Yeah, generated by a machine that can't add.
Admin
Remove the indenting, and you might see Satan pissing on the world.
Admin
Okay, I'm going to try to refactor at least a little bit.. using advanced features like "functions". It looks like sysobjs is an 8
// returns sysobjs[idx1][idx2], without bounds checking.
int getSysObj(int idx1, int idx2)
{
return sysobjs[idx1*8 + idx2];
}
// sets sysobjs[idx1][idx2] to newval, without bounds checking.
void setSysObj(int idx1, int idx2, int newval)
{
sysobjs[idx1*8 + idx2] = newval;
}
void RstPccoLv(int curIdx)
{
if (getSysObj(curIdx, 2) == 0x1c && getSysObj(curIdx, 1) > -1) // condition must be true for any other code to execute
{
setSysObj(curIdx, 0, 0);
if (getSysObj(getSysObj(curIdx, 1), 5) < 0)
setSysObj(getSysObj(curIdx, 1), 5, getSysObj(getSysObj(curIdx, 1), 5) + 4); // I know.. this is ugly..
// the following two sections check the value of a given index of the array
// it looks like they really could be 'if...else if' statements since they appear
// to be mutually exclusive
///////////////////////////////////////////////////////////////////
// First section - when sysobjs[sysobjs[curIdx][1]][2] == 0x18
///////////////////////////////////////////////////////////////////
if (getSysObj(getSysObj(curIdx, 1), 2) == 0x18)
{
setSysObj(getSysObj(curIdx, 1), 0, 0);
XPos2 = getSysObj(curIdx, 1);
if ((XPos2 + 1) < nbObj)
{
while (getSysObj(XPos2 + 1, 2) == 0x18)
{
setSysObj(XPos2 + 1, 0, 0);
XPos2++;
}
}
}
///////////////////////////////////////////////////////////////////
// Second section - when sysobjs[sysobjs[curIdx][1]][2] == 0x1b
///////////////////////////////////////////////////////////////////
if (getSysObj(getSysObj(curIdx, 1), 2) == 0x1b)
{
if ((getSysObj(curIdx, 3) & (1 << 4)) == 0)
setSysObj(curIdx, 0, 0);
else
setSysObj(curIdx, 0, 1);
}
}
}
There. If anyone wants to clean that up, go ahead. I am at work and have spent 15 minutes on this and really shouldn't spend any more... or my boss will be saying "WTF" :)
Also, there's a good chance I've made some typos and/or that that this will not compile...
Admin
The movie line that came to me when reading the code was:
All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy.
Admin
The *compiler* is doing work to calculate 0+1. Only the most brain-dead compiler for any language would actually write out those additions.
Only when a user-defined type is involved. 0 and 1 both have type int, and you can't override operator+(int, int).
Admin
<FONT face="Courier New" size=2>your machine is an accumulator with only two instructions:</FONT>
<FONT face="Courier New" size=2>and(b) : takes the value in the accumulator and performs </FONT><FONT face="Courier New" size=2>an 'and' (&) on the bit b. ex. '5' and(1) leaves '4' in the register.</FONT>
<FONT face="Courier New" size=2>clear : takes the value in the accumulator and clears it.</FONT>
<FONT face="Courier New" size=2>takeshi_kagav("allez cuisine!") ;</FONT>
<FONT face="Courier New" size=2></FONT>
Admin
Sun javac will.
Admin
I'm willing to be that this is C++ with operator overloading for the indexing operator.
They are using some sort of bit twiddling with the index in the operator, and wanted to have an explicit way to see the bit fields.
Admin
While your machine is interestingly similar to brainfuck, I don't think it's quite the same type of stupid as the stupid machine to which dubwai alludes.
What method of bit-numbering leads to '5' and(1) == '4', anyway? The sanest choices would be 1-based octal or 0-based hex, which should give you some idea just how little sanity there is to be had here.