From d04d9b25190d78aaa8bceba150d76a17c10f2805 Mon Sep 17 00:00:00 2001 From: Lee Mon Date: Wed, 13 Mar 2019 21:17:28 +0300 Subject: [PATCH] BugFix 2: fix errors found by cppcheck Change-Id: I262af4dcf3ad1dca9d7e7d88838ae90323303c1d Reviewed-on: https://review.haiku-os.org/c/1294 Reviewed-by: waddlesplash --- src/add-ons/kernel/file_systems/bfs/FileSystemVisitor.cpp | 2 +- src/add-ons/kernel/partitioning_systems/atari/atari.cpp | 2 +- src/bin/unzip/beos.c | 2 +- src/kits/interface/Shelf.cpp | 2 ++ src/kits/tracker/DeskWindow.cpp | 2 +- src/kits/tracker/NavMenu.cpp | 2 +- src/libs/libunwind/os-linux.h | 5 +++-- src/system/libnetwork/netresolv/irs/getaddrinfo.c | 2 +- 8 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/FileSystemVisitor.cpp b/src/add-ons/kernel/file_systems/bfs/FileSystemVisitor.cpp index 779f1ebae8..103218623c 100644 --- a/src/add-ons/kernel/file_systems/bfs/FileSystemVisitor.cpp +++ b/src/add-ons/kernel/file_systems/bfs/FileSystemVisitor.cpp @@ -47,6 +47,7 @@ FileSystemVisitor::Next() while (true) { const char* name = NULL; + char treeName[B_FILE_NAME_LENGTH]; Inode* inode; Vnode vnode; @@ -97,7 +98,6 @@ FileSystemVisitor::Next() vnode.Keep(); } } else { - char treeName[B_FILE_NAME_LENGTH]; uint16 length; ino_t id; diff --git a/src/add-ons/kernel/partitioning_systems/atari/atari.cpp b/src/add-ons/kernel/partitioning_systems/atari/atari.cpp index 5bcc1058a9..eaa7b5f8e8 100644 --- a/src/add-ons/kernel/partitioning_systems/atari/atari.cpp +++ b/src/add-ons/kernel/partitioning_systems/atari/atari.cpp @@ -91,7 +91,7 @@ atari_identify_partition(int fd, partition_data *partition, void **_cookie) if (arb->Checksum() == 0x55aa) weight -= 0.1; /* possible but likely a PC sector */ - if (arb->_reserved_1[1] != 0x00) + if (arb->_reserved_1[0] != 0x00) weight -= 10; /* hope so */ if (arb->MaxPartitionSize() < 10) diff --git a/src/bin/unzip/beos.c b/src/bin/unzip/beos.c index 8c4fe98b7c..fd6334ea0e 100644 --- a/src/bin/unzip/beos.c +++ b/src/bin/unzip/beos.c @@ -504,7 +504,7 @@ int mapname(__G__ renamed) != (RO_extra_block *)NULL) { /* file *must* have a RISC OS extra field */ - long ft = (long)makelong((ef_spark->loadaddr); + long ft = (long)makelong(ef_spark->loadaddr); /*32-bit*/ if (lastcomma) { pp = lastcomma + 1; diff --git a/src/kits/interface/Shelf.cpp b/src/kits/interface/Shelf.cpp index 070c0566f8..a953b46318 100644 --- a/src/kits/interface/Shelf.cpp +++ b/src/kits/interface/Shelf.cpp @@ -464,6 +464,8 @@ ShelfContainerViewFilter::_ObjectDropFilter(BMessage *msg, BHandler **_handler) BDragger *dragger = NULL; if (handler) dragger = dynamic_cast(handler); + else + return B_SKIP_MESSAGE; BRect rect; if (dragger->fRelation == BDragger::TARGET_IS_CHILD) diff --git a/src/kits/tracker/DeskWindow.cpp b/src/kits/tracker/DeskWindow.cpp index 9e357303cd..e0451a52e9 100644 --- a/src/kits/tracker/DeskWindow.cpp +++ b/src/kits/tracker/DeskWindow.cpp @@ -522,7 +522,7 @@ BDeskWindow::AddWindowContextMenus(BMenu* menu) #ifdef CUT_COPY_PASTE_IN_CONTEXT_MENU BMenuItem* pasteItem = new BMenuItem(B_TRANSLATE("Paste"), - new BMessage(B_PASTE), 'V')); + new BMessage(B_PASTE), 'V'); menu->AddItem(pasteItem); menu->AddSeparatorItem(); #endif diff --git a/src/kits/tracker/NavMenu.cpp b/src/kits/tracker/NavMenu.cpp index 7d442a1c44..41d82cd74d 100644 --- a/src/kits/tracker/NavMenu.cpp +++ b/src/kits/tracker/NavMenu.cpp @@ -606,7 +606,7 @@ BNavMenu::NewModelItem(Model* model, const BMessage* invokeMessage, if (newResolvedModel->InitCheck() != B_OK) { // broken link, still can show though, bail delete newResolvedModel; - result = 0; + result = NULL; } else result = newResolvedModel; } diff --git a/src/libs/libunwind/os-linux.h b/src/libs/libunwind/os-linux.h index 3976b38cc2..d9052f1fac 100644 --- a/src/libs/libunwind/os-linux.h +++ b/src/libs/libunwind/os-linux.h @@ -178,7 +178,7 @@ scan_char (char *cp, char *valp) } /* Scan a string delimited by white-space. Fails on empty string or - if string is doesn't fit in the specified buffer. */ + if string doesn't fit in the specified buffer. */ static inline char * scan_string (char *cp, char *valp, size_t buf_size) { @@ -195,7 +195,8 @@ scan_string (char *cp, char *valp, size_t buf_size) } if (i == 0 || i >= buf_size) return NULL; - valp[i] = '\0'; + if (valp != NULL) + valp[i] = '\0'; return cp; } diff --git a/src/system/libnetwork/netresolv/irs/getaddrinfo.c b/src/system/libnetwork/netresolv/irs/getaddrinfo.c index b897040b25..ca0e4e45cd 100644 --- a/src/system/libnetwork/netresolv/irs/getaddrinfo.c +++ b/src/system/libnetwork/netresolv/irs/getaddrinfo.c @@ -614,8 +614,8 @@ getaddrinfo(const char *hostname, const char *servname, cur = cur->ai_next; } } - } #endif + } /* XXX */ if (sentinel.ai_next)