Unhandled Exception Error [closed]

北战南征 提交于 2019-12-06 11:52:30

问题


I am experiencing an unhandled exception within xutility

if (_Myproxy != 0)
    {   // proxy allocated, drain it
    _Lockit _Lock(_LOCK_DEBUG);

    for (_Iterator_base12 **_Pnext = &_Myproxy->_Myfirstiter;
        *_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)
        (*_Pnext)->_Myproxy = 0;  <------- unhandled exception here
    _Myproxy->_Myfirstiter = 0;
}

I do not have control over xutility. This unhandled exception train stems from

std::string BinarySearchFile::readT(long filePointerLocation, long sizeOfData) 
{
     try{
          if(binary_search_file){
              std::string data;
              binary_search_file.seekp(filePointerLocation);
              binary_search_file.seekg(filePointerLocation);
              binary_search_file.read(reinterpret_cast<char *>(&data), sizeOfData);

              return data;  <------- branch into xutility and subsequent unhandled exception

          }else if(binary_search_file.fail()){
              throw CustomException("Attempt to read attribute error");
          }

     }
     catch(CustomException &custom_exception){  // Using custom exception class
          std::cout << custom_exception.what() << std::endl;
     }

}

Normally, the return would proceed to

std::string BinarySearchFile::read_data(long filePointerLocation, long sizeOfData){
    return readT(filePointerLocation, sizeOfData);
}

And subsequently back to the original call

attributeValue = data_file->read_data(index, size);

What am I doing wrong?


回答1:


The data string is empty when you try to read into it. That will corrupt memory somewhere.

You should add data.resize(sizeOfData) to allocate space, and then read into its buffer

binary_search_file.read(&data[0], sizeOfData);
                             ^^^

not into the string object itself.



来源:https://stackoverflow.com/questions/16038954/unhandled-exception-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!