简体   繁体   English

分段错误(核心已转储)-无法修复错误

[英]Segmentation fault (core dumped)-cannot fix error

I am having trouble with the following bit of code. 我在以下代码方面遇到麻烦。 I am using Boost to do the matrix multiplication. 我正在使用Boost进行矩阵乘法。 I am using Gtesting to test my code. 我正在使用Gtesting测试我的代码。 When I test the following bit of code I get the following error. 当我测试以下代码时,出现以下错误。

Segmentation fault (core dumped)

I know that is has to do with the pointers I am using, but I cant find the error. 我知道这与我使用的指针有关,但是我找不到错误。 I have tried a couple of things but with no luck. 我尝试了几件事,但是没有运气。 My code is the following. 我的代码如下。 I am running Ubuntu 14.04. 我正在运行Ubuntu 14.04。

BLAS::matrix<double>* PolyFilter::getCoef(const std::queue<double> y const std::queue<double> x, const BLAS::vector<double>& w)
{
    int size = y.size();
    queue<double> yList = y;
    BLAS::matrix<double> pos(size,1);
    BLAS::matrix<double>* vand = makeVandermondeMatrix(x);
    BLAS::matrix<double>* weights = makeDiag(w);
    BLAS::matrix<double> *temp1,*temp2,*temp3,*temp4,*temp5;
    BLAS::matrix<double>* temp6 = new BLAS::matrix<double>(size,size);
    std::cout<<size<<endl;


    for( unsigned int i = 0; i < size; i++)
    {
        pos.insert_element(i,0,yList.front());
        yList.pop();
    }

    *temp1 = BLAS::prod(BLAS::trans(*vand), *weights);

    *temp2 = BLAS::prod(*temp1, *vand);


    if( rfalInverse(*temp2, *temp3) )
    {
        *temp4 = BLAS::prod(*temp3, BLAS::trans(*vand));
        *temp5 = BLAS::prod(*temp4,*weights);
        *temp6 = BLAS::prod(*temp5, BLAS::trans(pos));  
    } 



    return temp6;

}

Thankyou for any help. 感谢您的任何帮助。 This error is driving me crazy. 这个错误使我发疯。

You declared several pointers: 您声明了几个指针:

BLAS::matrix<double> *temp1,*temp2,*temp3,*temp4,*temp5;

And then you immediately proceed to dereference the uninitialized pointers: 然后,您立即继续取消引用未初始化的指针:

*temp1 = BLAS::prod(BLAS::trans(*vand), *weights);

*temp2 = BLAS::prod(*temp1, *vand);

There's your problem. 有你的问题。

PS You should invest some time in learning how to use a debugger. PS:您应该花一些时间来学习如何使用调试器。 This should be trivial to figure out with a debugger. 用调试器弄清楚这应该很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM