Fix a null-pointer dereference in 5.1 branch

TRACK::GetEndNetCode() can get called using a NULL-pointer as 'this'.
The compiler assumes this won't happen and optimizes away a NULL pointer
check at the start of the function (so we might as well remove this check.)

Fixes: lp:1840562
https://bugs.launchpad.net/kicad/+bug/1840562
This commit is contained in:
Erik Bosman 2019-08-18 02:44:11 +02:00 committed by jean-pierre charras
parent 65f2af5849
commit dcd31f5701
2 changed files with 5 additions and 5 deletions

View File

@ -509,9 +509,6 @@ TRACK* TRACK::GetEndNetCode( int NetCode )
TRACK* NextS, * Track = this;
int ii = 0;
if( Track == NULL )
return NULL;
if( NetCode == -1 )
NetCode = GetNetCode();

View File

@ -4,7 +4,7 @@
* Copyright (C) 2015 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -293,7 +293,10 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC,
wxASSERT( aNewTrack );
TRACK* bufStart = m_Pcb->m_Track->GetStartNetCode( netcode ); // Beginning of tracks of the net
TRACK* bufEnd = bufStart->GetEndNetCode( netcode ); // End of tracks of the net
TRACK* bufEnd;
if ( bufStart != NULL)
bufEnd = bufStart->GetEndNetCode( netcode ); // End of tracks of the net
// Flags for cleaning the net.
for( pt_del = bufStart; pt_del; pt_del = pt_del->Next() )