Skip to content

Conversation

@willmmiles
Copy link
Member

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 wled#4120
@softhack007 softhack007 merged commit 545bfa6 into wled:0_15 Nov 18, 2024
20 checks passed
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
Contributor

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
Member 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