diff options
author | Siarhei Vishniakou <svv@google.com> | 2019-02-28 08:16:26 -0800 |
---|---|---|
committer | Siarhei Vishniakou <svv@google.com> | 2019-04-18 15:56:39 -0700 |
commit | d59b2d06a47527384ed64a2a068c52e3f35b7990 (patch) | |
tree | e9e0d94ec310a94c65f8252db63da430da32a0eb | |
parent | 22a3ef220a63a82e5fbef8aa53b6a67e7d03ff6b (diff) | |
download | native-d59b2d06a47527384ed64a2a068c52e3f35b7990.tar.gz |
Initialize PointerCoords in input tests
The struct PointerCoords in VelocityTracker_test is created on the
stack, but never initialized. Later, the coords are used to add an x and
y value to the MotionEvent.
The field "bits" in the struct is therefore initialized to whatever was
previously occupying that stack address.
It is possible that stack contained some non-zero data. This would cause
enough of the bits of the 'bits' variable to be set, but without any of
them being X or Y. As a result, when a new X or Y value is assigned, it
does not fit into the bits (there's a 30-axes limit), and therefore
remains at zero.
Later, when velocity is computed, the coordinates evaluate to zero, and
therefore, zero velocity is produced. The test fails, because a non-zero
velocity is expected.
After an audit of the entire Android codebase for usage of
PointerCoords, found another potential issue in InputClassifier_test.
Likely the code was copied over from VelocityTracker_test. Add a fix for
that as well.
Bug: 126536349
Test: atest -it -a libinput_tests, but only executed after building and
flashing asanified libinput and libinput_tests onto device.
Change-Id: Id8b870b6201d7489284bf9fc646750770bb9321a
Merged-In: Id8b870b6201d7489284bf9fc646750770bb9321a
-rw-r--r-- | libs/input/tests/VelocityTracker_test.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libs/input/tests/VelocityTracker_test.cpp b/libs/input/tests/VelocityTracker_test.cpp index 9da2e2a315..56d5de4314 100644 --- a/libs/input/tests/VelocityTracker_test.cpp +++ b/libs/input/tests/VelocityTracker_test.cpp @@ -88,7 +88,9 @@ MotionEvent* createSimpleMotionEvent(const Position* positions, size_t numSample MotionEvent* event = new MotionEvent(); PointerCoords coords; - PointerProperties properties[1]; + coords.clear(); + constexpr size_t pointerCount = 1; + PointerProperties properties[pointerCount]; properties[0].id = DEFAULT_POINTER_ID; properties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; @@ -97,7 +99,7 @@ MotionEvent* createSimpleMotionEvent(const Position* positions, size_t numSample coords.setAxisValue(AMOTION_EVENT_AXIS_X, positions[0].x); coords.setAxisValue(AMOTION_EVENT_AXIS_Y, positions[0].y); event->initialize(0, AINPUT_SOURCE_TOUCHSCREEN, AMOTION_EVENT_ACTION_MOVE, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, positions[0].time, 1, properties, &coords); + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, positions[0].time, pointerCount, properties, &coords); for (size_t i = 1; i < numSamples; i++) { coords.setAxisValue(AMOTION_EVENT_AXIS_X, positions[i].x); |