[haiku-commits] haiku: hrev49462 - in src: kits/storage build/libbe/storage kits/support

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 26 Jul 2015 16:57:25 +0200 (CEST)

hrev49462 adds 9 changesets to branch 'master'
old head: 89de7826607770a33a540a0ec08e7f399479f1b0
new head: 58164f4a490e1a9d7bdef66621fb4a6055e19a96
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=58164f4a490e+%5E89de78266077

----------------------------------------------------------------------------

32a6b04592d9: PVS76: useless check of null pointer

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.

69ee6a6d621d: PVS 78-85: useless checks

* These were always true, so remove them.

c13e346a48b1: PVS 95-103: useless error checks

These conditions were always true, remove them.

67d9a9cb16eb: PVS 104: duplicate if check.

2f8639483aa5: PVS 170: use boolean for if comparison

Direct use of strcmp result in if is against our coding style.

3ec680083978: PVS 109: useless check

error was already checked one line above.

0e17424c6fb8: PVS 112: check result of memcmp against 0.

7895cfc69b8d: PVS 114: useless check.

We return a few line above if err is != 0.

58164f4a490e: PVS 122,123: useless checks.

[ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

8 files changed, 43 insertions(+), 40 deletions(-)
src/build/libbe/storage/AppFileInfo.cpp | 16 ++++++-------
src/build/libbe/storage/NodeInfo.cpp | 4 ++--
src/kits/storage/AppFileInfo.cpp | 16 ++++++-------
src/kits/storage/ResourceFile.cpp | 6 ++---
src/kits/storage/Resources.cpp | 34 ++++++++++++++++------------
src/kits/storage/mime/SnifferRules.cpp | 2 +-
src/kits/storage/mime/SupportingApps.cpp | 3 +--
src/kits/support/Archivable.cpp | 2 +-

############################################################################

Commit: 32a6b04592d9f8ad02c37bb68c62c04843c2b8d7
URL: http://cgit.haiku-os.org/haiku/commit/?id=32a6b04592d9
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Jul 26 12:58:25 2015 UTC

PVS76: useless check of null pointer

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.

----------------------------------------------------------------------------

diff --git a/src/kits/storage/Resources.cpp b/src/kits/storage/Resources.cpp
index 54bf553..b644f35 100644
--- a/src/kits/storage/Resources.cpp
+++ b/src/kits/storage/Resources.cpp
@@ -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;
}


############################################################################

Commit: 69ee6a6d621db9711d6623af6f8d5e8d2dfe6c9e
URL: http://cgit.haiku-os.org/haiku/commit/?id=69ee6a6d621d
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Jul 26 13:02:18 2015 UTC

PVS 78-85: useless checks

* These were always true, so remove them.

----------------------------------------------------------------------------

