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

Side by Side Diff: components/signin/core/browser/account_info.cc

Issue 1588913002: Fix AccountInfo uninitialized memory issues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Explicit default value to false Created 4 years, 11 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 | components/signin/core/browser/account_info_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/signin/core/browser/account_info.h" 5 #include "components/signin/core/browser/account_info.h"
6 6
7 namespace { 7 namespace {
8 8
9 bool UpdateField(std::string* field, const std::string& new_value) { 9 bool UpdateField(std::string* field, const std::string& new_value) {
10 bool should_update = field->empty() && !new_value.empty(); 10 bool should_update = field->empty() && !new_value.empty();
11 if (should_update) 11 if (should_update)
12 *field = new_value; 12 *field = new_value;
13 return should_update; 13 return should_update;
14 } 14 }
15 15
16 bool UpdateField(bool* field, bool new_value) { 16 bool UpdateField(bool* field, bool new_value) {
17 bool should_update = !*field && new_value; 17 bool should_update = !*field && new_value;
18 if (should_update) 18 if (should_update)
19 *field = new_value; 19 *field = new_value;
20 return should_update; 20 return should_update;
21 } 21 }
22 } 22 }
23 23
24 AccountInfo::AccountInfo() {} 24 AccountInfo::AccountInfo()
25 : account_id(),
26 gaia(),
27 email(),
28 full_name(),
29 given_name(),
30 hosted_domain(),
31 locale(),
32 picture_url(),
33 is_child_account(false) {}
25 AccountInfo::~AccountInfo() {} 34 AccountInfo::~AccountInfo() {}
26 35
27 bool AccountInfo::IsValid() const { 36 bool AccountInfo::IsValid() const {
28 return !account_id.empty() && !email.empty() && !gaia.empty() && 37 return !account_id.empty() && !email.empty() && !gaia.empty() &&
29 !hosted_domain.empty() && !full_name.empty() && !given_name.empty() && 38 !hosted_domain.empty() && !full_name.empty() && !given_name.empty() &&
30 !locale.empty() && !picture_url.empty(); 39 !locale.empty() && !picture_url.empty();
31 } 40 }
32 41
33 bool AccountInfo::UpdateWith(const AccountInfo& other) { 42 bool AccountInfo::UpdateWith(const AccountInfo& other) {
34 if (account_id != other.account_id) { 43 if (account_id != other.account_id) {
35 // Only updates with a compatible AccountInfo. 44 // Only updates with a compatible AccountInfo.
36 return false; 45 return false;
37 } 46 }
38 47
39 bool modified = UpdateField(&gaia, other.gaia); 48 bool modified = UpdateField(&gaia, other.gaia);
40 modified |= UpdateField(&email, other.email); 49 modified |= UpdateField(&email, other.email);
41 modified |= UpdateField(&full_name, other.full_name); 50 modified |= UpdateField(&full_name, other.full_name);
42 modified |= UpdateField(&given_name, other.given_name); 51 modified |= UpdateField(&given_name, other.given_name);
43 modified |= UpdateField(&hosted_domain, other.hosted_domain); 52 modified |= UpdateField(&hosted_domain, other.hosted_domain);
44 modified |= UpdateField(&locale, other.locale); 53 modified |= UpdateField(&locale, other.locale);
45 modified |= UpdateField(&picture_url, other.picture_url); 54 modified |= UpdateField(&picture_url, other.picture_url);
46 modified |= UpdateField(&is_child_account, other.is_child_account); 55 modified |= UpdateField(&is_child_account, other.is_child_account);
47 56
48 return modified; 57 return modified;
49 } 58 }
OLDNEW
« no previous file with comments | « no previous file | components/signin/core/browser/account_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698