Analysing and removing cppcheck warnings in wrt repository
authorKarol Pawlowski <k.pawlowski@samsung.com>
Thu, 21 Feb 2013 15:12:29 +0000 (16:12 +0100)
committerGerrit Code Review <gerrit2@kim11>
Wed, 27 Feb 2013 09:59:50 +0000 (18:59 +0900)
[Issue#]        LINUXWRT-125
[Problem]       Too many cppcheck warnings
[Cause]         N/A
[Solution]      N/A
[Verification]  Build wrt repository

Change-Id: I0bd7bf6fe534b9be4aeb7e7b33d99f63b8f0e367

12 files changed:
src/view/common/view_logic_custom_header_support.cpp
src/view/common/view_logic_custom_header_support.h
src/view/webkit/bundles/bundle_uri_handling.cpp
src/view/webkit/bundles/wrt-wk2-bundle.cpp
src/view/webkit/view_logic.cpp
src/view/webkit/view_logic.h
src/wrt-client/wrt-client.h
src/wrt-launchpad-daemon/launchpad_src/launchpad.c
src/wrt-launchpad-daemon/launchpad_src/sigchild.h
src/wrt-launchpad-daemon/src/app_sock.c
src/wrt-launchpad-daemon/src/simple_util.c
tests/widgets/common/src/InstallerWrapper.cpp

index 3c4b90b..58e9032 100644 (file)
@@ -33,7 +33,7 @@ const std::string LANGUAGE_EN = "en";
 
 namespace ViewModule {
 namespace CustomHeaderSupport {
-std::string getValueByField(const std::string field)
+std::string getValueByField(const std::string &field)
 {
     LogDebug("Field : " << field);
     std::string ret;
@@ -62,4 +62,4 @@ std::string getValueByField(const std::string field)
     return ret;
 }
 } // namespace CustomHeaderSupport
-} // namespace ViewModule
\ No newline at end of file
+} // namespace ViewModule
index 8b82b18..99ab3e9 100644 (file)
@@ -28,7 +28,7 @@ namespace ViewModule {
 namespace CustomHeaderSupport {
 const std::string ACCEPT_LANGUAGE = "Accept-Language";
 
-std::string getValueByField(const std::string field);
+std::string getValueByField(const std::string &field);
 } // namespace UserAgentSupport
 } // namespace CustomHeaderSupport
 
