| « Prev | Page 1 | Page 2 | Next » |
|
With that last example you realise that syntax highlighting in code editors us such a blessing.
|
|
The first one is stupid, the second one looks like it stems from a misunderstanding of how C handles strings, and the third looks like it's a server-side script where you can just change the comment markers to change the response of the web server. Of course, it would be clearer to just put // at the beginning of two of the lines.
|
|
That last one is centainly one of the most confusing ways to do commenting...
|
Re: Strings in Hiding
2007-04-19 09:24
•
by
Rafael Larios
(unregistered)
|
|
I'm getting tired of reading: this is just stupid is not a WTF!!!
Well for me the first example is a big WTF, a little more of WTFness and the example could go to college, graduate, work in finnancial institutions, marry and have children by means of copulating with female WTFs. |
|
I think the first one was actually attempting to make each item point to a seperate instance of "\nDEFAULT", and went about it in quite a bizarre way.
|
|
/* First! /*
The real WTF*//*is the forum software. */ I personally like those small SoD, /*/* Where is the wooden*//*/*table?*/keep them coming. /* They need FILE_NOT_FOUND Captcha: tastey */ |
Re: Strings in Hiding
2007-04-19 09:56
•
by
Stilgar
(unregistered)
|
|
if true what is the point?
what is more = new String("\nDEFAULT"); would have accomplished that... I think |
Why do you say first when the first post was an hour before you? |
|
The WTF is that in polish "dupa" (as in strdupa()) means "ASS".
|
Re: Strings in Hiding
2007-04-19 10:15
•
by
muhahaha
(unregistered)
|
That 'First!' was commented out. Can't you read?!? |
psh! everyone knows it should be this:
ignorant fools! |
Re: Strings in Hiding
2007-04-19 10:23
•
by
UnresolvedExternal
(unregistered)
|
or even: buffer[0] ='\0'; prependString(buffer,string) You can take my CAPTCHA from my cold dead hands! |
Re: Strings in Hiding
2007-04-19 10:24
•
by
anne
(unregistered)
|
that was awesome!!! I had to paste it into my emacs window to read it!!! Um, I can imagine a backwards compiler that parsed that wrong, thinking it's a nested comment and like having a stack of /*. but if it happened i'd have to kill myself. |
Re: Strings in Hiding
2007-04-19 10:31
•
by
Gert
(unregistered)
|
|
err, the last line is ridiculous... strcpy already takes care of the ending NUL char... rtfm
and in case it wouldnt, strlen() would not help as strlen also looks for the NUL char (which isnt there, its probably somewhere out of the memory allocated to that variable) and you would overwrite another NUL (pretty damn good change for access violation) |
|
strdupa...
dupa means arse in polish. |
Re: Strings in Hiding
2007-04-19 10:42
•
by
Chris
(unregistered)
|
Hear the "wwwoooshh" sound? That's the other posters joke going right over your head. |
You must be new here. |
|
forgot to quote the comment:
my comment was for this, not the article |
Re: Strings in Hiding
2007-04-19 11:09
•
by
snoofle
(unregistered)
|
|
using Java:
|
Re: Strings in Hiding
2007-04-19 11:10
•
by
Jon Skeet
(unregistered)
|
Er, yes - but it was still posted sarcastically. The poster wasn't trying to suggest it was *actually* appropriate code to use. |
Yes... we know. |
Re: Strings in Hiding
2007-04-19 11:13
•
by
snoofle
(unregistered)
|
|
Damn: gotta start proofreading before posting...
|
|
yeah... he's new here
|
Re: Strings in Hiding
2007-04-19 11:23
•
by
RON
(unregistered)
|
It looks like VB, which is on .NET now, which means that all strings are interned. So any two references to the string "\nDEFAULT", no matter how they were constructed, will point to the same exact string objects in the string store. |
Re: Strings in Hiding
2007-04-19 11:28
•
by
Jon Skeet
(unregistered)
|
I don't believe that VB.NET interns all strings. C# certainly doesn't. For instance: string x = "hello"; string y = "hel"+"lo"; string tmp = "hel"; string z = tmp+"lo"; x and y now refer to the same strings. z refers to a different string. Jon |
|
Bah. If only people used "safe" string functions, there would be no such problems:
Count the WTFs! :D |
I especially like how the coder has used double-quotes, so there are actually two null bytes. Possibly the extra one is for redundancy, in case cosmic radition flips a bit in the first one? Or maybe it's for unicode support! Genius!!!!1 |
Re: Strings in Hiding
2007-04-19 12:02
•
by
AdT
(unregistered)
|
Neither does VB.NET (which uses largely the same libraries after all):
prints
so only the string literals were interned. Sorry for the bad layout, but the WTFish forum software inserts <br/> elements into <pre>-sections. *shudder* |
|
strfry()?
I thought that was only for text manipulation on Chinese web sites. |
|
Strings can cut both ways.
Null terminators perplex; re-write it in Perl. |
Re: Strings in Hiding
2007-04-19 12:17
•
by
john doe
(unregistered)
|
As per yesterday's example this should be:
|
Re: Strings in Hiding
2007-04-19 12:22
•
by
pl2
(unregistered)
|
... and is one of the most popular polish password elements. |
|
Hehe, That's a new one. I've never seen someone try to append the already present null terminator...
|
Re: Strings in Hiding
2007-04-19 13:02
•
by
howdy
(unregistered)
|
You're also assuming the strcpy() function supplies the null terminator. There are many libraries with improper implementations that don't supply it. General rule of thumb in *real* software development is to not trust *any* of the str* functions until the library has been properly vetted (and even then be wary) [and before someone says "use a *real* library/language/...", you must live in La-La Land where you have control over such decisions ... never leave if such is the case]. This is especially true in the embedded world. Now, using strcat to supply the null terminator, that part is bizarre. |
If you read the whole thing, he's aping the WTF memes. |
Talk about ignorant! You forgot to allocate the buffer!
And don't forget to free it when done!
|
|
c-strings < g-strings (and i'm not talking about music...)
|
Re: Strings in Hiding
2007-04-19 13:43
•
by
Scottford
(unregistered)
|
Things are going to get very entertaining around here, real soon now. |
Pleeeeease be joking... strcpy() may be THE single easiest function in C to implement. You simply CANNOT work on a platform where you have to guard against it possibly not working. If you can't trust it, supply your own... period! The other str* functions are trickier, yes, but seriously; broken strcpy()? Really? |
|
On some early systems I did maintence on, some programmers would write:
char buffer[16]; for (i = 0; i < 16; i++) buffer[i] = '\0'; strcpy(buffer, "Some String"); There would be houndreds of example of this idiom in the program. Crash Magnet |
No, I think that strlen is easier. size_t strlen(const char* s)
Not to mention wrong anyway if strcpy doesn't append the null character. Addendum (2007-04-19 17:58): Yes, that strlen is wrong. I'm an idiot. "Thanks" to iMalc for pointing that out. ;-) |
clbuttic :)
6? - Not checking for bounds error properly in first if statement - Failing to return -1 if the for loop has to abort - Copying from in the middle of src instead of the beginning (pro-tip! - dest[i] = src[i-strlen(dest)]; // append the string) \o/ - Buffer overrun on final character assignment - Final character assignment assumes the string ends at the end of the buffer - By the standard of strcat, shouldn't it return return dest not an error code? I suppose if you're being really picky you could complain about "i" being an int instead of size_t. But I have unilaterally decided that's not a wtf, because I'd probably do that do :) |
Re: Strings in Hiding
2007-04-19 14:12
•
by
bathe
(unregistered)
|
You must be relatively new to the art of computer programming if you believe somebody might be joking when they say there are broken implementations of strcpy. The reliability of the libraries has increased significantly in recent years and thus not necessarily be as problematic anymore. Regarding "if you can't trust it, supply your own", this is generally what happens with all str* functions anyway (seemingly more so for those working on embedded systems, where sometimes str* functions may not even exist). Unfortunately, this is also what had initially led to the proliferation of broken str* libraries. |
Re: Strings in Hiding
2007-04-19 14:17
•
by
Firestarter
(unregistered)
|
Use a real language that deals with memory [de]allocation for you! flame-on! |
I was actually more stunned by the implicit suggestion (based on the response to a previous post), that one deal with the possibility of broken str* functions by manually null terminating after each use. That is a vile thought! :) But yes, especially with "optimizations", I suppose I can imagine a broken strcpy(). But the canonical, unoptimized (arguably) K&R versions are small and easy to carry around with you, until you prove the library versions correct. Working with broken C string functions is like trying to write a story without consonants or vowels. |
Use a fake language that deals with memory [de]allocation for you! |
I'm not quite familiar with that language, looks like python to me, but it seems that for the first line, and first line only, it would add what was in sb before the loop, then add "\nDEFAULT" for every other line. It's definately obfuscated though. For instanct, say sb contained "Test". It would hit the while, append "\nDEFAULT" to "Test" making "Test\nDEFAULT" and add that as the first index, then until indexN add just "DEFAULT". Or am I seeing the code wrong? Without seeing the whole program, more specifically what was in sb before this while loop was hit, it would be hard to say. |
Re: Strings in Hiding
2007-04-19 15:25
•
by
SomeCoder
(unregistered)
|
It's VB.NET and yeah, that's what it does. The first time through the loop could be special because sb could have something in it from before. The subsequent times through the loop it just puts "\nDEFAULT" in. However, the user of a StringBuilder there is definitely overkill. |
Re: Strings in Hiding
2007-04-19 15:27
•
by
iMalc
(unregistered)
|
Yes I have definitely worked on a project using a compiler that had a broken strcpy! (no lies). Actually it worked in a few cases, but not when you were copying form a near pointer to a far pointer, or the other way around, despite the library having been written such that this was supposed to work. We made our strcpyNF, strcpyFN, strcpyNN, and strcpyFF and used those instead as they always worked. btw, your strlen is broken. I've never seen anyone use chars 1 thru 10 to terminate a string before. |
| « Prev | Page 1 | Page 2 | Next » |