commit 7c4b468f
Perform the out of bound check before using it as an index
Changed files
| M | source/code/main.cpp before |
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 46619ae..b80d872 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -343,7 +343,7 @@ public:
int addBall(int x, int y,bool right,int color) {
int ballNumber = 0;
//Find a free ball
- while ((ballUsed[ballNumber])&&(ballNumber<maxNumberOfBalls)) {
+ while (ballNumber<maxNumberOfBalls && ballUsed[ballNumber]) {
ballNumber++;
}
//Could not find a free ball, return -1