-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
effect was changed from int to uint but it relied on negative numbers. fixed by checking overflow and a cast.
- Loading branch information
Showing
1 changed file
with
2 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1827,7 +1827,7 @@ uint16_t mode_oscillate(void) { | |
// if the counter has increased, move the oscillator by the random step | ||
if (it != SEGENV.step) oscillators[i].pos += oscillators[i].dir * oscillators[i].speed; | ||
oscillators[i].size = SEGLEN/(3+SEGMENT.intensity/8); | ||
if((oscillators[i].dir == -1) && (oscillators[i].pos <= 0)) { | ||
if((oscillators[i].dir == -1) && (oscillators[i].pos > SEGLEN << 1)) { // use integer overflow | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
DedeHai
Author
Collaborator
|
||
oscillators[i].pos = 0; | ||
oscillators[i].dir = 1; | ||
// make bigger steps for faster speeds | ||
|
@@ -1843,7 +1843,7 @@ uint16_t mode_oscillate(void) { | |
for (unsigned i = 0; i < SEGLEN; i++) { | ||
uint32_t color = BLACK; | ||
for (unsigned j = 0; j < numOscillators; j++) { | ||
if(i >= (unsigned)oscillators[j].pos - oscillators[j].size && i <= oscillators[j].pos + oscillators[j].size) { | ||
if((int)i >= (int)oscillators[j].pos - oscillators[j].size && i <= oscillators[j].pos + oscillators[j].size) { | ||
color = (color == BLACK) ? SEGCOLOR(j) : color_blend(color, SEGCOLOR(j), uint8_t(128)); | ||
} | ||
} | ||
|
Instead I would rather choose to modify
pos
to beint16_t
and useint
fori
,j
andnumOscillators
.Now the logic assumes overflow of 16 bit number which is also prone to future errors.