From 2afadb010807326d20642d035e2f1f89ea9db8b8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 1 Jun 2016 23:41:34 +0200 Subject: [PATCH] - fixed: ADehackedPickup was missing NULL pointer checks in nearly all methods that used RealPickup. Some DECORATE hacks make it possible that this does not contain a valid pointer when these methods are called. --- src/d_dehacked.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index a7a378375..e4acc75a6 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -3123,22 +3123,29 @@ bool ADehackedPickup::TryPickup (AActor *&toucher) const char *ADehackedPickup::PickupMessage () { - return RealPickup->PickupMessage (); + if (RealPickup != nullptr) + return RealPickup->PickupMessage (); + else return ""; } bool ADehackedPickup::ShouldStay () { - return RealPickup->ShouldStay (); + if (RealPickup != nullptr) + return RealPickup->ShouldStay (); + else return true; } bool ADehackedPickup::ShouldRespawn () { - return RealPickup->ShouldRespawn (); + if (RealPickup != nullptr) + return RealPickup->ShouldRespawn (); + else return false; } void ADehackedPickup::PlayPickupSound (AActor *toucher) { - RealPickup->PlayPickupSound (toucher); + if (RealPickup != nullptr) + RealPickup->PlayPickupSound (toucher); } void ADehackedPickup::DoPickupSpecial (AActor *toucher) @@ -3146,19 +3153,19 @@ void ADehackedPickup::DoPickupSpecial (AActor *toucher) Super::DoPickupSpecial (toucher); // If the real pickup hasn't joined the toucher's inventory, make sure it // doesn't stick around. - if (RealPickup->Owner != toucher) + if (RealPickup != nullptr && RealPickup->Owner != toucher) { RealPickup->Destroy (); } - RealPickup = NULL; + RealPickup = nullptr; } void ADehackedPickup::Destroy () { - if (RealPickup != NULL) + if (RealPickup != nullptr) { RealPickup->Destroy (); - RealPickup = NULL; + RealPickup = nullptr; } Super::Destroy (); }