Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Greystoke on February 18, 2011, 05:38:35 am

Title: Program works in CB terminal, but seg faults in Linux terminal?
Post by: Greystoke on February 18, 2011, 05:38:35 am
I have a small-ish program that seems to works fine in the Code::Blocks terminal window (I get all the output, it exits normally).  But if I go to a Linux terminal and run the same program, I get a segmentation fault.  (Open a new terminal window, CD to the directory, do "./program".)  Anyone have any ideas about this?  What should be looking at?

I did compile it with -fprofile-arcs and -ftest-coverage flags, BTW.

Thanks!

-G
Title: Re: Program works in CB terminal, but seg faults in Linux terminal?
Post by: Jenna on February 18, 2011, 06:52:48 am
Do you try to read from a file or something similar, that depends on the working directory ?
If yes, check whether you test the vaildity of the (file- or whatever) handlers before using them.
Title: Re: Program works in CB terminal, but seg faults in Linux terminal?
Post by: Greystoke on February 18, 2011, 07:29:22 am
No, I am not reading from any files.  The profiling/gcov stuff does, however...

Oh bollocks.  I reconfigured it to not do profiling and now it crashes in Code::Blocks, too!  :)

But it runs fine (in CB anyway) if I use my debug profile/target.  I can't find any culprits as to why there's a difference, either.  (I'm rather new at this, so I am probably missing something obvious.)

-- G
Title: Re: Program works in CB terminal, but seg faults in Linux terminal?
Post by: stahta01 on February 18, 2011, 01:44:42 pm
The likely problem is your code is bad; as in you are reading or writing to memory you have to rights to access.
The above is not a topic for this site. Try cboard for code issues. http://cboard.cprogramming.com/general-programming-boards/

Tim S.
Title: Re: Program works in CB terminal, but seg faults in Linux terminal?
Post by: Greystoke on February 18, 2011, 04:43:42 pm
Actually, it was my own dumb fault; similar to my code being bad, but different.

I had set a 'program arguments' for my CB profile when executing that build target.  I had forgotten about that when trying to run it manually.  When I included the command line argument in a native terminal, it worked fine. 

DOH!  :)