Check that number of points passed to wxDC::DrawSpline() is at least 2

DoDrawSpline() implementations for all ports work for the number of points
>= 2 (for 2 points there is drawn a straight line) so we need to add checks
whether this requirement is met.

See #19172.
This commit is contained in:
Artur Wieczorek
2021-06-30 22:20:39 +02:00
parent a3988c8db6
commit b35d595e5d
6 changed files with 12 additions and 11 deletions

View File

@@ -714,7 +714,7 @@ public:
/** /**
Draws a spline between all given points using the current pen. Draws a spline between all given points using the current pen.
The number of points must be at least 3 for the spline to be drawn. The number of points must be at least 2 for the spline to be drawn.
@beginWxPerlOnly @beginWxPerlOnly
Not supported by wxPerl. Not supported by wxPerl.

View File

@@ -903,16 +903,14 @@ static void wx_spline_draw_point_array(wxDC *dc)
void wxDCImpl::DoDrawSpline( const wxPointList *points ) void wxDCImpl::DoDrawSpline( const wxPointList *points )
{ {
wxCHECK_RET( IsOk(), wxT("invalid window dc") ); wxCHECK_RET( IsOk(), wxT("invalid window dc") );
wxCHECK_RET(points, "NULL pointer to spline points?");
wxCHECK_RET(points->GetCount() >= 2, "incomplete list of spline points?");
const wxPoint *p; const wxPoint *p;
double cx1, cy1, cx2, cy2; double cx1, cy1, cx2, cy2;
double x1, y1, x2, y2; double x1, y1, x2, y2;
wxPointList::compatibility_iterator node = points->GetFirst(); wxPointList::compatibility_iterator node = points->GetFirst();
if (!node)
// empty list
return;
p = node->GetData(); p = node->GetData();
x1 = p->x; x1 = p->x;

View File

@@ -846,6 +846,8 @@ void wxGCDCImpl::DoDrawLines(int n, const wxPoint points[],
void wxGCDCImpl::DoDrawSpline(const wxPointList *points) void wxGCDCImpl::DoDrawSpline(const wxPointList *points)
{ {
wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") ); wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
wxCHECK_RET(points, "NULL pointer to spline points?");
wxCHECK_RET(points->GetCount() >= 2, "incomplete list of spline points?");
if ( !m_logicalFunctionSupported ) if ( !m_logicalFunctionSupported )
return; return;
@@ -853,10 +855,6 @@ void wxGCDCImpl::DoDrawSpline(const wxPointList *points)
wxGraphicsPath path = m_graphicContext->CreatePath(); wxGraphicsPath path = m_graphicContext->CreatePath();
wxPointList::compatibility_iterator node = points->GetFirst(); wxPointList::compatibility_iterator node = points->GetFirst();
if ( !node )
// empty list
return;
const wxPoint *p = node->GetData(); const wxPoint *p = node->GetData();
wxCoord x1 = p->x; wxCoord x1 = p->x;

View File

@@ -1463,6 +1463,8 @@ void wxPostScriptDCImpl::SetLogicalFunction(wxRasterOperationMode WXUNUSED(funct
void wxPostScriptDCImpl::DoDrawSpline( const wxPointList *points ) void wxPostScriptDCImpl::DoDrawSpline( const wxPointList *points )
{ {
wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
wxCHECK_RET(points, "NULL pointer to spline points?");
wxCHECK_RET(points->GetCount() >= 2, "incomplete list of spline points?");
SetPen( m_pen ); SetPen( m_pen );

View File

@@ -1716,6 +1716,9 @@ void wxGtkPrinterDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCo
#if wxUSE_SPLINES #if wxUSE_SPLINES
void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList *points) void wxGtkPrinterDCImpl::DoDrawSpline(const wxPointList *points)
{ {
wxCHECK_RET(points, "NULL pointer to spline points?");
wxCHECK_RET(points->GetCount() >= 2, "incomplete list of spline points?");
SetPen (m_pen); SetPen (m_pen);
double c, d, x1, y1, x3, y3; double c, d, x1, y1, x3, y3;

View File

@@ -1158,10 +1158,10 @@ void wxMSWDCImpl::DoDrawSpline(const wxPointList *points)
// B2 = (2*P1 + P2)/3 // B2 = (2*P1 + P2)/3
// B3 = P2 // B3 = P2
wxASSERT_MSG( points, wxT("NULL pointer to spline points?") ); wxCHECK_RET( points, "NULL pointer to spline points?" );
const size_t n_points = points->GetCount(); const size_t n_points = points->GetCount();
wxASSERT_MSG( n_points > 2 , wxT("incomplete list of spline points?") ); wxCHECK_RET( n_points >= 2 , "incomplete list of spline points?" );
const size_t n_bezier_points = n_points * 3 + 1; const size_t n_bezier_points = n_points * 3 + 1;
POINT *lppt = new POINT[n_bezier_points]; POINT *lppt = new POINT[n_bezier_points];