2

我正在经历一个unhandled exception内在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;
}

我没有控制权xutility。这unhandled exception列火车起源于

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;
     }

}

通常,return将继续

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

随后又回到原来的通话

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

我究竟做错了什么?

4

1 回答 1

2

data当您尝试读入字符串时,该字符串为空。那会在某处破坏内存。

你应该添加data.resize(sizeOfData)分配空间,然后读入它的缓冲区

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

不进入字符串对象本身。

于 2013-04-16T14:03:52.860 回答