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

Delta Between Two Patch Sets: src/plugin/PluginSystem.cpp

Issue 5163581322559488: Issue 1283 - wrong usage of memset, fix sizeof, make proper initializing (Closed)
Left Patch Set: Created Oct. 8, 2014, 2:49 p.m.
Right Patch Set: remove intializating call Created Oct. 13, 2014, 9:47 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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 // According to http://msdn.microsoft.com/en-us/library/windows/desktop/dd3738 48(v=vs.85).aspx
16 if (res == 0) 11 // The maximum number of characters allowed for this string is nine, including a terminating null character.
17 { 12 {
18 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO _BROWSER_LANGUAGE, "System::GetBrowserLang - Failed"); 13 std::array<wchar_t, 9> localeLanguage;
19 } 14 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, localeLanguage.data() , localeLanguage.size());
Oleksandr 2014/10/17 07:09:07 We could use std::wstring for localeLanguage here
20 else 15 if (res == 0)
21 { 16 {
22 lang += language; 17 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed");
18 }
19 else
20 {
21 lang += localeLanguage.data();
22 }
23 } 23 }
24 lang += L"-"; 24 lang += L"-";
25 res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, country, 127);
26 if (res == 0)
27 { 25 {
28 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO _BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country"); 26 std::array<wchar_t, 9> localeCountry;
29 } 27 int res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, localeCountry.data() , localeCountry.size());
30 else 28 if (res == 0)
31 { 29 {
32 lang += country; 30 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country");
31 }
32 else
33 {
34 lang += localeCountry.data();
35 }
33 } 36 }
34 return lang; 37 return lang;
35 } 38 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld