| 233 | } |
| 234 | |
| 235 | bool SourceData::FileData::readFile(FileAccess& file) |
| 236 | { |
| 237 | reset(); |
| 238 | if(file.fileName().isEmpty()) |
| 239 | { |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | if(!file.isNormal()) |
| 244 | return true; |
| 245 | |
| 246 | mDataSize = file.sizeForReading(); |
| 247 | /* |
| 248 | If the extra bytes are removed an unknown heap currption issue is triggered in the |
| 249 | diff code. I don't have time to track this down to its true root cause. |
| 250 | */ |
| 251 | m_pBuf = std::make_unique<char[]>(mDataSize + 100); // Alloc 100 byte extra: Safety hack, not nice but does no harm. |
| 252 | // Some extra bytes at the end of the buffer are needed by |
| 253 | // the diff algorithm. See also GnuDiff::diff_2_files(). |
| 254 | bool bSuccess = file.readFile(m_pBuf.get(), mDataSize); |
| 255 | if(!bSuccess) |
| 256 | { |
| 257 | m_pBuf = nullptr; |
| 258 | mDataSize = 0; |
| 259 | } |
| 260 | else |
| 261 | { |
| 262 | //null terminate buffer |
| 263 | m_pBuf[mDataSize + 1] = 0; |
| 264 | m_pBuf[mDataSize + 2] = 0; |
| 265 | m_pBuf[mDataSize + 3] = 0; |
| 266 | m_pBuf[mDataSize + 4] = 0; |
| 267 | } |
| 268 | return bSuccess; |
| 269 | } |
| 270 | |
| 271 | bool SourceData::FileData::readFile(const QString& filename) |
| 272 | { |
no test coverage detected