From 01be25aefe233feefb17b8c70d7553dc789bee1a Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 5 Mar 2014 15:27:12 -0500 Subject: [PATCH] GIFTranslator: Refactor filling out BBitmap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove the NULL check since BBitmaps don't return NULL but check that it IsValid() instead. * Fill out the *out pointer directly instead of creating a temporary bitmap pointer. * Rename err to result. * Return B_OK unconditionally if we get to the end of the function. Thanks again Jérôme --- src/add-ons/translators/gif/GIFTranslator.cpp | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/add-ons/translators/gif/GIFTranslator.cpp b/src/add-ons/translators/gif/GIFTranslator.cpp index ef1615d887..1eb442d806 100644 --- a/src/add-ons/translators/gif/GIFTranslator.cpp +++ b/src/add-ons/translators/gif/GIFTranslator.cpp @@ -121,6 +121,7 @@ DetermineType(BPositionIO* source, bool* isGif) *isGif = true; if (source->Read(header, 6) != 6) return false; + header[6] = 0x00; if (strcmp((char*)header, "GIF87a") != 0 @@ -152,8 +153,8 @@ status_t GetBitmap(BPositionIO* in, BBitmap** out) { TranslatorBitmap header; - status_t err = in->Read(&header, sizeof(header)); - if (err != sizeof(header)) + status_t result = in->Read(&header, sizeof(header)); + if (result != sizeof(header)) return B_IO_ERROR; header.magic = B_BENDIAN_TO_HOST_INT32(header.magic); @@ -166,24 +167,19 @@ GetBitmap(BPositionIO* in, BBitmap** out) header.dataSize = B_BENDIAN_TO_HOST_INT32(header.dataSize); // dump data from stream into a BBitmap - BBitmap* bitmap = new BBitmap(header.bounds, header.colors); - *out = bitmap; - if (bitmap == NULL) - return B_NO_MEMORY; - - unsigned char* bits = (unsigned char*)bitmap->Bits(); - if (bits == NULL) { - delete bitmap; + *out = new BBitmap(header.bounds, header.colors); + if (!(*out)->IsValid()) { + delete *out; return B_NO_MEMORY; } - err = in->Read(bits, header.dataSize); - if (err == (status_t)header.dataSize) - return B_OK; - else { - delete bitmap; + result = in->Read((*out)->Bits(), header.dataSize); + if (result != (status_t)header.dataSize) { + delete *out; return B_IO_ERROR; } + + return B_OK; } @@ -256,15 +252,15 @@ GIFTranslator::DerivedTranslate(BPositionIO* inSource, if (!isGif && inInfo->type != B_TRANSLATOR_BITMAP) return B_NO_TRANSLATOR; - status_t err = B_OK; + status_t result = B_OK; bigtime_t now = system_time(); if (!isGif) { // BBitmap to GIF BBitmap* bitmap; - err = GetBitmap(inSource, &bitmap); - if (err != B_OK) - return err; + result = GetBitmap(inSource, &bitmap); + if (result != B_OK) + return result; GIFSave* gifSave = new GIFSave(bitmap, outDestination, fSettings); if (gifSave->fatalerror) {