Skip to content

Commit

Permalink
PVS76: useless check of null pointer
Browse files Browse the repository at this point in the history
Refactor BResources::WriteResource to return early in case of errors,
instead of checking permanently if (error == B_OK). Makes the code more
readable and removes some useless checks.
  • Loading branch information
pulkomandy committed Jul 26, 2015
1 parent 89de782 commit 32a6b04
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/kits/storage/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,23 +618,27 @@ BResources::WriteResource(type_code type, int32 id, const void* data,
error = InitCheck();
if (error == B_OK)
error = (fReadOnly ? B_NOT_ALLOWED : B_OK);
ResourceItem *item = NULL;
if (error == B_OK) {
item = fContainer->ResourceAt(fContainer->IndexOf(type, id));
if (!item)
error = B_BAD_VALUE;
}
if (error == B_OK && fResourceFile)

if (error != B_OK)
return error;

ResourceItem *item = fContainer->ResourceAt(fContainer->IndexOf(type, id));
if (!item)
return B_BAD_VALUE;

if (fResourceFile) {
error = fResourceFile->ReadResource(*item);
if (error == B_OK) {
if (item) {
ssize_t written = item->WriteAt(offset, data, length);
if (written < 0)
error = written;
else if (written != (ssize_t)length)
error = B_ERROR;
}
if (error != B_OK)
return error;
}

ssize_t written = item->WriteAt(offset, data, length);

if (written < 0)
error = written;
else if (written != (ssize_t)length)
error = B_ERROR;

return error;
}

Expand Down

0 comments on commit 32a6b04

Please sign in to comment.