- 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
if (!comment) return fist;
Admin
Admin
Admin
I bet whoever wrote the "do I exist" C++ class defense noticed that that was checked after "new <whateverclass>" every time, so he figured hey, I can put this code in one place and stop duplicating it! Either that, or it's from some abomination of a mixed-language application and the class is used through some strange wrapper from another language and might not be trusted to actually set the "this" pointer while calling. Either way, WTF?
Admin
"of" has been deprecated
Admin
The logic here all hinges on what is returned for what state by confirm(message). The comment says "If confirmed then return false", but then they return false for ! confirmation. I imagine the comment was supposed to say: // If not confirmed then return false to stop form submit
So instead of: var confirmed = Custom_Confirm(messageToConfirm);
...how about this? var confirmed = confirm(messageToConfirm);
Admin
Admin
Gives the optimizer something to work with, making the runtime more efficient.
(And is it just me, or has this site become a lot more boring since TopCod3r went silent?)
Admin
That is wrong on so many levels. It should be used as an example in programming classes. I count at least three redundant/useless operations and another three things you shouldn't do because there are more efficient ways. And i'm probably missing some more. I just hope there were a lot of blind mass refactorings involved in the creation of this statement.
Admin
An Example from a well-known UI class library:
Admin
FTFY
Admin
I'm not convinced that "if(!this)" is a WTF. For a nonvirtual function, most compilers would probably be happy to produce code that called the function through a null pointer. (This is probably undefined behavior at runtime, but by far the most common actual behavior must be to attempt to execute the function body with this being null).
On the other hand, silently returning false as a defensive action is a lot more questionable. That just exchanges a segfault-and-core-dump here and now with wrong results further down the road that could be a lot harder to debug.
Perhaps the product of faulty metrics, such as "the programmer in whose code the segfault occurred is to be blamed for the bug"?
Admin
The C++ one is obviously some kind of attempt to defend against dereferencing NULL pointers. It fails miserably under the following conditions:
The reason is that in order to get a pointer to B from a pointer to C, you have to add a constant offset (8 bytes on a 32-bit system), so when pc->nullprotect() is called, this is (B*)0x8.
If nullprotect were virtual, the compiler would actually generate a tiny "thunk" function that adds a constant value to this and jumps to the original function.
Admin
It's like running across those branches that begin with a comment saying "this should never happen"
Admin
This was obviously written by a woman. When they say yes it means no and when they say no it means yes. At least that's what I told the judge.
Admin
Then again...
Judge: Guilty?
Male jurors: No.
Female jurors: Yes.
So, you're fine.
Admin
if (!this) return false;
It's perfectly legitimate because it's entirely possible to cast NULL to an object and use it to call non-virtual functions. Not smart or safe, but you'll see it throughout MS code.
E.g.
HDC hdc = ((CDC *)NULL)->GetSafeHdc();
Yet another gotcha of C++...
Admin
The Real WTF is caring whether code works in IE6 or not. Bet it doesn't work in Lynx, SlipKnot, or Netscape 3 either.
Admin
Some people simply forget that member functions of classes are nothing else then normal class-less functions with a hidden parameter (this).
Admin
Well, unless of course you expect 29654 as the answer, which the OP doesn't say isn't the case...
Admin
The real WTF is Java's boxing model!
Admin
IE6 still accounts for 15% of the traffic to the site I operate at my day job. Do you think management would be happy if sales were to drop by 15%?
Admin
Mine's bigger
Boolean[] values = new Boolean[new Boolean(Boolean.TRUE), new Boolean(Boolean.FALSE)]
Admin
More peculiar was that when I pointed it out to the others in the class -- all alleged security pros -- the most common response was "what version should it be?"
Admin
Admin
I wouldn't depend on the (!this) stuff since the standard specifically states that the behavior is undefined. You can invoke a static function from a null pointer, but that is it.
Admin
I would say "bad troll" but we all bit, so maybe it wasn't such a bad troll after all.
Admin
Admin
The real WTF is that someone thinks that "!this" is a WTF in C++. Please do us a favor and stay far away from C++ until you learn what you are doing.
Bjarne Stroustrup uses "if (this==0)" twice on page 605 of "Programming: Principles and Practice using C++". It isn't needed in every method, but it isn't automatically a WTF.
Admin
[quote user="Jamie"] [quote user="Blob"] [quote user="Jerry"] Josh's predecessor seemed to miss out on the fundamentals the request/response paradigm.[/quote] ... while Josh, in turn, missed out on the fundamentals the English grammar.[/quote] "of" has been depreciated [/quote] FTFY [/quote] No, you didn't.
Admin
Admin
Admin
The Real WTF are sites which rely on JS (or Flash, Java, ...) for basic functionality.
Admin
Now, if you didn't have that branch, the program would still happily continue with wrong values.
Admin
Sorry... I guess you had to be here yesterday.... I was just running the script provided by "Language Nazi"
Admin
Admin
Admin
Admin
Admin
I don't get the String.format() one.
Admin
Someone explain to me the javascript one. Is the WTF that the comment and the if (!confirmed) don't match? I'm going crazy trying to see what is wrong with this (maybe just because it is Friday...)
Admin
I mean, other than the fact that there is a lot of unnecessary code (assuming that the comment is incorrect, but the code is right...)
Sorry for the double-post, can't edit since I am not registered...
Admin
Admin
if(!this) { throw new NullPointerException(); }
Admin
Admin
The whole function is an unnecessary wrapper around
var confirmation = confirm(message);
It doesn't add anything beyond that one line.
Admin
Admin
We did something similar to this back in our Windows 3.1 programming days. But it was
assert(this);
at the top of every method. We were using the Borland compiler.
The problem was that you could call non virtual methods without a valid "this" pointer (because those methods weren't put into the virtual table) and we would end up with segfaults or other assertions farther down in the code.
Not all class methods touched the "this" pointer, but we wanted to assert() the failure sooner rather than later.
Moving the assert(this) higher up in the stack showed the developer immediately that he was dealing with a null pointer. Not that he shouldn't have been asserting his pointer earlier.. but in win16 programming we believed in belts AND suspenders!
And yes, it doesn't work for virtual functions in subclasses. But virtual functions weren't what we were trying to protect! Ideally you should segfault when the compiler indexes into the bad virtual table pointer. (And then often bring down your Windows 3.1 with it!)
Admin
It's like, Why do we waste money hiring police? After all, people SHOULD never break the law.
Admin
The whole
thing actually does make sense. Something like would make more sense, but the rationale for it is fairly simple. Let's say you have some badly written code like this: The return value of 'getSomeInstance' isn't checked, so it could return NULL. Instead of segfaulting on the badFunctionCall() it will just hit an assertion failure in the case that you have an assertion on the 'this' pointer, because 'this' would be NULL. It's even' better if you have a custom assertion function that prints debugging info, because you can easily figure out where you made a mistake in your program.