- 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
ClueBat™ is insufficient for this scenario; more… drastic measures are required…
Admin
something like this?
[image]Admin
I'm so disappointed, I read that as Megatron Hammer at first.
Admin
Or one of these: [image]
Admin
Remind me how many write operations are supported by the SSD, please ?
And how many sectors it has still free ?
With the naughty flush, it is is honored, there is to be such number of rewritten sectors so that the drive will be dead sooner than expected.
Admin
no, that's a megatron blaster
[image]Admin
Yo Dawg, I heard you liked writes, so I put a write in your write...
Admin
No, this is clearly a case of brillance because as everyone knows, RAM is slower than hard drives
Filed Under: :trolleybus:
Admin
Not… the clue cactus?
Admin
TRWTF is the use of the word 'parser'
Parsers parse XML they don't write it.
#pedantic.
Admin
I can soooooo relate to this. I fixed some code that did something like this writing CSV files: two opens per field, one for the data, one for the delimiter. It didn't close or explicitly flush, though, except at the end of the row.
Admin
At first, I was wondering WTF this comment meant. What does "essentially" mean? It's either a linked list or it isn't. Then I looked at the code some more. Apparently, an
xml_t
can only have one child node. If a node has a second child node, it's represented bypSibling
. For more than two child nodes, each one is thepSibling
of the previous child node.Searching Google for "xml_t" has this article as the third result, so I'm assuming that it's a homemade class/struct. It seems kinda screwy to me, but then again, I prefer languages with built-in list types.
Admin
Interestingly, though, despite all that nonsense, the code appears to work... horribly inefficiently, but it generates real XML as far as I can tell. One actual bug that stands out is that it passes
bNew
in the recursive call toxmlwrite_file
instead of0
which could potentially mean it overwrites all the data it's written so far and starts a new file... but that only comes up if the root node has a next-sibling, which should never happen in a real XML document.Only other thing is that the nodevalue isn't escaped (unless the escaping logic is in the
FillNodeValue
function, which isn't given), which would be my first guess as to what's causing the problem. My second guess would be a bug somewhere inFillNodeAttribs
(or possiblyFillNodeName
/FillNodeValue
), which we don't see here.Of course, whether or not it's worth tracking down the actual bug rather than dusting off and nuking it from orbit is a different question...
Admin
Good buttumption. .
Admin
I'm "anonymous" in the submission. Yeah, you're right about the parser terminology but this thing was ALSO a parser though. It did everything you could need to do with xml... just very, very poorly.
For reference, the bug I tracked down was that when removing nodes from the xml struct, it didn't actually remove them, it moved pointers around. While this sort of worked, it ended up causing issues when writing out because the nodes still existed and still could be accessed under certain conditions.
Oh and this thing likes to write out XML that looks like this:
which of course isn't valid XML sigh
Admin
I'd wager that these writes will probably get cached and coalesced by the OS. You'll still pay the performance cost of a bazillion syscalls, but I don't think it's going to be a bazillion real I/O operations on the disk.
The flush itself does nothing, since the
fclose()
would have done the flushing anyways. On other hand, had the incompetent developer known aboutfsync(2)
, then we could be sure that each individual write operation would be hitting the disk and waiting for that to complete (assuming, of course, that the disk controller isn't lying to the OS that the writes have hit durable storage instead of its on-board cache, as some disk controllers are wont to do).Admin
TRWTF is PH... oh wait! It's C!
See? You can do stupid shit in any language.
Now, I'm going to play devils advocate here, but maybe, just maybe, whoever wrote this didn't intended this behavior. I mean, this guy clearly knew what he was doing, he has some recursion, some malloc, some fflush and the thing works with some quirks, but hey, it's C, it probably doesn't even have unit tests.
Admin
You had me at "homegrown Xml parser". In C, no less!
Admin
http://www.huffingtonpost.com/2012/07/16/jonah-falcon-largest-penis-frisked-by-tsa_n_1675767.html