diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 22:13:19 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 22:13:19 +0000 |
commit | 3b68e8b7eaef2a5effac097fcd03b67d86501e72 (patch) | |
tree | d2778df7a7f93596f298818947ceaeb042821d8c /native_client_sdk | |
parent | cb2d19245f805d6c0acdce42f3b26757494427d1 (diff) | |
download | chromium_src-3b68e8b7eaef2a5effac097fcd03b67d86501e72.zip chromium_src-3b68e8b7eaef2a5effac097fcd03b67d86501e72.tar.gz chromium_src-3b68e8b7eaef2a5effac097fcd03b67d86501e72.tar.bz2 |
Fix PluginImageData and mouselock NaCl example:
- Fix the memory leak in PluginImageData.
- Fix the out-of-bound memory access in mouselock NaCl example.
BUG=106779
TEST=mouselock NaCl example won't crash after a while (~30 seconds).
Review URL: http://codereview.chromium.org/8872045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rw-r--r-- | native_client_sdk/src/examples/mouselock/mouselock.cc | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/native_client_sdk/src/examples/mouselock/mouselock.cc b/native_client_sdk/src/examples/mouselock/mouselock.cc index b0e18fd..af40043 100644 --- a/native_client_sdk/src/examples/mouselock/mouselock.cc +++ b/native_client_sdk/src/examples/mouselock/mouselock.cc @@ -10,6 +10,8 @@ #include <stdio.h> #include <string.h> +#include <algorithm> + // Indicate the direction of the mouse location relative to the center of the // view. These values are used to determine which 2D quadrant the needle lies // in. @@ -217,12 +219,14 @@ void MouseLockInstance::DrawCenterSpot(pp::ImageData* image, int center_y = image->size().height() / 2; int region_of_interest_radius = kCentralSpotRadius + 1; - for (int y = center_y - region_of_interest_radius; - y < center_y + region_of_interest_radius; - ++y) { - for (int x = center_x - region_of_interest_radius; - x < center_x + region_of_interest_radius; - ++x) { + pp::Point left_top(std::max(0, center_x - region_of_interest_radius), + std::max(0, center_y - region_of_interest_radius)); + pp::Point right_bottom(std::min(image->size().width(), + center_x + region_of_interest_radius), + std::min(image->size().height(), + center_y + region_of_interest_radius)); + for (int y = left_top.y(); y < right_bottom.y(); ++y) { + for (int x = left_top.x(); x < right_bottom.x(); ++x) { if (GetDistance(x, y, center_x, center_y) < kCentralSpotRadius) { *image->GetAddr32(pp::Point(x, y)) = spot_color; } @@ -269,8 +273,14 @@ void MouseLockInstance::DrawNeedle(pp::ImageData* image, anchor_1.swap(anchor_2); } - for (int y = center_y - abs_mouse_y; y < center_y + abs_mouse_y; ++y) { - for (int x = center_x - abs_mouse_x; x < center_x + abs_mouse_x; ++x) { + pp::Point left_top(std::max(0, center_x - abs_mouse_x), + std::max(0, center_y - abs_mouse_y)); + pp::Point right_bottom(std::min(image->size().width(), + center_x + abs_mouse_x), + std::min(image->size().height(), + center_y + abs_mouse_y)); + for (int y = left_top.y(); y < right_bottom.y(); ++y) { + for (int x = left_top.x(); x < right_bottom.x(); ++x) { bool within_bound_1 = ((y - anchor_1.y()) * (vertex.x() - anchor_1.x())) > ((vertex.y() - anchor_1.y()) * (x - anchor_1.x())); |