From 4a3f65e0c1cc7f08a4676816e17629f0152abaf1 Mon Sep 17 00:00:00 2001 From: scott snyder <snyder@bnl.gov> Date: Fri, 16 Jun 2017 10:32:09 +0200 Subject: [PATCH] FourMom: Avoid conversion of null pointers to references. Avoid a conversion of a null pointer to a reference, caught by ubsan. --- Event/FourMom/FourMom/DeepCopyPointer.h | 3 +++ Event/FourMom/FourMom/Lib/P4ImplEEtaPhiM.h | 2 +- Event/FourMom/FourMom/Lib/P4ImplIPtCotThPhiM.h | 3 +-- Event/FourMom/FourMom/Lib/P4ImplPtEtaPhiM.h | 2 +- Event/FourMom/FourMom/Lib/P4ImplPxPyPzE.h | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Event/FourMom/FourMom/DeepCopyPointer.h b/Event/FourMom/FourMom/DeepCopyPointer.h index efe834c12ab..091da12c909 100644 --- a/Event/FourMom/FourMom/DeepCopyPointer.h +++ b/Event/FourMom/FourMom/DeepCopyPointer.h @@ -35,6 +35,9 @@ public: return *this; } + T* get() { return m_theData; } + const T* get() const { return m_theData; } + T& operator*() { return *m_theData;} const T& operator*() const { return *m_theData;} diff --git a/Event/FourMom/FourMom/Lib/P4ImplEEtaPhiM.h b/Event/FourMom/FourMom/Lib/P4ImplEEtaPhiM.h index 4b04851d7ba..81eae8a7089 100755 --- a/Event/FourMom/FourMom/Lib/P4ImplEEtaPhiM.h +++ b/Event/FourMom/FourMom/Lib/P4ImplEEtaPhiM.h @@ -215,7 +215,7 @@ inline double P4ImplEEtaPhiM::e() const inline const I4MomentumError* P4ImplEEtaPhiM::errors() const { - return &(*m_error); + return m_error.get(); } inline void P4ImplEEtaPhiM::setE( const double theE ) diff --git a/Event/FourMom/FourMom/Lib/P4ImplIPtCotThPhiM.h b/Event/FourMom/FourMom/Lib/P4ImplIPtCotThPhiM.h index c9477a9c0df..cd4bb69b3a8 100755 --- a/Event/FourMom/FourMom/Lib/P4ImplIPtCotThPhiM.h +++ b/Event/FourMom/FourMom/Lib/P4ImplIPtCotThPhiM.h @@ -228,8 +228,7 @@ inline double P4ImplIPtCotThPhiM::cotTh() const inline const I4MomentumError* P4ImplIPtCotThPhiM::errors() const { - // check if the pointer is empty before dereferencing - return (m_error ? &(*m_error) : 0); + return m_error.get(); } // setters diff --git a/Event/FourMom/FourMom/Lib/P4ImplPtEtaPhiM.h b/Event/FourMom/FourMom/Lib/P4ImplPtEtaPhiM.h index 73bc2e66ee1..cc99936c573 100755 --- a/Event/FourMom/FourMom/Lib/P4ImplPtEtaPhiM.h +++ b/Event/FourMom/FourMom/Lib/P4ImplPtEtaPhiM.h @@ -212,7 +212,7 @@ inline double P4ImplPtEtaPhiM::pt() const inline const I4MomentumError* P4ImplPtEtaPhiM::errors() const { // check if the pointer is empty before dereferencing - return (m_error ? &(*m_error) : 0); + return m_error.get(); } // setters diff --git a/Event/FourMom/FourMom/Lib/P4ImplPxPyPzE.h b/Event/FourMom/FourMom/Lib/P4ImplPxPyPzE.h index af8f0b084b7..7b371c34efc 100755 --- a/Event/FourMom/FourMom/Lib/P4ImplPxPyPzE.h +++ b/Event/FourMom/FourMom/Lib/P4ImplPxPyPzE.h @@ -219,7 +219,7 @@ inline double P4ImplPxPyPzE::e() const inline const I4MomentumError* P4ImplPxPyPzE::errors() const { // check if the pointer is empty before dereferencing - return (m_error ? &(*m_error) : 0); + return m_error.get(); } inline void P4ImplPxPyPzE::setPx( const double px ) -- GitLab