4091: Check for null. Fix #4090 r=edg-l a=Learath2

<!-- What is the motivation for the changes of this pull request -->
`@ChillerDragon` can you check if this fixes the issue?

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
bors[bot] 2021-08-16 16:28:16 +00:00 committed by GitHub
commit 551369cda1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1246,10 +1246,12 @@ void CCharacter::Snap(int SnappingClient)
SnapCharacter(SnappingClient, ID);
CNetObj_SwitchState *pSwitchState = static_cast<CNetObj_SwitchState *>(Server()->SnapNewItem(NETOBJTYPE_SWITCHSTATE, ID, sizeof(CNetObj_SwitchState)));
if(pSwitchState)
if(GameServer()->Collision()->m_pSwitchers)
{
CNetObj_SwitchState *pSwitchState = static_cast<CNetObj_SwitchState *>(Server()->SnapNewItem(NETOBJTYPE_SWITCHSTATE, ID, sizeof(CNetObj_SwitchState)));
if(!pSwitchState)
return;
pSwitchState->m_NumSwitchers = GameServer()->Collision()->m_NumSwitchers;
if(pSwitchState->m_NumSwitchers > 256)