ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
PerformanceMonitoring
PerfMonTests
src
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
17
#include "
PerfMonTestErroneousAlg.h
"
18
19
using namespace
PerfMonTest
;
20
21
22
StatusCode
ErroneousAlg::execute
(
const
EventContext&
/*ctx*/
)
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
38
bool
ErroneousAlg::jumpOnUninitializedValue
()
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
59
bool
ErroneousAlg::invalidRead
()
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
94
bool
ErroneousAlg::mismatchedFree
()
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
}
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
PerfMonTestErroneousAlg.h
PerfMonTest::ErroneousAlg::shouldIJump
bool shouldIJump(bool shouldIJump)
Definition
PerfMonTestErroneousAlg.h:41
PerfMonTest::ErroneousAlg::jumpOnUninitializedValue
bool jumpOnUninitializedValue()
three member functions which will exhibit faulty behaviour
Definition
PerfMonTestErroneousAlg.cxx:38
PerfMonTest::ErroneousAlg::mismatchedFree
bool mismatchedFree()
Definition
PerfMonTestErroneousAlg.cxx:94
PerfMonTest::ErroneousAlg::invalidRead
bool invalidRead()
Definition
PerfMonTestErroneousAlg.cxx:59
PerfMonTest::ErroneousAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
PerfMonTestErroneousAlg.cxx:22
PerfMonTest
PerfMonTestPolyVectorAlg.h Example for the memory optimization tutorial.
Definition
Control/PerformanceMonitoring/PerfMonTests/src/Hit.h:7
Generated on
for ATLAS Offline Software by
1.17.0