소스 검색

Fixed hasardous cast in streamer example

Paul-Louis Ageneau 2 년 전
부모
커밋
9cfb6dd34a
1개의 변경된 파일3개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 2
      examples/streamer/fileparser.cpp

+ 3 - 2
examples/streamer/fileparser.cpp

@@ -50,8 +50,9 @@ void FileParser::loadNextSample() {
         return;
     }
 
-    vector<uint8_t> fileContents((std::istreambuf_iterator<char>(source)), std::istreambuf_iterator<char>());
-    sample = *reinterpret_cast<vector<byte> *>(&fileContents);
+    vector<char> contents((std::istreambuf_iterator<char>(source)), std::istreambuf_iterator<char>());
+    auto *b = reinterpret_cast<const std::byte*>(contents.data());
+    sample.assign(b, b + contents.size());
     sampleTime_us += sampleDuration_us;
 }