2013-04-16 5 views
1

나는 xutility 통해 unhandled exception처리되지 않은 예외 오류

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 기차는 return 이후 다시 내가 잘못 뭐하는 거지 원래 통화

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

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

로 진행 그리고 것,

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

} 

일반적으로 유래?

+1

"처리되지 않은 예외"는 절박한 진단이며, 알고있는 내용을 말해야합니다. 디버거는 예외에 대한 세부 정보를 보여줍니다. 일반적으로, 이것은 xutility와 관련이 있다고 생각하지 마십시오. 프로그램이 힙을 손상 시키면 표준적인 설명이됩니다. –

+0

위에서 (코드)를 게시 한 내용에서 힙을 손상시킬 수 있다고 생각합니까? 나는 바이너리 데이터를'std :: string'으로 읽어 들여 호출자에게 돌려 보낸다. – Mushy

+0

어딘가에 메모리가 엉망이되었습니다. 귀하의 [testcase] (http://sscce.org)는 어디에 있습니까? –

답변

2

data 문자열을 읽으려고하면 문자열이 비어 있습니다. 그러면 어딘가에서 메모리가 손상 될 것입니다.

당신은 문자열 객체 자체에

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

하지 버퍼로 읽어 후 공간을 할당 data.resize(sizeOfData)를 추가해야한다.

+0

수정하십시오. OP는'data'를 기성의 바이트 콜렉션으로 취급하고 있지만 그렇지 않습니다. 실제로는 내부적으로나 간접적으로 어떤 바이트도 "포함"하지 않는 복잡한 객체입니다. –

+0

예, 작동하지만 의도 한대로 작동하지 않습니다. 왜 바이너리 데이터가 부정확한지와 관련된 또 다른 질문을해야 할 것입니다. binary_search_file.write (reinterpret_cast (& attribute), attribute.length() * 2); '를 사용하여 "packard (3 개의 후행 공백)"파일에 썼으나 binary_search_file.read (& data [0], sizeOfData);'XXX packard XXX' 여기서 X는 바람직하지 않은 데이터입니다. – Mushy