Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

avector index out of bound issue C++

Open
#103 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp
Domain
backend

Research direction

Start from the shortBubbleSort function shown in the issue and reproduce the invalid read with a vector of four integers, using the project's available checks or a memory checker. Done means the sort handles the final comparison without accessing beyond the vector and still returns correctly sorted values.

Written by the indexing model from the issue text.

Description

vector shortBubbleSort(vector avector){ //the vector for bubble sort
bool exchanges = true;
int passnum = avector.size();
//while vector size is greater than 0 and exchanges = true
while (passnum > 0 && exchanges) {
exchanges = false;
//loops through vector, exchanging values until it reaches the end of vector.
for(int i = 0; i < passnum; i++){
if(avector[i] > avector[i+1]){
exchanges = true;
int temp = avector[i];
avector[i] = avector[i+1];
avector[i+1] = temp;
}
}
//subtracts from the passnum variable so that the next passthrough is one less
//than the previous, because the largest value has already 'bubbled' all the way up.
passnum = passnum - 1;
}
return avector;

The comparison of avector[i] with avector[i + 1] is going to create an issue when we are comparing the last element. The error will be as follows: "Invalid read of size 4" for avector of size four.

Dominant language
Python
Stars
274
Forks
161
PR merge metrics
No merged PRs in 30d

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RunestoneInteractive/pythonds

All issues in RunestoneInteractive/pythonds

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.