ATLAS Offline Software
Loading...
Searching...
No Matches
PerfMonTestErroneousAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// PerfMonTestErroneousAlg.cxx
6// Implementation file for class PerfMonTest::ErroneousAlg
7// Author: R.Seuster
9
10
11// STL includes
12
13// FrameWork includes
14#include "Gaudi/Property.h"
15
16// PerfMonTests includes
18
19using namespace PerfMonTest;
20
21
23{
24 ATH_MSG_DEBUG ( "Executing " << name() << "..." ) ;
25
26 if ( this->jumpOnUninitializedValue() )
27 ATH_MSG_INFO ( " jumpOnUninitializedValue() returned false !" ) ;
28
29 if ( this->invalidRead() )
30 ATH_MSG_INFO ( " jumpOnUninitializedValue() returned false !" ) ;
31
32 if ( this->mismatchedFree() )
33 ATH_MSG_INFO ( " jumpOnUninitializedValue() returned false !" ) ;
34
35 return StatusCode::SUCCESS;
36}
37
39{
40 const unsigned int maximum=8192;
41
42 bool someConditions[64*maximum];
43
44 unsigned int yesNo[] = { 0, 0};
45
46 for ( unsigned int i=0; i<64*maximum; ++i )
47 // cppcheck-suppress uninitvar; this is meant to be uninitialized
48 // cppcheck-suppress legacyUninitvar; this is meant to be uninitialized
49 if ( this->shouldIJump(someConditions[i]) )
50 yesNo[0]++;
51 else
52 yesNo[1]++;
53
54 //m_msg << "Jump, jump not, jump, jump not : " << yesNo[0] << " to " << yesNo[1] << endmsg;
55
56 return (yesNo[1]==0);
57}
58
60{
61 const unsigned int maximum=8192;
62 double *invalidReadPointer = new double[maximum];
63
64 // fill with something
65 for ( unsigned int i=1; i<=maximum; ++i ){
66 //intentional out-of-bounds access
67 //cppcheck-suppress arrayIndexOutOfBounds
68 invalidReadPointer[i] = double(i);
69 }
70 //intentional out-of-bounds access
71#if __GNUC__ >= 15
72# pragma GCC diagnostic ignored "-Warray-bounds"
73#endif
74 //cppcheck-suppress arrayIndexOutOfBounds
75 ATH_MSG_INFO ( "Found, that last element contains " << invalidReadPointer[maximum] ) ;
76
77 // and delete
78#if __GNUC__ >= 12
79# pragma GCC diagnostic ignored "-Wuse-after-free"
80#endif
81 delete [] invalidReadPointer;
82
83 // and print out element 10 !
84 //intentional out-of-bounds access
85 //cppcheck-suppress arrayIndexOutOfBounds
86 ATH_MSG_INFO ( "Found, that last element contains " << invalidReadPointer[maximum] ) ;
87
88 return true;
89}
90
91#ifdef __clang__
92#pragma GCC diagnostic ignored "-Wmismatched-new-delete"
93#endif
95{
96 const unsigned int maximum=8192;
97 double *invalidReadPointer = new double[maximum];
98
99 // fill with something
100 for ( unsigned int i=1; i<maximum; ++i )
101 invalidReadPointer[i] = double(i);
102 ATH_MSG_INFO ( "Found, that last element contains " << invalidReadPointer[maximum-1] ) ;
103
104 // and delete
105 delete [] invalidReadPointer;
106
107 return true;
108}
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
virtual StatusCode execute() override
bool shouldIJump(bool shouldIJump)
bool jumpOnUninitializedValue()
three member functions which will exhibit faulty behaviour
PerfMonTestPolyVectorAlg.h Example for the memory optimization tutorial.