index 9595dcf..9a9792e 100644 (file)
@@ -152,7 +152,7 @@ namespace BundleURIHandling {
 bool processURI(const DPL::String& inputURI,
                 bool is_xhr,
                 const DPL::String& tizenId,
-                WKBundleRef bundle)
+                WKBundleRef /*bundle*/)
 {
     DPL::Optional<DPL::String> uri(inputURI);
     if (uri.IsNull()) {
index 1734762..763a4d9 100644 (file)
@@ -465,9 +465,9 @@ void Bundle::didRemoveFrameFromHierarchyCallback(
 
 void Bundle::didFinishLoadForResourceCallback(
     WKBundlePageRef /*page*/,
-    WKBundleFrameRef frame,
+    WKBundleFrameRef /*frame*/,
     uint64_t /*resourceIdentifier*/,
-    const void* clientInfo)
+    const void* /*clientInfo*/)
 {
     LogDebug("didFinishLoadForResourceCallback called");
 }
@@ -604,7 +604,7 @@ WKURLRequestRef Bundle::willSendRequestForFrame(WKURLRequestRef request)
     DPL::String dplurl = DPL::FromUTF8String(toString(urlStr));
     WKRelease(urlStr);
 
-    DPL::Optional<DPL::String> localizedUrl = 
+    DPL::Optional<DPL::String> localizedUrl =
         BundleURIHandling::localizeURI(dplurl, m_widgetTizenId);
     bool ret = BundleURIHandling::processURI(
             *localizedUrl,
@@ -637,9 +637,9 @@ WKURLRequestRef Bundle::willSendRequestForFrame(WKURLRequestRef request)
         return request;
     } else {
         std::string checkUrl = toString(tmpUrl);
-        int getFileSize;
 
         if (m_encrypted) {
+            int getFileSize;
             if (isEncryptedResource(checkUrl, getFileSize)) {
                 std::string decryptString = DecryptResource(checkUrl,
                                                             getFileSize);
@@ -697,7 +697,7 @@ WKBundlePagePolicyAction Bundle::pageDecidePolicyForNavigationAction(
 
     // WARP & ACE Check
     DPL::String dplUrl = DPL::FromUTF8String(request_uri);
-    DPL::Optional<DPL::String> localizedUrl = 
+    DPL::Optional<DPL::String> localizedUrl =
         BundleURIHandling::localizeURI(dplUrl, m_widgetTizenId);
     bool ret = BundleURIHandling::processURI(
             *localizedUrl, true, m_widgetTizenId, m_bundle);
index 9cd73b2..41a3e63 100644 (file)
@@ -170,15 +170,18 @@ std::map<const std::string,
 
 ViewLogic::ViewLogic() :
     m_ewkContext(0),
+    m_attachedToCustomHandlerDao(false),
     m_currentEwkView(0),
+    m_closedEwkView(NULL),
     m_window(NULL),
     m_model(0),
     m_cbs(new WRT::UserDelegates),
+    m_imeWidth(0),
+    m_imeHeight(0),
     m_isBackgroundReload(false),
     m_isBackgroundSupport(false),
     m_appsSupport(new ViewModule::AppsSupport()),
-    m_vibrationSupport(new ViewModule::VibrationSupport()),
-    m_attachedToCustomHandlerDao(false)
+    m_vibrationSupport(new ViewModule::VibrationSupport())
 {
     ApplicationLauncherSingleton::Instance().Touch();
 }
@@ -259,7 +262,7 @@ void ViewLogic::hideWidget()
 
     m_vibrationSupport->deinitialize();
 
-    while (m_ewkViewList.size()) {
+    while (!m_ewkViewList.empty()) {
         LogInfo("pop webview: " << m_ewkViewList.back());
         removeEwkView(m_ewkViewList.back());
     }
@@ -325,7 +328,7 @@ void ViewLogic::resetWidget()
     LogInfo("Resetting Widget");
 
     // destory all webview
-    while (m_ewkViewList.size()) {
+    while (!m_ewkViewList.empty()) {
         LogInfo("pop webview: " << m_ewkViewList.back());
         removeEwkView(m_ewkViewList.back());
     }
@@ -387,8 +390,8 @@ void ViewLogic::reloadStartPage()
     m_isBackgroundReload = true;
     PluginModuleSupport::resume(m_ewkContext);
 
-    if (m_ewkViewList.size() != 0) {
-        while (m_ewkViewList.size() > 0) {
+    if (!m_ewkViewList.empty()) {
+        while (!m_ewkViewList.empty()) {
             if (!m_cbs->bufferUnset.empty()) {
                 m_cbs->bufferUnset(m_currentEwkView);
             }
index 6c14862..a45e1f8 100644 (file)
@@ -264,6 +264,7 @@ class ViewLogic : public ViewModule::IViewModule
     void windowClose(void);
 
     Ewk_Context* m_ewkContext;
+    bool m_attachedToCustomHandlerDao;
     std::list<Evas_Object*> m_ewkViewList;
     Evas_Object* m_currentEwkView;
     Evas_Object* m_closedEwkView;
@@ -283,7 +284,6 @@ class ViewLogic : public ViewModule::IViewModule
     std::unique_ptr<ViewModule::AppsSupport> m_appsSupport;
     std::unique_ptr<ViewModule::VibrationSupport> m_vibrationSupport;
     std::unique_ptr<ViewModule::SecurityOriginSupport> m_securityOriginSupport;
-    bool m_attachedToCustomHandlerDao;
 
     static std::map<const std::string, const Evas_Smart_Cb> m_ewkCallbacksMap;
 };
index 93f2d73..36a25f3 100644 (file)
@@ -104,7 +104,6 @@ class WrtClient :
     bool m_initialized;
     int m_sdkLauncherPid;
     bool m_debugMode;
-    bundle *m_bundle;
     unsigned short m_debuggerPort;
     ReturnStatus::Type m_returnStatus;
     WRT::RunnableWidgetObjectPtr m_widget;
index ddf707c..484cc64 100644 (file)
@@ -139,9 +139,6 @@ _static_ void __set_sdk_env(app_info_from_db* menu_info, char* str)
 _static_ void __set_env(app_info_from_db * menu_info, bundle * kb)
 {
     const char *str;
-    const char **str_array;
-    int len;
-    int i;
 
     setenv("PKG_NAME", _get_pkgname(menu_info), 1);
 
@@ -153,8 +150,11 @@ _static_ void __set_env(app_info_from_db * menu_info, bundle * kb)
     }
 
     if (bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
+        int len;
+        const char **str_array;
         str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
         if (str_array != NULL) {
+            int i;
             for (i = 0; i < len; i++) {
                 _D("index : [%d]", i);
                 __set_sdk_env(menu_info, (char *)str_array[i]);
@@ -246,7 +246,7 @@ _static_ int __normal_fork_exec(int argc, char **argv)
     _D("start real fork and exec\n");
 
     // warning: unused parameter
-    argc = argc;
+    (void)argc;
 
     if (execv(argv[0], argv) < 0) {     /* Flawfinder: ignore */
         if (errno == EACCES) {
@@ -393,7 +393,7 @@ _static_ void __modify_bundle(bundle * kb, int caller_pid,
                               app_info_from_db * menu_info, int cmd)
 {
     // warning: unused parameter
-    caller_pid = caller_pid;
+    (void)caller_pid;
 
     bundle_del(kb, AUL_K_PKG_NAME);
     bundle_del(kb, AUL_K_EXEC);
@@ -623,7 +623,8 @@ _static_ void __send_result_to_caller(int clifd, int ret)
         }
 
         _D("-- now wait to change cmdline --");
-        usleep(50 * 1000);              /* 50ms sleep*/
+        struct timespec duration = { 0, 50 * 1000 * 1000 };
+        nanosleep(&duration, NULL);     /* 50ms sleep*/
         wait_count++;
     } while (wait_count <= 20);         /* max 50*20ms will be sleep*/
 
index d1e0214..6d30b65 100644 (file)
@@ -24,7 +24,8 @@ sigset_t oldmask;
 static inline void __socket_garbage_collector()
 {
     DIR *dp;
-    struct dirent *dentry;
+    struct dirent dentry;
+    struct dirent *result;
     char tmp[MAX_LOCAL_BUFSZ];
 
     dp = opendir(AUL_SOCK_PREFIX);
@@ -32,15 +33,15 @@ static inline void __socket_garbage_collector()
         return;
     }
 
-    while ((dentry = readdir(dp)) != NULL) {
-        if (!isdigit(dentry->d_name[0])) {
+    while (readdir_r(dp, &dentry, &result) == 0 && result != NULL) {
+        if (!isdigit(dentry.d_name[0])) {
             continue;
         }
 
-        snprintf(tmp, MAX_LOCAL_BUFSZ, "/proc/%s", dentry->d_name);
+        snprintf(tmp, MAX_LOCAL_BUFSZ, "/proc/%s", dentry.d_name);
         if (access(tmp, F_OK) < 0) {            /* Flawfinder: ignore */
             snprintf(tmp, MAX_LOCAL_BUFSZ, "%s/%s", AUL_SOCK_PREFIX,
-                     dentry->d_name);
+                    dentry.d_name);
             unlink(tmp);
             continue;
         }
@@ -141,8 +142,8 @@ static void __launchpad_sig_child(int signo, siginfo_t *info, void *data)
     pid_t child_pgid;
 
     // warning: unused parameter
-    signo = signo;
-    data = data;
+    (void)signo;
+    (void)data;
 
     child_pgid = getpgid(info->si_pid);
     _D("dead_pid = %d pgid = %d", info->si_pid, child_pgid);
index decce63..26edf9f 100644 (file)
@@ -22,6 +22,8 @@
 #include <sys/smack.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <time.h>
+
 
 #include "app_sock.h"
 #include "simple_util.h"
@@ -75,7 +77,7 @@ int __create_server_sock(int pid)
         }
     }
 
-    bzero(&saddr, sizeof(saddr));
+    memset(&saddr, 0, sizeof(saddr));
     saddr.sun_family = AF_UNIX;
     snprintf(saddr.sun_path, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, pid);
     unlink(saddr.sun_path);
@@ -172,17 +174,18 @@ int __create_client_sock(int pid)
 
     saddr.sun_family = AF_UNIX;
     snprintf(saddr.sun_path, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, pid);
-retry_con:
-    ret = __connect_client_sock(fd, (struct sockaddr *)&saddr, sizeof(saddr),
-                                100 * 1000);
-    if (ret < -1) {
+
+    while ((ret = __connect_client_sock(fd, (struct sockaddr *)&saddr, sizeof(saddr),
+            100 * 1000)) < -1) {
         _E("maybe peer not launched or peer daed\n");
         if (retry > 0) {
-            usleep(100 * 1000);
+            struct timespec duration = { 0, 100 * 1000 * 1000 };
+            nanosleep(&duration, NULL);     /* 100ms sleep*/
             retry--;
-            goto retry_con;
         }
+        else break;
     }
+
     if (ret < 0) {
         close(fd);
         return -1;
index 4342efb..6f87ad4 100644 (file)
@@ -82,7 +82,8 @@ int __proc_iter_cmdline(
     void *priv)
 {
     DIR *dp;
-    struct dirent *dentry;
+    struct dirent dentry;
+    struct dirent *result;
     int pid;
     int ret;
     char buf[MAX_LOCAL_BUFSZ];
@@ -96,12 +97,12 @@ int __proc_iter_cmdline(
         iterfunc = __find_pid_by_cmdline;
     }
 
-    while ((dentry = readdir(dp)) != NULL) {
-        if (!isdigit(dentry->d_name[0])) {
+    while (readdir_r(dp, &dentry, &result) == 0 && result != NULL) {
+        if (!isdigit(dentry.d_name[0])) {
             continue;
         }
 
-        snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name);
+        snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry.d_name);
         ret = __read_proc(buf, buf, sizeof(buf));
         if (ret <= 0) {
             continue;
@@ -110,10 +111,10 @@ int __proc_iter_cmdline(
         /* support app launched by shell script*/
         if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0) {
             pid =
-                iterfunc(dentry->d_name, &buf[BINSH_SIZE + 1],
+                iterfunc(dentry.d_name, &buf[BINSH_SIZE + 1],
                          priv);
         } else {
-            pid = iterfunc(dentry->d_name, buf, priv);
+            pid = iterfunc(dentry.d_name, buf, priv);
         }
 
         if (pid > 0) {
@@ -188,7 +189,8 @@ int __proc_iter_pgid(int pgid, int (*iterfunc)(int pid, void *priv),
                      void *priv)
 {
     DIR *dp;
-    struct dirent *dentry;
+    struct dirent dentry;
+    struct dirent *result;
     int _pgid;
     int ret = -1;
 
@@ -197,14 +199,14 @@ int __proc_iter_pgid(int pgid, int (*iterfunc)(int pid, void *priv),
         return -1;
     }
 
-    while ((dentry = readdir(dp)) != NULL) {
-        if (!isdigit(dentry->d_name[0])) {
+    while (readdir_r(dp, &dentry, &result) == 0 && result != NULL) {
+        if (!isdigit(dentry.d_name[0])) {
             continue;
         }
 
-        _pgid = __get_pgid_from_stat(atoi(dentry->d_name));
+        _pgid = __get_pgid_from_stat(atoi(dentry.d_name));
         if (pgid == _pgid) {
-            ret = iterfunc(atoi(dentry->d_name), priv);
+            ret = iterfunc(atoi(dentry.d_name), priv);
             if (ret >= 0) {
                 break;
             }
index 40e680e..505a01c 100644 (file)
@@ -71,11 +71,8 @@ InstallResult install(
     }
 
     char buffer[1024] = "";
-    int ret;
-    while ((ret = fread_unlocked(buffer,
-                                 sizeof(char),
-                                 sizeof(buffer)/sizeof(char),
-                                 filehandle)) > 0)
+    while (fread_unlocked(buffer, sizeof(char), sizeof(buffer)/sizeof(char),
+                                 filehandle) > 0)
     {
         msg += buffer;
     }