From 057f2143b02d50f405f81b64cf97689e9460bd16 Mon Sep 17 00:00:00 2001 From: Grzegorz Rynkowski Date: Mon, 18 Feb 2013 14:02:40 +0100 Subject: [PATCH] Fix issues shown by cppcheck for wrt-plugins-common [Issue#] LINUXWRT-124 [Problem] Cppcheck appears some warnings for wrt-plugins-common. [Cause] Incorrect code. [Solution] Make some changes. [Verification] Run cppcheck on wrt-plugins-common (omitting incorrectStringBooleanError). It would be no warnings. I used the command: cppcheck --std=posix --std=c++11 --std=c99 --max-configs=1 --enable=all "`PKG_CONFIG_LIBDIR="/home/grynkowski/GBS-ROOT/local/scratch.armv7l.0/usr/lib/pkgconfig" PKG_CONFIG_SYSROOT_DIR="/home/grynkowski/GBS-ROOT/local/scratch.armv7l.0" pkg-config --cflags-only-I dpl-efl wrt-plugins-types security-client dpl-event-efl ewebkit2 dpl-wrt-dao-ro dpl-wrt-dao-rw dpl-db-efl libpcrecpp icu-i18n libxml-2.0 cert-svc-vcore`" "/home/grynkowski/ngwap/wrt-plugins-common" --suppress=incorrectStringBooleanError Change-Id: I8cc6142660c4f2253909c7537cc966a3c027fa6f --- src/CommonsJavaScript/Converter.cpp | 3 +- src/CommonsJavaScript/Validator.cpp | 2 +- .../API/TizenServiceEvent/TizenServiceEvent.cpp | 3 +- src/modules/tizen/Filesystem/Node.cpp | 34 +++++++++++++--------- .../WidgetInterfaceDAO/WidgetInterfaceDAO.cpp | 4 +-- src/plugin-loading/js_page_session.cpp | 21 +++++++++---- src/plugins-installer/plugin_installer.cpp | 17 +++++++---- src/standards/W3C/Widget/JSWidget.cpp | 2 +- src/wrt-popup/ace/popup-bin/Popup.cpp | 17 +++++++---- src/wrt-popup/ace/popup-runner/popup-runner.cpp | 3 +- src/wrt-popup/wrt/popup-bin/InfoPopup.cpp | 4 +++ src/wrt-popup/wrt/popup-bin/InfoPopup.h | 1 + .../wrt/popup-bin/renderer/popup_renderer.cpp | 5 +++- src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp | 4 +-- tests/dao/WidgetDBTest.cpp | 2 +- 15 files changed, 81 insertions(+), 41 deletions(-) diff --git a/src/CommonsJavaScript/Converter.cpp b/src/CommonsJavaScript/Converter.cpp index 27183f4..71028c7 100644 --- a/src/CommonsJavaScript/Converter.cpp +++ b/src/CommonsJavaScript/Converter.cpp @@ -290,7 +290,8 @@ JSValueRef Converter::toJSValueRef(const tm& arg) JSValueRef Converter::toJSValueRef(const time_t arg) { - struct tm *tminfo = localtime(&arg); + struct tm *tminfo = NULL; + tminfo = localtime_r(&arg, tminfo); return toJSValueRef(*tminfo); } diff --git a/src/CommonsJavaScript/Validator.cpp b/src/CommonsJavaScript/Validator.cpp index ef664e0..e73d361 100644 --- a/src/CommonsJavaScript/Validator.cpp +++ b/src/CommonsJavaScript/Validator.cpp @@ -94,7 +94,7 @@ Validator::checkArrayKeys(const std::vector &allowed, found = false; for (std::list::const_iterator it = allowedJS.begin(); it != allowedJS.end(); - it++) + ++it) { if (JSStringIsEqual(*it, JSPropertyNameArrayGetNameAtIndex(jsProps, diff --git a/src/modules/API/TizenServiceEvent/TizenServiceEvent.cpp b/src/modules/API/TizenServiceEvent/TizenServiceEvent.cpp index 79d4f9a..b6233c6 100644 --- a/src/modules/API/TizenServiceEvent/TizenServiceEvent.cpp +++ b/src/modules/API/TizenServiceEvent/TizenServiceEvent.cpp @@ -26,7 +26,8 @@ namespace WrtDeviceApis { namespace TizenServiceEvent { namespace Api { -TizenServiceEvent::TizenServiceEvent() +TizenServiceEvent::TizenServiceEvent() : + m_scale(0) {} TizenServiceEvent::~TizenServiceEvent() diff --git a/src/modules/tizen/Filesystem/Node.cpp b/src/modules/tizen/Filesystem/Node.cpp index d345dd0..eddbe19 100644 --- a/src/modules/tizen/Filesystem/Node.cpp +++ b/src/modules/tizen/Filesystem/Node.cpp @@ -44,7 +44,7 @@ INodePtr Node::resolve(const IPathPtr& path) "Node does not exist or access denied."); } - if (!S_ISDIR(info.st_mode) & !S_ISREG(info.st_mode)) { + if (!S_ISDIR(info.st_mode) && !S_ISREG(info.st_mode)) { ThrowMsg(Commons::PlatformException, "Platform node is of unsupported type."); } @@ -100,16 +100,20 @@ Node::NameList Node::getChildNames() const NameList result; errno = 0; - struct dirent *entry = NULL; - while ((entry = readdir(dir))) { - if (!strncmp(entry->d_name, ".", - 1) || !strncmp(entry->d_name, "..", 2)) + int return_code; + struct dirent entry; + struct dirent *entry_result; + for (return_code = readdir_r(dir, &entry, &entry_result); + entry_result != NULL && return_code != 0; + return_code = readdir_r(dir, &entry, &entry_result)) { + if (!strncmp(entry.d_name, ".", 1) || + !strncmp(entry.d_name, "..", 2)) { continue; } - result.push_back(entry->d_name); + result.push_back(entry.d_name); } - if (errno != 0) { + if (return_code != 0 || errno != 0) { ThrowMsg(Commons::PlatformException, "Error while reading directory."); } @@ -138,16 +142,20 @@ NodeList Node::getChildNodes(const NodeFilterPtr& filter) const errno = 0; NodeList result; - struct dirent *entry = NULL; - while ((entry = readdir(dir))) { - if (!strncmp(entry->d_name, ".", - 1) || !strncmp(entry->d_name, "..", 2)) + int return_code; + struct dirent entry; + struct dirent *entry_result; + for (return_code = readdir_r(dir, &entry, &entry_result); + entry_result != NULL && return_code != 0; + return_code = readdir_r(dir, &entry, &entry_result)) { + if (!strncmp(entry.d_name, ".", 1) || + !strncmp(entry.d_name, "..", 2)) { continue; } Try { Assert(m_path); - INodePtr node = Node::resolve(*m_path + entry->d_name); + INodePtr node = Node::resolve(*m_path + entry.d_name); node->setPermissions(getPermissions()); // inherit access rights if (NodeFilterMatcher::match(node, filter)) { result.push_back(node); @@ -156,7 +164,7 @@ NodeList Node::getChildNodes(const NodeFilterPtr& filter) const Catch(Commons::PlatformException) {} } - if (errno != 0) { + if (return_code != 0 || errno != 0) { ThrowMsg(Commons::PlatformException, "Error while reading directory."); } diff --git a/src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.cpp b/src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.cpp index 411b559..f560fdd 100644 --- a/src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.cpp +++ b/src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.cpp @@ -167,7 +167,7 @@ void WidgetInterfaceDAO::setItem(const std::string& key, Equals(DPL::FromUTF8String(key))); std::list rows = select.GetRowList(); - if (rows.size() == 0) { + if (rows.empty()) { Properties::Insert insert(&m_databaseInterface); Properties::Row row; row.Set_key(DPL::FromUTF8String(key)); @@ -234,7 +234,7 @@ DPL::Optional WidgetInterfaceDAO::getValue( Properties::Select select(&m_databaseInterface); select.Where(Equals(DPL::FromUTF8String(key))); std::list value = select.GetValueList(); - if (value.size() == 0) { + if (value.empty()) { return DPL::Optional(); } return DPL::Optional(DPL::ToUTF8String(value.front())); diff --git a/src/plugin-loading/js_page_session.cpp b/src/plugin-loading/js_page_session.cpp index 501c4bb..64d0a45 100644 --- a/src/plugin-loading/js_page_session.cpp +++ b/src/plugin-loading/js_page_session.cpp @@ -144,7 +144,10 @@ class JSPageSession::Impl }; JSPageSession::Impl::Impl(const PluginContainerSupportPtr& support) : - m_sessionStarted(false) + m_widgetHandle(0), + m_context(NULL), + m_sessionStarted(false), + m_objectExplorer(NULL) { // DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS"); LogDebug("Initializing Page Session"); @@ -391,20 +394,24 @@ void JSPageSession::Impl::loadInjectedJavaScript() return; } - struct dirent* libdir; + int return_code; + struct dirent libdir; + struct dirent* result; std::list jsFiles; // make file list from DIR_PATH - while ((libdir = readdir(dir)) != 0) { - if (strncmp(libdir->d_name, ".", 2) == 0 || - strncmp(libdir->d_name, "..", 3) == 0) + for (return_code = readdir_r(dir, &libdir, &result); + result != NULL && return_code != 0; + return_code = readdir_r(dir, &libdir, &result)) { + if (strncmp(libdir.d_name, ".", 2) == 0 || + strncmp(libdir.d_name, "..", 3) == 0) { continue; } std::string filepath = DIR_PATH; filepath += "/"; - filepath += libdir->d_name; + filepath += libdir.d_name; std::string lowercase = filepath; std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), @@ -433,6 +440,8 @@ void JSPageSession::Impl::loadInjectedJavaScript() LogInfo("Added : " << filepath); jsFiles.push_back(filepath); } + if (0 != return_code) + LogError("Error while reading directory."); closedir(dir); diff --git a/src/plugins-installer/plugin_installer.cpp b/src/plugins-installer/plugin_installer.cpp index 05475d2..824f6b9 100644 --- a/src/plugins-installer/plugin_installer.cpp +++ b/src/plugins-installer/plugin_installer.cpp @@ -377,22 +377,26 @@ int PluginsInstaller::installAllPlugins() } LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH); - struct dirent* libdir; + int return_code; + struct dirent libdir; + struct dirent* result; errno = 0; std::list pluginsPaths; - while ((libdir = readdir(dir)) != 0) { - if (strcmp(libdir->d_name, ".") == 0 || - strcmp(libdir->d_name, "..") == 0) + for (return_code = readdir_r(dir, &libdir, &result); + result != NULL && return_code != 0; + return_code = readdir_r(dir, &libdir, &result)) { + if (strcmp(libdir.d_name, ".") == 0 || + strcmp(libdir.d_name, "..") == 0) { continue; } std::string path = PLUGIN_PATH; path += "/"; - path += libdir->d_name; + path += libdir.d_name; struct stat tmp; @@ -410,6 +414,9 @@ int PluginsInstaller::installAllPlugins() pluginsPaths.push_back(path); } + if (0 != return_code) + LogError("Error while reading directory."); + if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) { LogError("Failed to close dir: " << PLUGIN_PATH); } diff --git a/src/standards/W3C/Widget/JSWidget.cpp b/src/standards/W3C/Widget/JSWidget.cpp index 384347a..6dd18ba 100644 --- a/src/standards/W3C/Widget/JSWidget.cpp +++ b/src/standards/W3C/Widget/JSWidget.cpp @@ -106,7 +106,7 @@ struct WidgetPrivateObject Widget::Api::IWidgetPtr iwidget; JSObjectRef preferencesObject; //TEMP - int widgetId; + //int widgetId // TODO: check is it necessary (g.rynkowski) JSObjectRef widgetObject; }; typedef std::shared_ptr WidgetPrivateObjectPtr; diff --git a/src/wrt-popup/ace/popup-bin/Popup.cpp b/src/wrt-popup/ace/popup-bin/Popup.cpp index a3baeb6..6d51ace 100644 --- a/src/wrt-popup/ace/popup-bin/Popup.cpp +++ b/src/wrt-popup/ace/popup-bin/Popup.cpp @@ -191,8 +191,6 @@ static void show_popup(struct ace_popup_data *pdp) const char *resource_type = static_cast (pdp->resource_name); Evas_Object *win = NULL; - Evas_Object *cb_session = NULL; - Evas_Object *cb_always = NULL; Evas_Object *box = NULL; Evas_Object *label = NULL; Evas_Object *grant_button = NULL; @@ -236,7 +234,7 @@ static void show_popup(struct ace_popup_data *pdp) LogDebug("popup_type == " << pdp->popup_type); if (pdp->popup_type == ACE_SESSION || pdp->popup_type == ACE_BLANKET) { LogDebug("popup_type == ACE_SESSION || ACE_BLANKET"); - cb_session = elm_check_add(pdp->popup); + Evas_Object *cb_session = elm_check_add(pdp->popup); elm_object_text_set(cb_session, "Remember choice for this session"); elm_check_state_pointer_set(cb_session, &(pdp->per_session)); evas_object_smart_callback_add(cb_session, "changed", NULL, NULL); @@ -251,7 +249,7 @@ static void show_popup(struct ace_popup_data *pdp) if (pdp->popup_type == ACE_BLANKET) { LogDebug("popup_type == ACE_BLANKET"); - cb_always = elm_check_add(pdp->popup); + Evas_Object *cb_always = elm_check_add(pdp->popup); elm_object_text_set(cb_always, "Remember choice forever"); elm_check_state_pointer_set(cb_always, &(pdp->always)); evas_object_smart_callback_add(cb_always, "changed", NULL, NULL); @@ -323,16 +321,23 @@ elm_main(int argc, char ** argv) int pipe_in; int pipe_out; + std::stringstream parsing_stream; // Parsing args (pipe_in, pipe_out) - if (0 == sscanf(argv[1], "%d", &pipe_in) ) { + parsing_stream.str(argv[1]); + parsing_stream >> pipe_in; + if ( parsing_stream.fail() ) { LogError("Error while parsing pipe_in; return ACE_INTERNAL_ERROR"); return ACE_INTERNAL_ERROR; } - if (0 == sscanf(argv[2], "%d", &pipe_out) ) { + parsing_stream.clear(); + parsing_stream.str(argv[2]); + parsing_stream >> pipe_out; + if ( parsing_stream.fail() ) { LogError("Error while parsing pipe_out; return ACE_INTERNAL_ERROR"); return ACE_INTERNAL_ERROR; } + parsing_stream.clear(); LogDebug("Parsed pipes: IN: " << pipe_in << ", OUT: " << pipe_out); int buff_size = 1024; diff --git a/src/wrt-popup/ace/popup-runner/popup-runner.cpp b/src/wrt-popup/ace/popup-runner/popup-runner.cpp index 6bd34c4..e46fc16 100644 --- a/src/wrt-popup/ace/popup-runner/popup-runner.cpp +++ b/src/wrt-popup/ace/popup-runner/popup-runner.cpp @@ -251,10 +251,11 @@ ace_return_t run_popup( int count; count = TEMP_FAILURE_RETRY(read(fd_send_to_parent[0], result, buff_size)); close(fd_send_to_parent[0]); // cleanup - int validation_result_int; + if (0 < count) { BinaryStream stream_in; + int validation_result_int; stream_in.Write(count, result); LogDebug("RESULT FROM POPUP (CHILD) : [ " << count << " ]"); DPL::Deserialization::Deserialize(stream_in, validation_result_int); diff --git a/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp b/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp index 5a58fa2..faa3807 100644 --- a/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp +++ b/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp @@ -29,6 +29,10 @@ namespace Wrt { namespace Popup { +InfoPopup::InfoPopup() : + m_parent(NULL) +{} + void InfoPopup::show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent) { LogDebug("Entered"); diff --git a/src/wrt-popup/wrt/popup-bin/InfoPopup.h b/src/wrt-popup/wrt/popup-bin/InfoPopup.h index 8d28341..3a29fc0 100644 --- a/src/wrt-popup/wrt/popup-bin/InfoPopup.h +++ b/src/wrt-popup/wrt/popup-bin/InfoPopup.h @@ -30,6 +30,7 @@ namespace Popup { class InfoPopup : public IPopup { public: + InfoPopup(); virtual void show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent); private: diff --git a/src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.cpp b/src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.cpp index 68290ae..2f3a872 100644 --- a/src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.cpp +++ b/src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.cpp @@ -73,7 +73,10 @@ class PopupRenderer::Impl Impl() : m_popupsToRender(), m_current(), - m_initialized(false) + m_initialized(false), + m_checkState(false), + m_themeIndexV(0), + m_externalCanvas(NULL) {} ~Impl() diff --git a/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp b/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp index 8e44eb3..10997dc 100644 --- a/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp +++ b/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp @@ -34,8 +34,8 @@ const char *POPUP_EXEC = "/usr/bin/wrt-popup-wrt-runtime"; namespace Wrt { namespace Popup { PopupInvoker::PopupInvoker() : - m_inputName(tmpnam(NULL)), - m_outputName(tmpnam(NULL)) + m_inputName(tmpnam_r(NULL)), + m_outputName(tmpnam_r(NULL)) { Try { diff --git a/tests/dao/WidgetDBTest.cpp b/tests/dao/WidgetDBTest.cpp index e2b0d42..ea6ca11 100644 --- a/tests/dao/WidgetDBTest.cpp +++ b/tests/dao/WidgetDBTest.cpp @@ -369,7 +369,7 @@ RUNNER_TEST(widgetDB_test_get_config_value_empty) { try { IWidgetDBPtr widget = getWidgetDB(2005); - std::string tmp = widget->getConfigValue(ConfigAttribute::ID); + widget->getConfigValue(ConfigAttribute::ID); //exception should be thrown RUNNER_ASSERT(false); -- 2.7.4