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

Side by Side Diff: src/plugin/PluginSystem.cpp

Issue 6237450183639040: Issue 1283 - wrong usage of memset, fix sizeof, make proper initializing (Closed)
Patch Set: Created Sept. 1, 2014, 11:52 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2
3 #include "PluginSystem.h" 2 #include "PluginSystem.h"
4 #include "PluginClient.h" 3 #include "PluginClient.h"
4 #include <array>
5 5
6 std::wstring GetBrowserLanguage() 6 std::wstring GetBrowserLanguage()
7 { 7 {
8 LANGID lcid = GetUserDefaultLangID(); 8 LANGID lcid = GetUserDefaultLangID();
9 wchar_t language[128];
10 memset(language, 0, sizeof(language));
11 wchar_t country[128];
12 memset(language, 0, sizeof(country));
13
14 std::wstring lang; 9 std::wstring lang;
15 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, language, 127); 10 // we use `size() - 1` here to avoid additional calls to get the required size or to get the
16 if (res == 0) 11 // number of retrieved characters.
17 { 12 {
18 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO _BROWSER_LANGUAGE, "System::GetBrowserLang - Failed"); 13 std::array<wchar_t, 128> localeLanguage;
Eric 2014/09/26 18:07:23 The actual buffer size we need, both here for lang
19 } 14 localeLanguage.fill(L'\0');
20 else 15 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, localeLanguage.data() , localeLanguage.size() - 1);
21 { 16 if (res == 0)
22 lang += language; 17 {
18 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed");
19 }
20 else
21 {
22 lang += localeLanguage.data();
23 }
23 } 24 }
24 lang += L"-"; 25 lang += L"-";
25 res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, country, 127);
26 if (res == 0)
27 { 26 {
28 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO _BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country"); 27 std::array<wchar_t, 128> localeCountry;
29 } 28 localeCountry.fill(L'\0');
30 else 29 int res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, localeCountry.data() , localeCountry.size() - 1);
31 { 30 if (res == 0)
32 lang += country; 31 {
32 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country");
33 }
34 else
35 {
36 lang += localeCountry.data();
37 }
33 } 38 }
34 return lang; 39 return lang;
35 } 40 }
OLDNEW

Powered by Google App Engine
This is Rietveld