From 6e556d4a71d3c9cc5982902d04d15f000e128d20 Mon Sep 17 00:00:00 2001 From: Andreas Falkenhahn Date: Sun, 7 Jul 2019 03:27:30 +0200 Subject: [PATCH] Check parameters of XYToPosition() and PositionToXY() in wxSTC too For consistency with wxTextCtrl, return -1 if input parameters are out of range. Closes #18430. --- include/wx/stc/stc.h | 12 +++++++++++- src/stc/stc.h.in | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index 94ce11aa2c..294c693e83 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -5376,6 +5376,12 @@ public: virtual long XYToPosition(long x, long y) const wxOVERRIDE { long pos = PositionFromLine((int)y); + if ( pos == -1 ) + return -1; + + if ( x >= LineLength(y) ) + return -1; + pos += x; return pos; } @@ -5386,8 +5392,12 @@ public: if ( l == -1 ) return false; + int lx = pos - PositionFromLine(l); + if ( lx >= LineLength(l) ) + return false; + if ( x ) - *x = pos - PositionFromLine(l); + *x = lx; if ( y ) *y = l; diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index ea04d4f60c..5fdc401d75 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -493,6 +493,12 @@ public: virtual long XYToPosition(long x, long y) const wxOVERRIDE { long pos = PositionFromLine((int)y); + if ( pos == -1 ) + return -1; + + if ( x >= LineLength(y) ) + return -1; + pos += x; return pos; } @@ -503,8 +509,12 @@ public: if ( l == -1 ) return false; + int lx = pos - PositionFromLine(l); + if ( lx >= LineLength(l) ) + return false; + if ( x ) - *x = pos - PositionFromLine(l); + *x = lx; if ( y ) *y = l;