diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-21 23:10:26 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-21 23:10:26 +0000 |
commit | 60400404e23d6bc456071fc5acaf29c7b6bf550a (patch) | |
tree | b5bebffd3c958601033e5224f30c1d7c039cfbc3 | |
parent | f11f0de7f3e245d49f651423907f2c813a84ee6a (diff) | |
download | chromium_src-60400404e23d6bc456071fc5acaf29c7b6bf550a.zip chromium_src-60400404e23d6bc456071fc5acaf29c7b6bf550a.tar.gz chromium_src-60400404e23d6bc456071fc5acaf29c7b6bf550a.tar.bz2 |
Coverity: Convert dll_path_ to a std::wstring. This avoids having dll_path_ uninitialized after the object is constructed.
CID=1632
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/306037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29730 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chrome_exe_main.cc | 7 | ||||
-rw-r--r-- | chrome/app/client_util.cc | 13 | ||||
-rw-r--r-- | chrome/app/client_util.h | 6 | ||||
-rw-r--r-- | chrome/app/google_update_client.cc | 8 | ||||
-rw-r--r-- | chrome/app/google_update_client.h | 2 |
5 files changed, 20 insertions, 16 deletions
diff --git a/chrome/app/chrome_exe_main.cc b/chrome/app/chrome_exe_main.cc index a0899e6..33fc669 100644 --- a/chrome/app/chrome_exe_main.cc +++ b/chrome/app/chrome_exe_main.cc @@ -58,10 +58,9 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance, dll_full_path = client.GetDLLFullPath(); versionned_path = client.GetDLLPath(); #else - wchar_t exe_path[MAX_PATH] = {0}; - client_util::GetExecutablePath(exe_path); + std::wstring exe_path = client_util::GetExecutablePath(); wchar_t *version; - if (client_util::GetChromiumVersion(exe_path, L"Software\\Chromium", + if (client_util::GetChromiumVersion(exe_path.c_str(), L"Software\\Chromium", &version)) { versionned_path = exe_path; versionned_path.append(version); @@ -72,7 +71,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance, #endif // If the versionned path exists, we set the current directory to this path. - if (client_util::FileExists(versionned_path.c_str())) { + if (client_util::FileExists(versionned_path)) { ::SetCurrentDirectory(versionned_path.c_str()); } diff --git a/chrome/app/client_util.cc b/chrome/app/client_util.cc index 93cbdcd..0fd1c94 100644 --- a/chrome/app/client_util.cc +++ b/chrome/app/client_util.cc @@ -31,9 +31,10 @@ bool ReadStrValueFromRegistry(const HKEY reg_key, } namespace client_util { -bool FileExists(const wchar_t* const file_path) { +bool FileExists(const std::wstring& file_path) { WIN32_FILE_ATTRIBUTE_DATA attrs; - return ::GetFileAttributesEx(file_path, GetFileExInfoStandard, &attrs) != 0; + return ::GetFileAttributesEx( + file_path.c_str(), GetFileExInfoStandard, &attrs) != 0; } bool GetChromiumVersion(const wchar_t* const exe_path, @@ -49,7 +50,7 @@ bool GetChromiumVersion(const wchar_t* const exe_path, std::wstring new_chrome_exe(exe_path); new_chrome_exe.append(installer_util::kChromeNewExe); - if (FileExists(new_chrome_exe.c_str()) && + if (FileExists(new_chrome_exe) && ReadStrValueFromRegistry(reg_key, google_update::kRegOldVersionField, version)) { ::RegCloseKey(reg_key); @@ -65,7 +66,7 @@ bool GetChromiumVersion(const wchar_t* const exe_path, std::wstring GetDLLPath(const std::wstring& dll_name, const std::wstring& dll_path) { - if (!dll_path.empty() && FileExists(dll_path.c_str())) + if (!dll_path.empty() && FileExists(dll_path)) return dll_path + L"\\" + dll_name; // This is not an official build. Find the dll using the default @@ -80,7 +81,8 @@ std::wstring GetDLLPath(const std::wstring& dll_name, return path; } -void GetExecutablePath(wchar_t* exe_path) { +std::wstring GetExecutablePath() { + wchar_t exe_path[MAX_PATH]; DWORD len = ::GetModuleFileName(NULL, exe_path, MAX_PATH); wchar_t* tmp = exe_path + len - 1; while (tmp >= exe_path && *tmp != L'\\') @@ -89,6 +91,7 @@ void GetExecutablePath(wchar_t* exe_path) { tmp++; *tmp = 0; } + return exe_path; } } // namespace client_util diff --git a/chrome/app/client_util.h b/chrome/app/client_util.h index 2821c1d..b3ab7e7 100644 --- a/chrome/app/client_util.h +++ b/chrome/app/client_util.h @@ -21,7 +21,7 @@ typedef int (*DLL_MAIN)(HINSTANCE instance, sandbox::SandboxInterfaceInfo*, extern const wchar_t kProductVersionKey[]; // Returns true if file specified by file_path exists -bool FileExists(const wchar_t* const file_path); +bool FileExists(const std::wstring& file_path); // Returns Chromium version after reading it from reg_key registry key. Uses // exe_path to detemine registry root key (HKLM/HKCU). Note it is the @@ -37,8 +37,8 @@ std::wstring GetDLLPath(const std::wstring& dll_name, const std::wstring& dll_path); // Returns the path to the exe (without the file name) that called this -// function. The buffer should already be allocated (ideally of MAX_PATH size). -void GetExecutablePath(wchar_t* exe_path); +// function. +std::wstring GetExecutablePath(); } // namespace client_util diff --git a/chrome/app/google_update_client.cc b/chrome/app/google_update_client.cc index 1906004..3194f65 100644 --- a/chrome/app/google_update_client.cc +++ b/chrome/app/google_update_client.cc @@ -109,7 +109,7 @@ bool GoogleUpdateClient::Launch(HINSTANCE instance, bool GoogleUpdateClient::Init(const wchar_t* client_guid, const wchar_t* client_dll) { - client_util::GetExecutablePath(dll_path_); + dll_path_ = client_util::GetExecutablePath(); guid_.assign(client_guid); dll_.assign(client_dll); bool ret = false; @@ -120,13 +120,15 @@ bool GoogleUpdateClient::Init(const wchar_t* client_guid, } else { std::wstring key(google_update::kRegPathClients); key.append(L"\\" + guid_); - if (client_util::GetChromiumVersion(dll_path_, key.c_str(), &version_)) + if (client_util::GetChromiumVersion(dll_path_.c_str(), + key.c_str(), + &version_)) ret = true; } } if (version_) { - ::StringCchCat(dll_path_, MAX_PATH, version_); + dll_path_.append(version_); } return ret; } diff --git a/chrome/app/google_update_client.h b/chrome/app/google_update_client.h index 7d063f3..82f7d43 100644 --- a/chrome/app/google_update_client.h +++ b/chrome/app/google_update_client.h @@ -73,7 +73,7 @@ class GoogleUpdateClient { // The current version of this client registered with GoogleUpdate. wchar_t* version_; // The location of current chrome.dll. - wchar_t dll_path_[MAX_PATH]; + std::wstring dll_path_; }; } // namespace google_update |