- 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
Scary. Just scary.
Captcha: doom
HA!
Admin
So this is broken-register syndrome? If it fails the first time, do it a few more times to make sure it really takes?
Admin
C has a lot of potential for bad code, but logging to stderr that it failed to log on stderr is really creative.
Admin
My brain hurts.
Admin
I found the problem! the commenter used the wrong form of its. The one written there is the possessive, not the contraction for it is. I'll have to be careful in my comments from now on so I don't end up on this website.
Captcha: burned.
Admin
Oh, I see! It should have been:
That's much cleaner...
Admin
This code is so naff, but my favourite is the belief that fprintf returns less than zero on error. fprintf returns the number of characters printed - on failure it sets errno.
captcha: I'm not telling you
Admin
This could be worse. The system I'm testing atm used to log any kind of errors to the windows eventlog. Even if the error is that it doesn't have the rights to write to the windows eventlog....
I've never seen logfiles (the redundant log-method) being written that fast :)
Admin
This was repeated in every single place where an error occurred. It could have been done once in a common block of error handling code. <Sigh/>
Admin
I think you are confusing 'error' with 'errno'.
Admin
No, no. You want to spawn a thread on each pass of the loop - what else are all these SMP and multicore machines for?
Admin
Not to mention printing a stacktrace from the original exception and calling System.exit(1); rather than forcing a divide by zero.
Admin
I don't see where it logs "File Not Found"
Admin
Well, it's kind of a mixed bag. If it was running as a daemon, simply printing a stack trace wouldn't work as stdout/error would have been closed, thus leaving no place for the trace to be printed. However, the way they attempted to handle it in those cases was admittedly inept.
Admin
Captcha: Wigwam. basically the same shape as a pyramid, but easier built. :)
Admin
Then why does the NetBSD manpage on fprintf contain this:
Admin
You're right! My code is horribly inefficient. Let's fix it:
That's much better. But maybe we should add a sleep statement in there, because any error with stderr is bound to be fixed in, say, 30 seconds:
Admin
The REAL WTF is ...
everyone: ASL???
Paula, No Quack! VB Wooden Table
Step 1: Underwear Step 2: Step 3: Profit!
captcha: wigwam
Admin
Ahem... (Ok, I am intermixing C and Java here, but still):
Admin
If the log file is not found, how can you expect to see it?
Admin
You might what?
Admin
Sorry, is that an actual term? I can't find it anywhere, but it sounds interesting.
Admin
If at first you don't succeed....failure is probably your style. http://www.despair.com/los24x30prin.html
Admin
captcha: xevious i hated that game
Admin
The real WTF is that he hasn't got any newline characters in what gets printed!
Admin
Admin
That's no longer a pyramid! It can't work!
Admin
... and returns a negative number. (see man fprintf)
john
Admin
I guess that the really real WTF is that I still don't understand why people try to catch some real WTF in what is obviously a really real WTF. To me, such a behavior is really a really real WTF, not just a real Really Worse Than Failure.
I'm not sure I'm clear.
Admin
The potential for such a crock is there in any language, really.
Admin
The solution is to put it like this:
/* log("file not found"); */
Should work well (without producing any error).
Admin
Is this an example of recursive error logging???
Admin
I am reading the Linux man page of fprintf(). It says: Upon successful return, these functions return the number of characters printed. If an output error is encountered, a negative value is returned.
What happpens if it is possible the write the first half, but there is an error with the second half, is undefined.
Admin
It's a hacker joke - the author of code that repeatedly does something stupid pretends that it's trying to avoid a "broken register" in the CPU, hence the multiple executions. It's probably in the Hacker's Dictionary / Jargon File unless that numbnuts Eric Raymond has changed it to something about how great guns are.
Admin
Kind of like locking your keys INSIDE to keep them safe.
Admin
At least he optimized the loop!
Admin
Admin
should definitely work well but we have to think of the gas machines from the steel factory
Admin
This is not true. If the printf() family of functions has internal errors, then they return a negative value. Sometimes, they print less than the intended amount, and the return value is the truncated number of characters.
In any case, the system has crashed when stderr stream is not available.
Admin
As soon as I saw this I said "Worse Than Failure!!!". Oh, no, I guess not - I probably said "What the F***".
Admin
Yeah, except that it's not a joke. One chip in the one of HW platforms I've worked on had a bug where writes to a particular register would fail somewhere between 1% and 10% of the time, completely at random. The failure to set this register correctly wasn't awful, but a temporary loss of functionality.
What made it worse was that it was a register that we wrote to to invoke some processing on the chip, and the first thing the chip would do would be to clear the register, so we couldn't read it back. Fortunately, writing the register multiple times was completely safe, so we worked around it by writing six times in a row.
The explanation for this behavior was very well commented.
Admin
I'm not sure what language you're using, but in C fprintf returns a negative value if an output or encoding error occurred (ANSI ISO IEC 9899-1999 7.19.6.1 paragraph 14
Admin
The "guru" must really want to make sure it failed. The C libs really leave room for obfuscation.
Admin
if (error) if (fprintf(stderr,"All work and no play makes Jack a dull boy")<0){ if (fprintf(stderr,"all Work And No Play Makes jack A Dull Boy")<0){ if (fprintf(stderr,"All work")<0 && fprintf(stderr,"no Play Makes jack A Dull Boy")<0){ if (fprintf(stderr,"All work")<0 && !fprintf(stderr,"Play Makes jack A Dull Boy")<0){ return fprintf(stderr, "An error occured while writing to stderr"); /* lets stop here, its enough */ } } } }
Admin
In fact, I'm not even sure if just checking errno is valid. I'm under the impression that if a function succeeds what it does to errno is undefined, so you can't rely on it being a specific value when it comes out. It could set errno when it succeeds in other words.
Ignoring practical concerns about if this would ever happen in real code (I'm an academic ;-)), am I right about this? It's been a while.
Admin
I call BS. This kind of monstrosity could only have been created in VB, because all C/C++/C# developers write amazingly tight, readable & otherwise immaculate code. :p
Jeff
Admin
Admin
This code truly is enlightened! The output of fprintf(stderr,"An error occured while writing to stderr") is 42.
Admin
Actually, a negative value must be returned if there is an output or encoding error. The only way you'd get zero returned is if your input string actually specified no characters, eg. fprintf(fp, "%s", "");
(Otherwise the system does not conform to the C standard).
Also, whether or not errno is set is up to the individual system, you certainly should not write code that relies on it to detect success or failure.
Admin
At least the code was well indented, well commented and easy to read!:-)