Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginSystem.cpp

Issue 5163581322559488: Issue 1283 - wrong usage of memset, fix sizeof, make proper initializing (Closed)
Patch Set: Created Oct. 8, 2014, 2:49 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/plugin/PluginSettings.cpp ('k') | src/shared/Communication.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginSystem.cpp
===================================================================
--- a/src/plugin/PluginSystem.cpp
+++ b/src/plugin/PluginSystem.cpp
@@ -1,40 +1,35 @@
#include "PluginStdAfx.h"
+
#include "PluginSystem.h"
#include "PluginClient.h"
-#include <array>
std::wstring GetBrowserLanguage()
{
LANGID lcid = GetUserDefaultLangID();
+ wchar_t language[128];
+ memset(language, 0, sizeof(language));
+ wchar_t country[128];
+ memset(language, 0, sizeof(country));
+
std::wstring lang;
- // we use `size() - 1` here to avoid additional calls to get the required size or to get the
- // number of retrieved characters.
+ int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, language, 127);
+ if (res == 0)
{
- std::array<wchar_t, 9> localeLanguage;
- localeLanguage.fill(L'\0');
- int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, localeLanguage.data(), localeLanguage.size() - 1);
- if (res == 0)
- {
- DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed");
- }
- else
- {
- lang += localeLanguage.data();
- }
+ DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed");
+ }
+ else
+ {
+ lang += language;
}
lang += L"-";
+ res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, country, 127);
+ if (res == 0)
{
- std::array<wchar_t, 9> localeCountry;
- localeCountry.fill(L'\0');
- int res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, localeCountry.data(), localeCountry.size() - 1);
- if (res == 0)
- {
- DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country");
- }
- else
- {
- lang += localeCountry.data();
- }
+ DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country");
+ }
+ else
+ {
+ lang += country;
}
return lang;
}
« no previous file with comments | « src/plugin/PluginSettings.cpp ('k') | src/shared/Communication.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld