分段错误 - Fortran中的内存引用无效

时间:2017-12-18 12:20:02

标签: arrays segmentation-fault fortran

最近我在Fortran代码中收到以下错误

public function feedback_post()
{
    $objDate = new DateTime();

    $data = json_decode($this->input->post('QUESTION'), true);
    if (is_array($data)) 
    {
        foreach($data['ANSWERS'] AS $arrAnswer)
        {
            $arrInsertData =
            [
                'DRCODE' => $data['DATA']['DRCODE'],
                'DIVCODE' => $data['DATA']['DIVCODE'],
                'BRDCODE' => $data['DATA']['BRDCODE'],
                'PRDCODE' => $data['DATA']['PRDCODE'],
                'ADCODE' => $arrAnswer['ADCODE'],
                'ANSWERS' => $arrAnswer['ANSWER'],
                'CREATEDON' => $objDate->format('Y-m-d H:i:s'),
            ];

            $feedback_data = $this->Rest_user_model->feedbacksubmission($arrInsertData);
            $message = ($feedback_data) ?   ['status' => 1, 'message' => 'Feedback Submitted Successfully'] :   ['status' => 2, 'message' => 'Already Submitted'];
        }
    }
    else
    {
        $message = ["status" => 0, "msg" => "Request method not accepted"];
    }
    $this->set_response($message, REST_Controller::HTTP_OK);
}

我的代码如下

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x2AD9B0F8FE08
#1  0x2AD9B0F8EF90
#2  0x2AD9B12D44AF
#3  0x401A3E in MAIN__ at tstreadin.f90:?

我想将ASCII配置文件中的数据输入到数组中,因此我编写了测试代码。这是我第一次使用Fortran,我完全不能理解错误出现的原因。

1 个答案:

答案 0 :(得分:3)

数组xrange仅分配了1500个元素。但是在下面的

do i=1,rows,row
   xrange(i)=mat(1,i)
enddo

您正在尝试访问索引远远超过1500(行>> 1500)的xrange元素。因此无效的内存引用。