From 09deaf503b2d7232e8ed40b6e080f1ea063d3e4d Mon Sep 17 00:00:00 2001 From: Karol Pawlowski Date: Thu, 21 Feb 2013 16:12:29 +0100 Subject: [PATCH] Analysing and removing cppcheck warnings in wrt repository [Issue#] LINUXWRT-125 [Problem] Too many cppcheck warnings [Cause] N/A [Solution] N/A [Verification] Build wrt repository Change-Id: I0bd7bf6fe534b9be4aeb7e7b33d99f63b8f0e367 --- .../common/view_logic_custom_header_support.cpp | 4 ++-- src/view/common/view_logic_custom_header_support.h | 2 +- src/view/webkit/bundles/bundle_uri_handling.cpp | 2 +- src/view/webkit/bundles/wrt-wk2-bundle.cpp | 10 ++++----- src/view/webkit/view_logic.cpp | 15 ++++++++------ src/view/webkit/view_logic.h | 2 +- src/wrt-client/wrt-client.h | 1 - src/wrt-launchpad-daemon/launchpad_src/launchpad.c | 13 ++++++------ src/wrt-launchpad-daemon/launchpad_src/sigchild.h | 15 +++++++------- src/wrt-launchpad-daemon/src/app_sock.c | 17 ++++++++------- src/wrt-launchpad-daemon/src/simple_util.c | 24 ++++++++++++---------- tests/widgets/common/src/InstallerWrapper.cpp | 7 ++----- 12 files changed, 59 insertions(+), 53 deletions(-) diff --git a/src/view/common/view_logic_custom_header_support.cpp b/src/view/common/view_logic_custom_header_support.cpp index 3c4b90b..58e9032 100644 --- a/src/view/common/view_logic_custom_header_support.cpp +++ b/src/view/common/view_logic_custom_header_support.cpp @@ -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 diff --git a/src/view/common/view_logic_custom_header_support.h b/src/view/common/view_logic_custom_header_support.h index 8b82b18..99ab3e9 100644 --- a/src/view/common/view_logic_custom_header_support.h +++ b/src/view/common/view_logic_custom_header_support.h @@ -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 diff --git a/src/view/webkit/bundles/bundle_uri_handling.cpp b/src/view/webkit/bundles/bundle_uri_handling.cpp index 9595dcf..9a9792e 100644 --- a/src/view/webkit/bundles/bundle_uri_handling.cpp +++ b/src/view/webkit/bundles/bundle_uri_handling.cpp @@ -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 uri(inputURI); if (uri.IsNull()) { diff --git a/src/view/webkit/bundles/wrt-wk2-bundle.cpp b/src/view/webkit/bundles/wrt-wk2-bundle.cpp index 1734762..763a4d9 100644 --- a/src/view/webkit/bundles/wrt-wk2-bundle.cpp +++ b/src/view/webkit/bundles/wrt-wk2-bundle.cpp @@ -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 localizedUrl = + DPL::Optional 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 localizedUrl = + DPL::Optional localizedUrl = BundleURIHandling::localizeURI(dplUrl, m_widgetTizenId); bool ret = BundleURIHandling::processURI( *localizedUrl, true, m_widgetTizenId, m_bundle); diff --git a/src/view/webkit/view_logic.cpp b/src/view/webkit/view_logic.cpp index 9cd73b2..41a3e63 100644 --- a/src/view/webkit/view_logic.cpp +++ b/src/view/webkit/view_logic.cpp @@ -170,15 +170,18 @@ std::mapdeinitialize(); - 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); } diff --git a/src/view/webkit/view_logic.h b/src/view/webkit/view_logic.h index 6c14862..a45e1f8 100644 --- a/src/view/webkit/view_logic.h +++ b/src/view/webkit/view_logic.h @@ -264,6 +264,7 @@ class ViewLogic : public ViewModule::IViewModule void windowClose(void); Ewk_Context* m_ewkContext; + bool m_attachedToCustomHandlerDao; std::list m_ewkViewList; Evas_Object* m_currentEwkView; Evas_Object* m_closedEwkView; @@ -283,7 +284,6 @@ class ViewLogic : public ViewModule::IViewModule std::unique_ptr m_appsSupport; std::unique_ptr m_vibrationSupport; std::unique_ptr m_securityOriginSupport; - bool m_attachedToCustomHandlerDao; static std::map m_ewkCallbacksMap; }; diff --git a/src/wrt-client/wrt-client.h b/src/wrt-client/wrt-client.h index 93f2d73..36a25f3 100644 --- a/src/wrt-client/wrt-client.h +++ b/src/wrt-client/wrt-client.h @@ -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; diff --git a/src/wrt-launchpad-daemon/launchpad_src/launchpad.c b/src/wrt-launchpad-daemon/launchpad_src/launchpad.c index ddf707c..484cc64 100644 --- a/src/wrt-launchpad-daemon/launchpad_src/launchpad.c +++ b/src/wrt-launchpad-daemon/launchpad_src/launchpad.c @@ -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*/ diff --git a/src/wrt-launchpad-daemon/launchpad_src/sigchild.h b/src/wrt-launchpad-daemon/launchpad_src/sigchild.h index d1e0214..6d30b65 100644 --- a/src/wrt-launchpad-daemon/launchpad_src/sigchild.h +++ b/src/wrt-launchpad-daemon/launchpad_src/sigchild.h @@ -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); diff --git a/src/wrt-launchpad-daemon/src/app_sock.c b/src/wrt-launchpad-daemon/src/app_sock.c index decce63..26edf9f 100644 --- a/src/wrt-launchpad-daemon/src/app_sock.c +++ b/src/wrt-launchpad-daemon/src/app_sock.c @@ -22,6 +22,8 @@ #include #include #include +#include + #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; diff --git a/src/wrt-launchpad-daemon/src/simple_util.c b/src/wrt-launchpad-daemon/src/simple_util.c index 4342efb..6f87ad4 100644 --- a/src/wrt-launchpad-daemon/src/simple_util.c +++ b/src/wrt-launchpad-daemon/src/simple_util.c @@ -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; } diff --git a/tests/widgets/common/src/InstallerWrapper.cpp b/tests/widgets/common/src/InstallerWrapper.cpp index 40e680e..505a01c 100644 --- a/tests/widgets/common/src/InstallerWrapper.cpp +++ b/tests/widgets/common/src/InstallerWrapper.cpp @@ -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; } -- 2.7.4