Fix issues shown by cppcheck for wrt-plugins-common
authorGrzegorz Rynkowski <g.rynkowski@samsung.com>
Mon, 18 Feb 2013 13:02:40 +0000 (14:02 +0100)
committerGrzegorz Rynkowski <g.rynkowski@samsung.com>
Fri, 22 Feb 2013 16:36:04 +0000 (17:36 +0100)
[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

15 files changed:
src/CommonsJavaScript/Converter.cpp
src/CommonsJavaScript/Validator.cpp
src/modules/API/TizenServiceEvent/TizenServiceEvent.cpp
src/modules/tizen/Filesystem/Node.cpp
src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.cpp
src/plugin-loading/js_page_session.cpp
src/plugins-installer/plugin_installer.cpp
src/standards/W3C/Widget/JSWidget.cpp
src/wrt-popup/ace/popup-bin/Popup.cpp
src/wrt-popup/ace/popup-runner/popup-runner.cpp
src/wrt-popup/wrt/popup-bin/InfoPopup.cpp
src/wrt-popup/wrt/popup-bin/InfoPopup.h
src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.cpp
src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp
tests/dao/WidgetDBTest.cpp

index 27183f4..71028c7 100644 (file)
@@ -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);
 }
 
index ef664e0..e73d361 100644 (file)
@@ -94,7 +94,7 @@ Validator::checkArrayKeys(const std::vector<std::string> &allowed,
         found = false;
         for (std::list<JSStringRef>::const_iterator it = allowedJS.begin();
              it != allowedJS.end();
-             it++)
+             ++it)
         {
             if (JSStringIsEqual(*it,
                                 JSPropertyNameArrayGetNameAtIndex(jsProps,
index 79d4f9a..b6233c6 100644 (file)
@@ -26,7 +26,8 @@
 namespace WrtDeviceApis {
 namespace TizenServiceEvent {
 namespace Api {
-TizenServiceEvent::TizenServiceEvent()
+TizenServiceEvent::TizenServiceEvent() :
+        m_scale(0)
 {}
 
 TizenServiceEvent::~TizenServiceEvent()
index d345dd0..eddbe19 100644 (file)
@@ -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.");
     }
 
index 411b559..f560fdd 100644 (file)
@@ -167,7 +167,7 @@ void WidgetInterfaceDAO::setItem(const std::string& key,
             Equals<Properties::key>(DPL::FromUTF8String(key)));
         std::list<Properties::Row> 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<std::string> WidgetInterfaceDAO::getValue(
         Properties::Select select(&m_databaseInterface);
         select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
         std::list<DPL::String> value = select.GetValueList<Properties::value>();
-        if (value.size() == 0) {
+        if (value.empty()) {
             return DPL::Optional<std::string>();
         }
         return DPL::Optional<std::string>(DPL::ToUTF8String(value.front()));
index 501c4bb..64d0a45 100644 (file)
@@ -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<std::string> 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);
 
index 05475d2..824f6b9 100644 (file)
@@ -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<std::string> 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);
     }
index 384347a..6dd18ba 100644 (file)
@@ -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<WidgetPrivateObject> WidgetPrivateObjectPtr;
index a3baeb6..6d51ace 100644 (file)
@@ -191,8 +191,6 @@ static void show_popup(struct ace_popup_data *pdp)
     const char *resource_type = static_cast <char *>(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;
index 6bd34c4..e46fc16 100644 (file)
@@ -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);
index 5a58fa2..faa3807 100644 (file)
 
 namespace Wrt {
 namespace Popup {
+InfoPopup::InfoPopup() :
+        m_parent(NULL)
+{}
+
 void InfoPopup::show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent)
 {
     LogDebug("Entered");
index 8d28341..3a29fc0 100644 (file)
@@ -30,6 +30,7 @@ namespace Popup {
 class InfoPopup : public IPopup
 {
   public:
+    InfoPopup();
     virtual void show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent);
 
   private:
index 68290ae..2f3a872 100644 (file)
@@ -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()
index 8e44eb3..10997dc 100644 (file)
@@ -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
     {
index e2b0d42..ea6ca11 100644 (file)
@@ -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);