Strange behavior with this bit of C++

It has been a long time since I’ve had time to do anything in C++. So I figured it would be a useful way to limber up my memory, by implementing a little bit of my favorite Python classes/modules in C++. The only crazy thing, is the result this code has yielded.

// minimal program, using the code involved
#include
#include

extern "C" {
#include <sys/param.h>
#include <unistd.h>
}

namespace os {
bool link(const std::string& src, const std::string& dst);
}

bool
os::link(const std::string& src, const std::string& dst) {
if (link(src.c_str(), dst.c_str()) != 0) {
std::perror(NULL);
return false;
}
return true;
}

int
main() {
std::cout << "link()t" << std::endl;
os::link(std::string("./test"), std::string("/tmp/test"));
return 0;
}

compilation: /usr/bin/g++ -Wall -ggdb3 os.cpp test.cpp -o test

I compiled on FreeBSD 7 with the systems GCC 4.3.1 and get a segfault, then tried the code on my OpenBSD 4.4 machine. The OpenBSD 4.4 release has shipped with a patched GCC 3.5.3 (propolice) – on OpenBSD it ran perfectly! Trying to feed it through the debuger on FreeBSD wasn’t pretty either:

  • FreeBSD 7, system GCC 4.3.1 -> test program dies with a Segmentation Fault.
  • FreeBSD 7, system GDB 6.1.1 -> Endless stepping when used with a break point, or SIG SEGV in libc’s malloc() when run.
  • OpenBSD 4.4, system GCC 3.5.3 -> prints proper message from std::perror() as expected, when the program is executed.

If I change os::link to os::link_x and recompile on FreeBSD, it works the same as it does on OpenBSD, when unmodified that is. In a few tests on FreeBSD, When I run the program under GCC, it tells me

Program received signal SIGSEGV, Segmentation fault.
0x281fabc3 in malloc () from /lib/libc.so.7

if I set a break point in test.cpp on the os::link() call, and step through it into os::link() in os.cpp. If I keep stepping after the link(), I get returned to the os::link() call in main and can step through it all again. Like an endless loop of stepping into/out of the os::link() function call in test.cpp’s main(), and the if-conditional in os.cpp’s os::link(), geeze.

At least looking at the results I’ve had tonight, I know I’m not freaking nuts… lol. I still shouldn’t write code when I’m half asleep, but hey… It’s the only time I get :, Oh well… unless my family is late as usual, I need to be up in a few hour.

*head hits laptop, snores loudly until morning*

TODO FRIDAY

Adapt header to i386/amd64
Adapt header to supported compilers
Finish implementing the module
Test module with (puke) MSVC++

I put Stargate on and decided I would lay down for a few minutes before getting online; last thing I remember is O’Neil and Jackson being captured and about to be brought before Ra. Next thing I know, I wake up out of a sound sleep to see some show on depicting a 2 on 1, like wtf!? I slept through Stargate!!!

That’s what I get for taking a nap, instead of camping out in front of a computer lol.

N I’m wide awake and glad that unlike the rest of my family, I don’t set my TVs volume loud enough to be heard from Kansas..

Hooah a stroke of luck!

Just caught Top Gun starting a few minutes ago, usually I always find it on after the first halfhour r so; but my favorite part is in the beginning. They’re dancing with the MiGs, when Maverick and Goose end up inverted above the MiG, almost canopy to canopy -> Mav gives’em the bird while Goose takes a Polaroid of the look on the other pilots face xD –> Priceless !

Managed to get through work today in one piece, singing a song in my head to keep my mind else wheres; but not to bad a day overall, I guess. I don’t really have a problem with working a lot, it’s having to scrimp and scavenge my time whenever I’m /not/ working. My family drives me nuts at times…. and after work tomorrow, I’m expecting a headache with what’s planned.

I did get to have sme fun today though, joined PG#3 for a few games of SWAT 4. My custom skin is labeled 3.x.x beta, but I think unless I find any visual bugs of interest that it will probably be going gamma soon. I really like how the last take on the NWN BDU came out. The no armour vest didn’t come out as intended, but I kinda like it, really might pass as “no armour” if it wasn’t for the dang games design.

