Skip to content

Conversation

@softhack007
Copy link

@softhack007 softhack007 commented Jan 21, 2026

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

.pio/libdeps/esp32s2_PSRAM_M/animartrix/ANIMartRIX.h:425:60:   required from here
.pio/libdeps/esp32s2_PSRAM_M/animartrix/ANIMartRIX.h:59:87: error: exception handling disabled, use -fexceptions to enable
     if (n > std::numeric_limits<std::size_t>::max() / sizeof(T)) throw std::bad_alloc();

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.
Copilot AI review requested due to automatic review settings January 21, 2026 16:43
Copy link

Copilot AI left a 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_exceptions guards 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
Copy link

Copilot AI Jan 21, 2026

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.

Copilot uses AI. Check for mistakes.
Copy link
Author

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.

Copy link

Copilot AI left a 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.

Comment on lines +88 to 91
#if __cpp_exceptions
if (!res) throw std::bad_alloc();
#endif
return res;
Copy link

Copilot AI Jan 21, 2026

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.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

1 participant