Commit 9160e2aa authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Fixes memory alignment issues due to browser_theme_pack changes.

Bug=141522
Test=No more Arm crash reports

Review URL: https://chromiumcodereview.appspot.com/10854074

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151090 0039d316-1c4b-4281-b951-d872f2087c98
parent aaec1bcc
...@@ -188,32 +188,30 @@ int GetPersistentIDByIDR(int idr) { ...@@ -188,32 +188,30 @@ int GetPersistentIDByIDR(int idr) {
// Returns true if the scales in |input| match those in |expected|. // Returns true if the scales in |input| match those in |expected|.
// The order must match as the index is used in determining the raw id. // The order must match as the index is used in determining the raw id.
bool InputScalesValid(const char* input, bool InputScalesValid(const base::StringPiece& input,
const std::vector<ui::ScaleFactor>& expected) { const std::vector<ui::ScaleFactor>& expected) {
const float* scales = reinterpret_cast<const float*>(input); size_t scales_size = static_cast<size_t>(input.size() / sizeof(float));
size_t index = 0; if (scales_size != expected.size())
for (const float* end = scales; *end != -1.0f; ++end) {
if (index >= expected.size())
return false; return false;
if (*end != ui::GetScaleFactorScale(expected[index])) scoped_array<float> scales(new float[scales_size]);
// Do a memcpy to avoid misaligned memory access.
memcpy(scales.get(), input.data(), input.size());
for (size_t index = 0; index < scales_size; ++index) {
if (scales[index] != ui::GetScaleFactorScale(expected[index]))
return false; return false;
index++;
} }
return (index == expected.size()); return true;
} }
// Returns |scale_factors| as a string to be written to disk. // Returns |scale_factors| as a string to be written to disk.
std::string GetScaleFactorsAsString( std::string GetScaleFactorsAsString(
const std::vector<ui::ScaleFactor>& scale_factors) { const std::vector<ui::ScaleFactor>& scale_factors) {
size_t scales_size = scale_factors.size() + 1; scoped_array<float> scales(new float[scale_factors.size()]);
float* scales = new float[scales_size];
for (size_t i = 0; i < scale_factors.size(); ++i) for (size_t i = 0; i < scale_factors.size(); ++i)
scales[i] = ui::GetScaleFactorScale(scale_factors[i]); scales[i] = ui::GetScaleFactorScale(scale_factors[i]);
scales[scales_size - 1] = -1.0f;
std::string out_string = std::string( std::string out_string = std::string(
reinterpret_cast<const char*>(scales), reinterpret_cast<const char*>(scales.get()),
scales_size * sizeof(float)); scale_factors.size() * sizeof(float));
delete[] scales;
return out_string; return out_string;
} }
...@@ -508,12 +506,10 @@ scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack( ...@@ -508,12 +506,10 @@ scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack(
if (!pack->data_pack_->GetStringPiece(kScaleFactorsID, &pointer)) if (!pack->data_pack_->GetStringPiece(kScaleFactorsID, &pointer))
return NULL; return NULL;
if (!InputScalesValid(const_cast<char*>(pointer.data()), if (!InputScalesValid(pointer, pack->scale_factors_)) {
pack->scale_factors_)) {
DLOG(ERROR) << "BuildFromDataPack failure! The pack scale factors differ " DLOG(ERROR) << "BuildFromDataPack failure! The pack scale factors differ "
<< "from those supported by platform."; << "from those supported by platform.";
} }
return pack; return pack;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment