Chromium Code Reviews| Index: chrome/browser/themes/browser_theme_pack.cc |
| diff --git a/chrome/browser/themes/browser_theme_pack.cc b/chrome/browser/themes/browser_theme_pack.cc |
| index fef23f27ec18bea770f6eeb19355a40bb3f70292..51b3365978aef0e08ef66319b0f8fb7a4be5e81d 100644 |
| --- a/chrome/browser/themes/browser_theme_pack.cc |
| +++ b/chrome/browser/themes/browser_theme_pack.cc |
| @@ -188,31 +188,32 @@ int GetPersistentIDByIDR(int idr) { |
| // 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. |
| -bool InputScalesValid(const char* input, |
| +bool InputScalesValid(const base::StringPiece& input, |
| 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(char) / sizeof(float)); |
|
benrg
2012/08/09 21:45:10
Either don't multiply by sizeof(char) here or else
|
| + float* scales = new float[scales_size]; |
|
sky
2012/08/09 19:49:17
scoped_array here and 211 (200/202 leak the way yo
benrg
2012/08/09 21:45:10
I think there should be a comment explaining why t
|
| + memcpy(scales, input.data(), input.size()); |
| size_t index = 0; |
| - for (const float* end = scales; *end != -1.0f; ++end) { |
| + for (; index < scales_size; ++index) { |
| if (index >= expected.size()) |
|
benrg
2012/08/09 21:45:10
It would be slightly simpler to check scales_size
|
| return false; |
| - if (*end != ui::GetScaleFactorScale(expected[index])) |
| + if (scales[index] != ui::GetScaleFactorScale(expected[index])) |
| return false; |
| - index++; |
| } |
| + delete[] scales; |
| return (index == expected.size()); |
| } |
| // Returns |scale_factors| as a string to be written to disk. |
| std::string GetScaleFactorsAsString( |
| const std::vector<ui::ScaleFactor>& scale_factors) { |
| - size_t scales_size = scale_factors.size() + 1; |
| - float* scales = new float[scales_size]; |
| + float* scales = new float[scale_factors.size()]; |
| for (size_t i = 0; i < scale_factors.size(); ++i) |
| scales[i] = ui::GetScaleFactorScale(scale_factors[i]); |
| - scales[scales_size - 1] = -1.0f; |
| std::string out_string = std::string( |
| reinterpret_cast<const char*>(scales), |
| - scales_size * sizeof(float)); |
| + scale_factors.size() * sizeof(float)); |
| delete[] scales; |
| return out_string; |
| } |
| @@ -508,12 +509,10 @@ scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack( |
| if (!pack->data_pack_->GetStringPiece(kScaleFactorsID, &pointer)) |
| return NULL; |
| - if (!InputScalesValid(const_cast<char*>(pointer.data()), |
| - pack->scale_factors_)) { |
| + if (!InputScalesValid(pointer, pack->scale_factors_)) { |
| DLOG(ERROR) << "BuildFromDataPack failure! The pack scale factors differ " |
| << "from those supported by platform."; |
| } |
| - |
| return pack; |
| } |