Skip to content

Commit 38f2a77

Browse files
committed
Fix dangerous memset on Candidate struct after placement new
1 parent 1746721 commit 38f2a77

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

runtime/compiler/optimizer/NewInitialization.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ bool TR_NewInitialization::findAllocationNode(TR::TreeTop *treeTop, TR::Node *no
442442

443443
// An allocation node has been found. Create a new candidate entry.
444444
//
445-
Candidate *candidate = new (trStackMemory()) Candidate;
446-
memset(candidate, 0, sizeof(Candidate));
445+
Candidate *candidate = new (trStackMemory()) Candidate();
447446
candidate->treeTop = treeTop;
448447
candidate->node = node;
449448
candidate->size = size;

runtime/compiler/optimizer/NewInitialization.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ class TR_NewInitialization : public TR::Optimization {
6565
};
6666

6767
struct Candidate : public TR_Link<Candidate> {
68+
Candidate()
69+
: treeTop(NULL)
70+
, node(NULL)
71+
, uninitializedWords(NULL)
72+
, initializedBytes(NULL)
73+
, uninitializedBytes(NULL)
74+
// localStores, localLoads, and inlinedCalls are automatically constructed
75+
, size(0)
76+
, startOffset(0)
77+
, numUninitializedWords(0)
78+
, numInitializedBytes(0)
79+
, numUninitializedBytes(0)
80+
, isArrayNew(false)
81+
, isInSniffedMethod(false)
82+
{}
83+
6884
TR::TreeTop *treeTop;
6985
TR::Node *node;
7086
TR_BitVector *uninitializedWords;

0 commit comments

Comments
 (0)