我遇到了一个奇怪的分段错误。为了调试,我重写了我的代码,以便一些值是恒定的,但分段错误仍然存在。在这一点上,我不知道是什么导致了这个错误。
Program terminated with signal 11, Segmentation fault.
#0 findMaxFlowInSTNetwork (graph=0xbfb74076, adj=0xbfaaccf4, source=1, target=2,
maxValue=2) at invariants/connectivity/multi_connectivity.c:36
36 int order = 4;
(gdb) print order
Cannot access memory at address 0xbbd980c4
我从来没有遇到过这样的分段错误。有谁知道可能导致这种情况的原因以及如何解决?
编辑:
这是该函数的代码:
//returns the minimum of the maxflow of the st-network and maxValue
int findMaxFlowInSTNetwork(GRAPH graph, ADJACENCY adj, int source, int target, int maxValue){
int order = 4;
//int order = graph[0][0];
int paths[(MAXN+1)*(MAXN+1)] = {0};
int pathCount = 0;
boolean currentPath[MAXN+1] = {0};
while(findPath(graph, adj, source, target, paths, order, currentPath) && pathCount < maxValue){
pathCount++;
}
return pathCount;
}
注释中的行是原始行。由于这给出了分段错误,因此我将其替换为int order = 4;
. 我这样称呼这个函数:
minimumCutSize = minDegree;
for (i = 1; i <= graph[0][0]; i++){
if(i!=vertexMinDegree){
minimumCutSize = findMaxFlowInSTNetwork(graph, adj, vertexMinDegree, i, minimumCutSize);
}
}