From b95d8a76bc8c1ec8862490b028ad91d380da51ed Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Sat, 25 Oct 2003 22:05:23 +0000 Subject: [PATCH] Fixed bits->bits translation so that it no longer errors out due to reads at the end of the stream git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5166 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../translators/tgatranslator/TGATranslator.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/add-ons/translators/tgatranslator/TGATranslator.cpp b/src/add-ons/translators/tgatranslator/TGATranslator.cpp index 3c579e28bc..b64fac6d6d 100644 --- a/src/add-ons/translators/tgatranslator/TGATranslator.cpp +++ b/src/add-ons/translators/tgatranslator/TGATranslator.cpp @@ -1435,16 +1435,21 @@ translate_from_bits(BPositionIO *inSource, ssize_t amtread, uint8 *read, // write out the data (only if configured to) if (bdataonly || (!bheaderonly && !bdataonly)) { uint8 buf[1024]; - ssize_t rd = inSource->Read(buf, 1024); + uint32 remaining = B_BENDIAN_TO_HOST_INT32(bitsHeader.dataSize); + ssize_t rd, writ; + rd = inSource->Read(buf, 1024); while (rd > 0) { - outDestination->Write(buf, rd); - rd = inSource->Read(buf, 1024); + writ = outDestination->Write(buf, rd); + if (writ < 0) + break; + remaining -= static_cast(writ); + rd = inSource->Read(buf, min(1024, remaining)); } - if (rd == 0) - return B_OK; - else + if (remaining > 0) return B_ERROR; + else + return B_OK; } else return B_OK;