Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: components/translate/core/language_detection/language_detection_util.cc

Issue 1964823003: Initialize CLD score/language arrays prior to use, for pedantic safety. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/translate/core/language_detection/language_detection_util.h " 5 #include "components/translate/core/language_detection/language_detection_util.h "
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 const bool is_plain_text = true; 79 const bool is_plain_text = true;
80 80
81 // Language or CLD2::Language 81 // Language or CLD2::Language
82 int cld_language = 0; 82 int cld_language = 0;
83 bool is_valid_language = false; 83 bool is_valid_language = false;
84 84
85 const std::string utf8_text(base::UTF16ToUTF8(text)); 85 const std::string utf8_text(base::UTF16ToUTF8(text));
86 const int num_utf8_bytes = static_cast<int>(utf8_text.size()); 86 const int num_utf8_bytes = static_cast<int>(utf8_text.size());
87 const char* raw_utf8_bytes = utf8_text.c_str(); 87 const char* raw_utf8_bytes = utf8_text.c_str();
88 88
89 CLD2::Language language3[3]; 89 CLD2::Language language3[3] = {
90 int percent3[3]; 90 CLD2::UNKNOWN_LANGUAGE, CLD2::UNKNOWN_LANGUAGE, CLD2::UNKNOWN_LANGUAGE};
91 int percent3[3] = {0, 0, 0};
91 int flags = 0; // No flags, see compact_lang_det.h for details. 92 int flags = 0; // No flags, see compact_lang_det.h for details.
92 int text_bytes; // Amount of non-tag/letters-only text (assumed 0). 93 int text_bytes; // Amount of non-tag/letters-only text (assumed 0).
93 double normalized_score3[3]; 94 double normalized_score3[3] = {0, 0, 0};
Takashi Toyoshima 2016/05/11 06:08:50 0.0 is better for double?
94 95
95 const char* tld_hint = ""; 96 const char* tld_hint = "";
96 int encoding_hint = CLD2::UNKNOWN_ENCODING; 97 int encoding_hint = CLD2::UNKNOWN_ENCODING;
97 CLD2::Language language_hint = CLD2::GetLanguageFromName(html_lang.c_str()); 98 CLD2::Language language_hint = CLD2::GetLanguageFromName(html_lang.c_str());
98 CLD2::CLDHints cldhints = {code.c_str(), tld_hint, encoding_hint, 99 CLD2::CLDHints cldhints = {code.c_str(), tld_hint, encoding_hint,
99 language_hint}; 100 language_hint};
100 101
101 CLD2::ExtDetectLanguageSummaryCheckUTF8( 102 CLD2::ExtDetectLanguageSummaryCheckUTF8(
102 raw_utf8_bytes, num_utf8_bytes, is_plain_text, &cldhints, flags, 103 raw_utf8_bytes, num_utf8_bytes, is_plain_text, &cldhints, flags,
103 language3, percent3, normalized_score3, 104 language3, percent3, normalized_score3,
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // distinguish from English, and the language is one of well-known languages 367 // distinguish from English, and the language is one of well-known languages
367 // which often provide "en-*" meta information mistakenly. 368 // which often provide "en-*" meta information mistakenly.
368 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { 369 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) {
369 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) 370 if (cld_language == kWellKnownCodesOnWrongConfiguration[i])
370 return true; 371 return true;
371 } 372 }
372 return false; 373 return false;
373 } 374 }
374 375
375 } // namespace translate 376 } // namespace translate
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698