Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array overflow in exploding_fireworks #4289

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

willmmiles
Copy link
Collaborator

Attempt to allocate enough room for the "minimum" sparks; and ensure that we never overrun the allocated array size.

Fixes #4120

Attempt to allocate enough room for the "minimum" sparks; and ensure
that we never overrun the allocated array size.

Fixes Aircoookie#4120
@softhack007 softhack007 merged commit 545bfa6 into Aircoookie:0_15 Nov 18, 2024
20 checks passed
@@ -3547,7 +3547,7 @@ uint16_t mode_exploding_fireworks(void)
if (segs <= (strip.getMaxSegments() /4)) maxData *= 2; //ESP8266: 1024 if <= 4 segs ESP32: 2560 if <= 8 segs
int maxSparks = maxData / sizeof(spark); //ESP8266: max. 21/42/85 sparks/seg, ESP32: max. 53/106/213 sparks/seg

unsigned numSparks = min(2 + ((rows*cols) >> 1), maxSparks);
unsigned numSparks = min(5 + ((rows*cols) >> 1), maxSparks);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alone would be sufficient IMO. It will guarantee that minimum size is 5

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I do prefer to be absolutely explicit at the point of usage as well, though - it's saved me a couple times as I don't always remember the subtle relationships between static constants in future refactors.

@willmmiles willmmiles deleted the exploding_fireworks_overrun branch November 27, 2024 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants