-
Notifications
You must be signed in to change notification settings - Fork 4
fix exception handling for builds without exception support #3
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
base: OO
Are you sure you want to change the base?
Conversation
some WLED-MM builds failed because "throw" cannot be used when exceptions are disabled (especially tasmota framework). This fix makes sure that "throw" is not used when the compiler has exceptions disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds conditional compilation guards around exception-throwing code in the PSRAMAllocator class to enable compilation on platforms where C++ exceptions are disabled (e.g., Tasmota framework builds).
Changes:
- Wrapped
throw std::bad_alloc()statements with#if __cpp_exceptionsguards in the allocate and reallocate functions - Added exception checks before overflow validation and allocation failure handling
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if __cpp_exceptions | ||
| if (n > std::numeric_limits<std::size_t>::max() / sizeof(T)) throw std::bad_alloc(); | ||
|
|
||
| #endif |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation: tabs are used instead of spaces. Lines 61, 73, and 83 use tabs while the surrounding code uses spaces. The indentation should be consistent throughout the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@netmindz i'm "away from PC" right now, and only have a remote terminal. Please check if you want to merge this PR as-is. Otherwise feel free to edit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if __cpp_exceptions | ||
| if (!res) throw std::bad_alloc(); | ||
| #endif | ||
| return res; |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When exceptions are disabled and reallocation fails (res is nullptr), this function will return a null pointer without any error indication. This could lead to crashes when the caller attempts to use the returned pointer. Consider adding an alternative error handling mechanism for builds without exception support, such as calling abort() or using ESP_LOGE to log a fatal error before aborting.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
some WLED-MM builds failed because "throw" cannot be used when exceptions are disabled (especially tasmota framework). This fix makes sure that "throw" is not used when the compiler has exceptions disabled.
https://github.com/MoonModules/WLED-MM/actions/runs/21217405554/job/61042395595#step:7:435