Chromium Code Reviews| Index: cc/resources/resource.h |
| diff --git a/cc/resources/resource.h b/cc/resources/resource.h |
| index 0e3c3df688387b9ee927f150737bc8dd37a7a6b7..06893fe32749dad1a8d960302dcd80347b065316 100644 |
| --- a/cc/resources/resource.h |
| +++ b/cc/resources/resource.h |
| @@ -5,6 +5,7 @@ |
| #ifndef CC_RESOURCES_RESOURCE_H_ |
| #define CC_RESOURCES_RESOURCE_H_ |
| +#include "base/numerics/safe_math.h" |
| #include "cc/base/cc_export.h" |
| #include "cc/resources/resource_provider.h" |
| #include "ui/gfx/geometry/size.h" |
| @@ -27,9 +28,11 @@ class CC_EXPORT Resource { |
| inline static size_t MemorySizeBytes(const gfx::Size& size, |
| ResourceFormat format) { |
| DCHECK_EQ(0, (BitsPerPixel(format) * size.width() * size.height()) % 8); |
| - // TODO(vmpstr): Make this function overflow safe. crbug.com/495867 |
| - return static_cast<size_t>( |
| - (BitsPerPixel(format) * size.width() * size.height()) / 8); |
| + base::CheckedNumeric<size_t> result = BitsPerPixel(format); |
| + result *= size.width(); |
| + result *= size.height(); |
| + result /= 8; |
| + return result.ValueOrDie(); |
|
danakj
2015/06/04 19:02:38
This would work, but looking at the callsites of M
|
| } |
| protected: |