File tree 1 file changed +5
-4
lines changed
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ contract Election is Initializable {
11
11
error GetVotes ();
12
12
error ElectionIncomplete ();
13
13
error ElectionInactive ();
14
+ error InvalidCandidateID ();
14
15
15
16
mapping (address user = > bool isVoted ) public userVoted;
16
17
@@ -120,10 +121,10 @@ contract Election is Initializable {
120
121
}
121
122
122
123
function removeCandidate (uint _id ) external onlyOwner electionStarted {
123
- candidates[ _id] = candidates[candidates .length - 1 ] ;
124
- candidates[_id].candidateID = _id;
125
- candidates.pop ();
126
- }
124
+ if ( _id > = candidates.length ) revert InvalidCandidateID () ;
125
+ candidates[_id] = candidates[candidates. length - 1 ]; // Replace with last element
126
+ candidates.pop ();
127
+ }
127
128
128
129
function getCandidateList () external view returns (Candidate[] memory ) {
129
130
return candidates;
You can’t perform that action at this time.
0 commit comments