Additional Require Check

Added a check in the vote function to ensure that the proposal index is within the range of the proposals array. This prevents out-of-bounds errors.
pull/4813/head
wizard701 5 months ago committed by Aniket
parent 0e54bdbc28
commit 9943fca6c7
  1. 1
      apps/remix-ide/contracts/ballot.sol

@ -101,6 +101,7 @@ contract Ballot {
Voter storage sender = voters[msg.sender]; Voter storage sender = voters[msg.sender];
require(sender.weight != 0, "Has no right to vote"); require(sender.weight != 0, "Has no right to vote");
require(!sender.voted, "Already voted."); require(!sender.voted, "Already voted.");
require(proposal < proposals.length, "Invalid proposal index.");
sender.voted = true; sender.voted = true;
sender.vote = proposal; sender.vote = proposal;

Loading…
Cancel
Save