diff --git a/src/build/libbe/storage/AppFileInfo.cpp
b/src/build/libbe/storage/AppFileInfo.cpp
index 2b81579..d4e7499 100644
--- a/src/build/libbe/storage/AppFileInfo.cpp
+++ b/src/build/libbe/storage/AppFileInfo.cpp
@@ -181,13 +181,13 @@ BAppFileInfo::SetType(const char* type)
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
if (type != NULL) {
// check param
size_t typeLen = strlen(type);
- if (error == B_OK && typeLen >= B_MIME_TYPE_LENGTH)
+ if (typeLen >= B_MIME_TYPE_LENGTH)
error = B_BAD_VALUE;
// write the data
if (error == B_OK) {
@@ -230,13 +230,13 @@ BAppFileInfo::SetSignature(const char* signature)
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (B_OK && InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
if (signature) {
// check param
size_t signatureLen = strlen(signature);
- if (error == B_OK && signatureLen >= B_MIME_TYPE_LENGTH)
+ if (signatureLen >= B_MIME_TYPE_LENGTH)
error = B_BAD_VALUE;
// write the data
if (error == B_OK) {
@@ -318,7 +318,7 @@ BAppFileInfo::SetAppFlags(uint32 flags)
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
// write the data
@@ -334,7 +334,7 @@ BAppFileInfo::RemoveAppFlags()
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
// remove the data
@@ -373,7 +373,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage* types, bool
updateMimeDB,
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;

BMimeType mimeType;
@@ -590,7 +590,7 @@ BAppFileInfo::SetVersionInfo(const version_info* info,
version_kind kind)
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
if (info != NULL) {

############################################################################

Commit: c13e346a48b100efef2756df3a0788e285ba71ef
URL: http://cgit.haiku-os.org/haiku/commit/?id=c13e346a48b1
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Jul 26 13:06:38 2015 UTC

PVS 95-103: useless error checks

These conditions were always true, remove them.

----------------------------------------------------------------------------

diff --git a/src/kits/storage/AppFileInfo.cpp b/src/kits/storage/AppFileInfo.cpp
index ef3ca1a..f111a58 100644
--- a/src/kits/storage/AppFileInfo.cpp
+++ b/src/kits/storage/AppFileInfo.cpp
@@ -181,13 +181,13 @@ BAppFileInfo::SetType(const char* type)
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
if (type != NULL) {
// check param
size_t typeLen = strlen(type);
- if (error == B_OK && typeLen >= B_MIME_TYPE_LENGTH)
+ if (typeLen >= B_MIME_TYPE_LENGTH)
error = B_BAD_VALUE;
// write the data
if (error == B_OK) {
@@ -230,13 +230,13 @@ BAppFileInfo::SetSignature(const char* signature)
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
if (signature) {
// check param
size_t signatureLen = strlen(signature);
- if (error == B_OK && signatureLen >= B_MIME_TYPE_LENGTH)
+ if (signatureLen >= B_MIME_TYPE_LENGTH)
error = B_BAD_VALUE;
// write the data
if (error == B_OK) {
@@ -318,7 +318,7 @@ BAppFileInfo::SetAppFlags(uint32 flags)
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
// write the data
@@ -334,7 +334,7 @@ BAppFileInfo::RemoveAppFlags()
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
// remove the data
@@ -373,7 +373,7 @@ BAppFileInfo::SetSupportedTypes(const BMessage* types, bool
updateMimeDB,
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;

BMimeType mimeType;
@@ -588,7 +588,7 @@ BAppFileInfo::SetVersionInfo(const version_info* info,
version_kind kind)
{
// check initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
if (error == B_OK) {
if (info != NULL) {

############################################################################

Commit: 67d9a9cb16eb058ffa1501ba4bf6d117fbf3284a
URL: http://cgit.haiku-os.org/haiku/commit/?id=67d9a9cb16eb
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Jul 26 13:09:45 2015 UTC

PVS 104: duplicate if check.

----------------------------------------------------------------------------

diff --git a/src/kits/storage/mime/SupportingApps.cpp
b/src/kits/storage/mime/SupportingApps.cpp
index 4689462..495f06e 100644
--- a/src/kits/storage/mime/SupportingApps.cpp
+++ b/src/kits/storage/mime/SupportingApps.cpp
@@ -165,10 +165,9 @@ SupportingApps::SetSupportedTypes(const char *app, const
BMessage *types, bool f
std::set<std::string> &newTypes = fSupportedTypes[app];
std::set<std::string> &strandedTypes = fStrandedTypes[app];
// Make a copy of the previous types if we're doing a full sync
- if (!err)
+ if (!err) {
oldTypes = newTypes;

- if (!err) {
// Read through the list of new supported types, creating the
new
// supported types list and adding the app as a supporting app
for
// each type.

############################################################################

Commit: 2f8639483aa51409240e29679543881cd2a223f2
URL: http://cgit.haiku-os.org/haiku/commit/?id=2f8639483aa5
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Jul 26 13:13:41 2015 UTC

PVS 170: use boolean for if comparison

Direct use of strcmp result in if is against our coding style.

----------------------------------------------------------------------------

diff --git a/src/kits/support/Archivable.cpp b/src/kits/support/Archivable.cpp
index 8c092d9..d819d88 100644
--- a/src/kits/support/Archivable.cpp
+++ b/src/kits/support/Archivable.cpp
@@ -230,7 +230,7 @@ check_signature(const char* signature, image_info& info)
return err;
}

- if (strcmp(signature, imageSignature))
+ if (strcmp(signature, imageSignature) != 0)
return B_MISMATCHED_VALUES;

return B_OK;

############################################################################

Commit: 3ec680083978d2e840ba9557881653e00e321a30
URL: http://cgit.haiku-os.org/haiku/commit/?id=3ec680083978
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Jul 26 13:31:43 2015 UTC

PVS 109: useless check

error was already checked one line above.

----------------------------------------------------------------------------

diff --git a/src/kits/storage/ResourceFile.cpp
b/src/kits/storage/ResourceFile.cpp
index 48d5565..6885bcc 100644
--- a/src/kits/storage/ResourceFile.cpp
+++ b/src/kits/storage/ResourceFile.cpp
@@ -310,9 +310,9 @@ ResourceFile::ReadResource(ResourceItem& resource, bool
force)
status_t error = InitCheck();
size_t size = resource.DataSize();
if (error == B_OK && (force || !resource.IsLoaded())) {
- if (error == B_OK)
- error = resource.SetSize(size);
void* data = NULL;
+ error = resource.SetSize(size);
+
if (error == B_OK) {
data = resource.Data();
ssize_t bytesRead = fFile.ReadAt(resource.Offset(),
data, size);

############################################################################

Commit: 0e17424c6fb8e7c7c3e024da2360de45a2aa6f03
URL: http://cgit.haiku-os.org/haiku/commit/?id=0e17424c6fb8
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Jul 26 13:33:37 2015 UTC

PVS 112: check result of memcmp against 0.

----------------------------------------------------------------------------

diff --git a/src/kits/storage/ResourceFile.cpp
b/src/kits/storage/ResourceFile.cpp
index 6885bcc..907ee87 100644
--- a/src/kits/storage/ResourceFile.cpp
+++ b/src/kits/storage/ResourceFile.cpp
@@ -676,7 +676,7 @@ ResourceFile::_InitPEFFile(BFile& file, const
PEFContainerHeader& pefHeader)
if (error != B_OK)
throw Exception(error, "Failed to get the file size.");
// check architecture -- we support PPC only
- if (memcmp(pefHeader.architecture, kPEFArchitecturePPC, 4))
+ if (memcmp(pefHeader.architecture, kPEFArchitecturePPC, 4) != 0)
throw Exception(B_IO_ERROR, "PEF file architecture is not
PPC.");
fHostEndianess = B_HOST_IS_BENDIAN;
// get the section count

############################################################################

Commit: 7895cfc69b8d2ffd209400ab6ed4514cd2dab842
URL: http://cgit.haiku-os.org/haiku/commit/?id=7895cfc69b8d
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Jul 26 13:35:46 2015 UTC

PVS 114: useless check.

We return a few line above if err is != 0.

----------------------------------------------------------------------------

diff --git a/src/kits/storage/mime/SnifferRules.cpp
b/src/kits/storage/mime/SnifferRules.cpp
index 12efe32..a3ce4b1 100644
--- a/src/kits/storage/mime/SnifferRules.cpp
+++ b/src/kits/storage/mime/SnifferRules.cpp
@@ -452,7 +452,7 @@ SnifferRules::GuessMimeType(BFile* file, const void
*buffer, int32 length,
// wrap the buffer by a BMemoryIO
BMemoryIO data(buffer, length);

- if (!err && !fHaveDoneFullBuild)
+ if (!fHaveDoneFullBuild)
err = BuildRuleList();

// first ask the MIME sniffer for a suitable type

############################################################################

Revision: hrev49462
Commit: 58164f4a490e1a9d7bdef66621fb4a6055e19a96
URL: http://cgit.haiku-os.org/haiku/commit/?id=58164f4a490e
Author: Adrien Destugues <pulkomandy@xxxxxxxxx>
Date: Sun Jul 26 13:38:25 2015 UTC

PVS 122,123: useless checks.

----------------------------------------------------------------------------

diff --git a/src/build/libbe/storage/NodeInfo.cpp
b/src/build/libbe/storage/NodeInfo.cpp
index 83a6f50..2fd37b4 100644
--- a/src/build/libbe/storage/NodeInfo.cpp
+++ b/src/build/libbe/storage/NodeInfo.cpp
@@ -177,7 +177,7 @@ BNodeInfo::SetType(const char *type)
{
// check parameter and initialization
status_t error = B_OK;
- if (error == B_OK && type && strlen(type) >= B_MIME_TYPE_LENGTH)
+ if (type && strlen(type) >= B_MIME_TYPE_LENGTH)
error = B_BAD_VALUE;
if (error == B_OK && InitCheck() != B_OK)
error = B_NO_INIT;
@@ -540,7 +540,7 @@ BNodeInfo::SetAppHint(const entry_ref *ref)
{
// check parameter and initialization
status_t error = B_OK;
- if (error == B_OK && InitCheck() != B_OK)
+ if (InitCheck() != B_OK)
error = B_NO_INIT;
// write/remove the attribute
if (error == B_OK) {


Other related posts: