Author Topic: Program works in CB terminal, but seg faults in Linux terminal?  (Read 4031 times)

Offline Greystoke

  • Single posting newcomer
  • *
  • Posts: 3
Program works in CB terminal, but seg faults in Linux terminal?
« 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
« Last Edit: February 18, 2011, 05:46:09 am by Greystoke »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Program works in CB terminal, but seg faults in Linux terminal?
« Reply #1 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.

Offline Greystoke

  • Single posting newcomer
  • *
  • Posts: 3
Re: Program works in CB terminal, but seg faults in Linux terminal?
« Reply #2 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
« Last Edit: February 18, 2011, 07:42:12 am by Greystoke »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7601
    • My Best Post
Re: Program works in CB terminal, but seg faults in Linux terminal?
« Reply #3 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Greystoke

  • Single posting newcomer
  • *
  • Posts: 3
Re: Program works in CB terminal, but seg faults in Linux terminal?
« Reply #4 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!  :)