SIGSEGV在一个没有指针的线上

问题描述:

这是一个递归快速排序,到目前为止只有100000或更大的数组(也许有点小)失败。起初我认为这是一个内存大小问题,但它调用SIGSEGV而不是堆栈溢出。我有一个迭代版本使用相同的分区代码,并且工作正常。这里的 代码...SIGSEGV在一个没有指针的线上

template <typename T> 
void QuicksortR(T *a, u_int l, u_int r){ 
    if(r <= l) return; 
    u_int i = Partition(a, l, r); 
    if(i-1 < i) //in case of underflow 
    QuicksortR(a, l, i - 1); 
    QuicksortR(a, i + 1, r); 
} 

... 

template <typename T> 
u_int Partition(T a[], u_int l, u_int r){ 
    u_int i = l-1; //potential underflow fixed by an overflow 
    u_int j = r; 
    T v = a[r]; 
    while(1){ 
     while(a[++i] < v); //overflow fix; 
     while(a[--j] > v) 
      if(i == j) break; 
     if(i >= j) break; 
     swap(a[i], a[j]); 
    } 
    swap(*(a+i), *(a+r)); 
    return i; 
} 
+1

如果超出允许的堆栈大小,将会出现段错误。由于你的问题不符合[mcve]的要求,所以不可能有权威的答案。 –

+0

在这个问题中没有问题。 –

但它调用SIGSEGV没有堆栈溢出

没有人调用SIGSEGVSIGSEGV是内核在某些条件下将提升为例外情况。其中一种情况堆栈溢出,它可能发生在这里。