Dax

Phantom STL String Crashes

May 26th, 2006 · No Comments

strangely-arousing.jpgBeing a programmer is a lot like being House MD in that hot ladies are on your jock all the time. Also sitting in a chair all day causes Chronic Pain in your back or legs.

Here’s something else that’s a pain in your programming ass: phantom crashes that make no sense.

Phantom crashes are when a program crashes in the middle of nowhere and is reproduceable in absolutely no way — especially not on the programmer’s computer. Usually the best thing to do in this situation is to blame the user for some reason. Perhaps they installed some spyware or got a virus. Perhaps they merely think they did! Either way it isn’t true and didn’t cause the problem. The problem is that you overwrote some buffers somewhere and that’s the worst problem there is. It’s like someone pissed in your swimming pool and you have to clean it up without draining it because you’re having a hot hot party in two hours! Let me explain.

“Overwritting a buffer”, which is pretty much the only reason for a phantom crash, is like coloring in a picture of a unicorn or a tomatoe patch and not staying in the lines. Lets say you smeared a bunch of red crayon all over the tomatoe patch because you were watching TV or you’re 6 or something. The crash comes when you try to color the sky blue only to find out that there are streaks of tomatoe coloring all the fuck over the place.

“How the fuck am I supposed to color the sky blue now?” You say. A computer, however, says:

“Segmentation Fault all up in this bitch! Memory cannot be read at 0×0000000c! Hope you saved even though I know you didn’t because I’m the friggin computer and know for a fact the last time you saved was 3 hours ago. FAIL!”

Awesome.

The string class of STL (Standard Template Library) doesn’t make a copy of itself when you set it equal to another string. I thought it would, but it doesn’t. Copying an STL string (at least on Windows) only copies the pointer.

If your STL strings are turning into a bunch of shit that looks like Y’s in the debugger, you probably thought you were copying a string somewhere; in fact you are not. The Y’s are the big blue sky coming along and asking why there’s a bunch of tomatoe shit all over the place (AKA copied string pointers that have gone out of scope in another thread).

Go put a .c_str() after all your strings if you’re trying to copy their data to another one AND USE IT.

I could have put that bold bit at the beginning and saved you a lot of time, but that’s why you’re a programmer you motherfucker. You’re like House and you have to deal with 56 minutes of bullshit before you get the answer.

Tags: Work The Jerk

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment