Jump to content
  • Advertisement
Sign in to follow this  
suliman

Segmentation violation?

This topic is 485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

Im trying to submit an assignment in c++ that gives me this error message (see below). It compiles and runs fine on my own machine (and when I debug I find nothing strange) but the server compiler (which I cannot debug) does not accept it and "crashes" with this message. It runs fine for me both in debug and release builds. What could be the problem and how could I find it? Can I disable something (visual studio 2008) that makes it less accepting so it becomes more "sensitive"? The server compiler seems to be very sensitive...

Thanks for your input!

Erik

-------------- error message -----------------

Signal 11 is SIGSEGV, Segmentation Violation. This means that your program has tried to access memory which it was not allowed to access, either because the memory was not mapped by the process or due to permission errors. Make sure everything is properly initialized, be careful with your pointer arithmetic and don't follow null pointers.

 

Share this post


Link to post
Share on other sites
Advertisement


1) It compiles and runs fine on my own machine (and when I debug I find nothing strange) but the server compiler (which I cannot debug) does not accept it and "crashes" with this message. It runs fine for me both in debug and release builds.

2) What could be the problem and how could I find it?

3) Can I disable something (visual studio 2008) that makes it less accepting so it becomes more "sensitive"?

 

1)

Segfaults have little to do with compilation.  Segfaults mean the running program touched memory it should not have, like following a null pointer, following an unintialized pointer, accessing outside of an array's bounds, or similar.

If you are submitting the code and it is generating a segfault, such as submitting it to a school's automatic grading program, then the segfault is probably a bug in the tool that manages their compiler.

Otherwise, the fault would be with your own program touching memory it should not have.

2) 

The problem is that some program in the process is touching memory it should not have. Without more information it is hard to tell if that is your program crashing when being run, or if it is the server you submit the code to that has its code crashing.
 

3)

No. It is not a setting on your compiler. Depending on the nature of the bug you might be able to detect it with different settings, maybe the compiler could generate a warning about using an uninitialized value, or using a pointer after releasing it, or some other detection where the code might touch memory it should not. You can try adjusting the warning level settings on the compiler, but that will only help you find the error, not fix it.

The best way to find it is to attach the program to a debugger. When it dies the debugger will capture the fault, stop execution, and show you the exact location and program state at the time of the crash.

Share this post


Link to post
Share on other sites

Is it possible your school server is testing your program with different inputs than you are?  You should probably check all the edge conditions your program could possibly encounter.  Those TAs that write the grading test suites are sneaky beggars looking to break your program, and they have nothing on the real world waiting to eat your code alive when it its the wild.

It pays to be a paranoid programmer.

Share this post


Link to post
Share on other sites

If it works fine in your environment but not in a different environment, then there is probably something in your code that doesn't account for different environments. Consider things that might go wrong in different environments, such as assuming that a file is in a certain location, or that certain directories or drives exist. Better examples are hard to give without knowing what the program does.

Share this post


Link to post
Share on other sites
If you print a message to the console, can you see that output? If so, you can sprinkle your code with progress messages (e.g. "entered function foo", " about to access array element 42"). You may need to flush the output too.

If not (perhaps only the segfault will be reported regardless), then try commenting out some code and re-submitting. You should be able to narrow down the affected area by successively commenting out different sections (you might need to put in safe "dummy" code to keep it compiling, e.g. returning 0 rather than summing an array).

Share this post


Link to post
Share on other sites

I've tried drmemory (no problem) debugged through the code with many examples of different map sizes etc to no avail! All seem to work fine for me.

Could someone do me a HUGE favour and look at the actual code? It's not super long but I know im still asking alot. I just dont find the problem :(

 

https://www.dropbox.com/s/o8kroh9q2dkci56/pathfind_astar.zip?dl=0

(5kb zipfile, also with main.cpp to show usage and speed up testing)

Edited by suliman

Share this post


Link to post
Share on other sites

What does the stackdump say? Usually a crash like this can be precisly pinpointed to the spot where it breaks. Often that gives sufficient clues to what is not doing its job.

 

The simplest way to get a stackdump is to run the code under a debugger. When it crashes, the debugger grabs it, and shows you where exactly it crashes [1], with a dump with all function-calls in-progress from 'main()' to the line where it dies (ie all functions on the stack, which is how it got its name).

 

[1] Usually, you need to compile the code with debugging symbols enabled to get useful names and line numbers.

 

 

Edit: Never mind, I now read you cannot go this route.

I took a quick look, and it seems pretty good, compiling and running didn't crash.

valgrind says all memory is properly released, and found no other errors either.

 

Perhaps there is something special about the server, eg 64K memory model, or otherwise limited time or space? Perhaps wrong c++ version?

Edited by Alberth

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!