An odd segmentation violation

Hello, I am doing analysis of a monte carlo simulation.
I am using the Root libraries from CERN, and I am coming against some odd problems.

I am having a segmentation violation during the run time.
I will not post my code here (it is over 10,000 lines) but I know what lines are responsible.
whenever I have a condition of the format
if (varible> 10000) {continue;}
I get a segmentation fault. These conditions are entirely necessary to my analysis.
Thanks
It's impossible to say what the problem is. I recommend you use a debugger (like valgrind) that can point out where things go wrong.
> I will not post my code here
¡Oh, a challenge!

> (it is over 10,000 lines)
isolate your problem in a simpler program

> but I know what lines are responsible.
I doubt about that.


http://www.cplusplus.com/forum/general/112111/
as for a pasting mechanism you can use github.
I will not post my code here (it is over 10,000 lines) but I know what lines are responsible.

We really only need the part of the code that is causing the problem. This is usually (but not always) a single function or a single source code file. If you mean to say that your entire project is a single source code file 10K+ Lines long then I feel very sorry for you.

Although I share ne555 doubts about a conditional statement causing a seg fault, I'll try to entertain the idea. If that is actually all of the code causing the issue then my first idea is that you are breaking from a loop that is allocating\initializing something that the outer scope is then trying to use. Something like this is easy to spot in a debugger.
Thank You all!

I realized I should clarify my statement:

I isolated the lines by adding a
cout <<line number <<endl;
every other line and then commenting out any line that caused the problem. I found that any line with the format above was not passing, and resulting in a segmentation fault there

also, it has trouble with boolean conditions so
if (boolvar==False){continue;}
also is a problem
Last edited on
I isolated the lines by adding a
cout <<line number <<endl;
every other line and then commenting out any line that caused the problem.


The problem is... the line you commented out is a continue statement. Which means it might not be that line that is causing the segfault.. but it might be the fact that you are skipping the rest of the loop body in that iteration that's causing the segfault.

Regardless.... cout statements are a poor man's debugger. If you run this in an actual debugger, when the segfault occurs, the debugger will automatically snap on the exact line that it occurs on... at which point you will be able to examine the contents of all variables to see exactly why it segfaulted.


also, it has trouble with boolean conditions so
if (boolvar==False){continue;}
also is a problem


There is no way this is causing a segfault. The only chance is if 'boolvar' is a member and you have a bad 'this' pointer. That is literally the only way this could possibly screw up on you.

And if the 'this' pointer is the culprit, then this line of code is not where the problem is. The problem would be where you assign the this pointe (ie: when you call the member function -- the object you're giving it must be a bad pointer/incomplete object).


But really I'm just taking shots in the dark here. As others have said you simply have not provided enough info. Your method of isolating the problem is 'iffy' and you probably have not actually found the code that's causing the issue yet. And unless we can see more of the code, none of us are going to be able to find it either.


My advice:

- get rid of your cout statements.
- run the program in a debugger
- reproduce the segfault.
- Post the actual message you get when the program crashes (sometimes they have useful info that you might not realize is useful)
- go in the debugger during the segfault, post the line of code causing the problem (as well as the lines above/below it... ideally post the entire function).
- Look in the debugger's "watch" window
- Post the contents of all the variables involved in that line of code. So if the line of code looks like this:

 
foobar[ baz ] = boop;


Post the contents of:
- foobar (or &foobar[0])
- baz
- boop
- foobar[baz]
- this



Once you have that info, it'll be clearly obvious why it's segfaulting.
Sorry, the code was finishing the for loop, then trying to make a check on a vector that is no longer in the registries. This was causing the Seg fault
Topic archived. No new replies allowed.