RunestoneInteractive / RunestoneInteractive/pythonds
avector index out of bound issue C++
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 273
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100