I can’t wait for the weekend…. I outa be off Sat/Sun/Mon, and I’ve got a projects meeting n Sunday. Hopefully it won’t take forever to pull off, but I might get some of the other days to actually get stuff done on, hopefully anyway…

Just a little bit of time left until it’s time to leave from work, and odds of getting any work done before are dismal. (be lucky if I get time for lunch :). I was up to after 0500R, getting woken up at the crack of dawn, and dragged out on a shopping expedition around 1000R. Tomorrow is 2 jobs, so that’s the end of getting anything done then; but luckily one is short… it’s just the margin-time on pre and post op that’s the killer.

sigh

I really need a vacation…………..

but that’s not likely to happen, before the next ice age lol.

Been wprking on several things when I can, and playing a mixture of games whenever I can’t work on crap. *SIGH*

TODO: compile a more detailed analysis on all possible solutions (and their implications) to the meetings point 0 topic.

sounds like mental fun, if it wasn’t for family to drive me nuts and reck my train of thought every chance they get lol.

QTOD

While ProgramName always endeavours to protect its users from unnecessary harm, it will not stop you from ignoring the big red warning signs.

Some day :

My brother finally showed up around 1230R, to bitch at me for nt being ready – my response being, “Your late, so you can wait”. Good sized headache helping him ove crap around, I tell ya… family are the only creatures alive who have the balls to ask for help and insult you all the way through it!

Ducked into a few levels of F.E.A.R. to pass the time until he finally shoved off and Ma found something to do, not involving driving me nuts.

I managed to sort out the meeting, it’s either tomorrow at 1800GMT or next weekend lol. I still don’t think we’ll be able to get everyone present by then, but w/e works for most of us. Tomorrow, I also need to take some time to catch up with my email lol.

I also eventually made it into Proving Grounds #3 to join Chester, Decapi, and Duke for some great games. Pardoning my mother trying to shipwreck the highlight of my day, but it was still good to get the games in, even if I was last to show and first to leave :-(. One thing that did bring a smile to my face though, on the angels of mercy mission; I called for a reload before we continued on, b/c I had 18 rounds left and we were moving into 2 small rooms, followed by a hallway and 2 very large rooms without much time to reload if things hit the fan. When I completed our reloading drill, (EL) Duke stepped out of formation and asked us if we had ever seen this before, leaving all of us flabbergasted to figure out what he meant lol -> every thread angel was covered perfectly by the element, from gun down to gun up.

That made my day 🙂

Just once, I wish someone else in this family knew how to keep a schedule… dang nab’it. Well, o be fair there is at least one besides myself; but Uncle Pat was a coast guard captain, if he’s late, ya start to worry lol. Otherwise I’m about the only one who knows how to manage time… in a manor that approximately works.

I woke up around 1028R, my brothers not here. I was woken up around 1156R to find out he called a few minutes ago, to say that he was just starting out; our mothers been up since 0800R. And the other day, he said he was going to be here early [in the morning]… Well, I’ll probably be out of battery charge on my laptop before he even gets to the city limits… the putz !!!

Was dreaming several things, but I remember dreaming that I was going through CQB training before I was woken up. The last thing I remember, was 2 man stack, kick it in, he moved left, I took right. Tango across my sector, 2 to the chest with a single action revolver; made it to my corner, then sliced the pie around. Two more tangos, put a quick shot in the right ones chest, then the left while advancing, then cycled back and put a head shot in each, right to left. Then dropped to one knee shouting “GUN DOWN” and started reloading the revolver as my teammate took up a cover position from his point of domination; 6 in the can, “GUN UP” and moved out…

Something like this:

|--------------------------|
| y |
| T T |
| /-------------- T|
| ______________/ |
| |
| ___x___x___|
|Y x| |
|-- -----------|----------|
X=Spidey01's way point
Y=teammates way point
T=tango position

Which reminds me, there are supposed to be some team games on PG#3 today hehe 🙂