ATLAS Offline Software
PerfMonTestErroneousAlg.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // PerfMonTestErroneousAlg.cxx
8 // Implementation file for class PerfMonTest::ErroneousAlg
9 // Author: R.Seuster
11 
12 
13 // STL includes
14 
15 // FrameWork includes
16 #include "Gaudi/Property.h"
17 
18 // PerfMonTests includes
20 
21 using namespace PerfMonTest;
22 
24 // Public methods:
26 
27 // Constructors
29 ErroneousAlg::ErroneousAlg( const std::string& name,
30  ISvcLocator* pSvcLocator ) :
31  AthAlgorithm( name, pSvcLocator )
32 { }
33 
34 // Destructor
37 {
38  ATH_MSG_DEBUG ( "Calling destructor" ) ;
39 }
40 
41 // Athena Algorithm's Hooks
44 {
45  ATH_MSG_INFO ( "Initializing " << name() << "..." ) ;
46  return StatusCode::SUCCESS;
47 }
48 
50 {
51  ATH_MSG_INFO ( "Finalizing " << name() << "..." ) ;
52 
53  return StatusCode::SUCCESS;
54 }
55 
57 {
58  ATH_MSG_DEBUG ( "Executing " << name() << "..." ) ;
59 
60  if ( this->jumpOnUninitializedValue() )
61  ATH_MSG_INFO ( " jumpOnUninitializedValue() returned false !" ) ;
62 
63  if ( this->invalidRead() )
64  ATH_MSG_INFO ( " jumpOnUninitializedValue() returned false !" ) ;
65 
66  if ( this->mismatchedFree() )
67  ATH_MSG_INFO ( " jumpOnUninitializedValue() returned false !" ) ;
68 
69  return StatusCode::SUCCESS;
70 }
71 
73 {
74  const unsigned int maximum=8192;
75 
76  bool someConditions[64*maximum];
77 
78  unsigned int yesNo[] = { 0, 0};
79 
80  for ( unsigned int i=0; i<64*maximum; ++i )
81  // cppcheck-suppress uninitvar; this is meant to be uninitialized
82  // cppcheck-suppress legacyUninitvar; this is meant to be uninitialized
83  if ( this->shouldIJump(someConditions[i]) )
84  yesNo[0]++;
85  else
86  yesNo[1]++;
87 
88  //m_msg << "Jump, jump not, jump, jump not : " << yesNo[0] << " to " << yesNo[1] << endmsg;
89 
90  return (yesNo[1]==0);
91 }
92 
94 {
95  const unsigned int maximum=8192;
96  double *invalidReadPointer = new double[maximum];
97 
98  // fill with something
99  for ( unsigned int i=1; i<=maximum; ++i ){
100  //intentional out-of-bounds access
101  //cppcheck-suppress arrayIndexOutOfBounds
102  invalidReadPointer[i] = double(i);
103  }
104  //intentional out-of-bounds access
105  //cppcheck-suppress arrayIndexOutOfBounds
106  ATH_MSG_INFO ( "Found, that last element contains " << invalidReadPointer[maximum] ) ;
107 
108  // and delete
109 #if __GNUC__ >= 12
110 # pragma GCC diagnostic ignored "-Wuse-after-free"
111 #endif
112  delete [] invalidReadPointer;
113 
114  // and print out element 10 !
115  //intentional out-of-bounds access
116  //cppcheck-suppress arrayIndexOutOfBounds
117  ATH_MSG_INFO ( "Found, that last element contains " << invalidReadPointer[maximum] ) ;
118 
119  return true;
120 }
121 
122 #ifdef __clang__
123 #pragma GCC diagnostic ignored "-Wmismatched-new-delete"
124 #endif
126 {
127  const unsigned int maximum=8192;
128  double *invalidReadPointer = new double[maximum];
129 
130  // fill with something
131  for ( unsigned int i=1; i<maximum; ++i )
132  invalidReadPointer[i] = double(i);
133  ATH_MSG_INFO ( "Found, that last element contains " << invalidReadPointer[maximum-1] ) ;
134 
135  // and delete
136  delete [] invalidReadPointer;
137 
138  return true;
139 }
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PerfMonTest::ErroneousAlg::mismatchedFree
bool mismatchedFree()
Definition: PerfMonTestErroneousAlg.cxx:125
PerfMonTest::ErroneousAlg::shouldIJump
bool shouldIJump(bool shouldIJump)
Definition: PerfMonTestErroneousAlg.h:64
PerfMonTest::ErroneousAlg::invalidRead
bool invalidRead()
Definition: PerfMonTestErroneousAlg.cxx:93
PerfMonTest::ErroneousAlg::execute
virtual StatusCode execute()
Definition: PerfMonTestErroneousAlg.cxx:56
PerfMonTestErroneousAlg.h
PerfMonTest::ErroneousAlg::~ErroneousAlg
virtual ~ErroneousAlg()
Destructor:
Definition: PerfMonTestErroneousAlg.cxx:36
PerfMonTest::ErroneousAlg::ErroneousAlg
ErroneousAlg()
Default constructor:
lumiFormat.i
int i
Definition: lumiFormat.py:85
PerfMonTest::ErroneousAlg::jumpOnUninitializedValue
bool jumpOnUninitializedValue()
three member functions which will exhibit faulty behaviour
Definition: PerfMonTestErroneousAlg.cxx:72
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PerfMonTest
PerfMonTestPolyVectorAlg.h Example for the memory optimization tutorial.
Definition: Control/PerformanceMonitoring/PerfMonTests/src/Hit.h:7
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
AthAlgorithm
Definition: AthAlgorithm.h:47
PerfMonTest::ErroneousAlg::finalize
virtual StatusCode finalize()
Definition: PerfMonTestErroneousAlg.cxx:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
PerfMonTest::ErroneousAlg::initialize
virtual StatusCode initialize()
Definition: PerfMonTestErroneousAlg.cxx:43