Skip to content

Commit 9ca863e

Browse files
committed
Fix out of bounds crash in TouchCypress
1 parent 19ec2c8 commit 9ca863e

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/features/touchscreen/touchCypress/TouchCypress.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,10 @@ bool Touch::getTouchData(struct cypressTouchData *_touchData)
341341
_touchData->y[1] = _regs[11] << 8 | _regs[12];
342342
_touchData->z[1] = _regs[13];
343343
_touchData->detectionType = _regs[8];
344-
_touchData->fingers = _regs[2];
344+
345+
// Hardware can report spurious high finger counts (e.g. when palm-swiping).
346+
// Clamp to 2 — the maximum the controller and all callers' arrays support.
347+
_touchData->fingers = (_regs[2] > 2) ? 2 : _regs[2];
345348

346349
// Everything went ok? Return true.
347350
return true;

0 commit comments

Comments
 (0)