Skip to content

Throw exceptions by value, not by pointer - #42

Open
Sheephog wants to merge 1 commit into
jrl290:mainfrom
Sheephog:fix/throw-by-value
Open

Throw exceptions by value, not by pointer#42
Sheephog wants to merge 1 commit into
jrl290:mainfrom
Sheephog:fix/throw-by-value

Conversation

@Sheephog

@Sheephog Sheephog commented Aug 6, 2026

Copy link
Copy Markdown

Problem

Five sites throw a pointer to an exception rather than the exception itself:

  • lib/microReticulum/src/Cryptography/Token.cpp (2 sites, in encrypt and decrypt)
  • lib/microReticulum/src/Cryptography/Token.h (generate_key)
  • lib/microReticulum/src/Link.cpp (2 sites)

catch (const std::exception&) does not match std::invalid_argument*, and nothing in the tree catches by pointer. So when one of these fires it bypasses every handler, unwinds to std::terminate() — which on ESP32 is a device reboot — and leaks the allocation on the way out.

Origin

This is inherited rather than recent: the same form is present in the vendored microReticulum snapshot this fork is based on (attermann 0.2.4, which has throw new at these sites). Upstream attermann fixed it in 0.4.0; this fork predates that re-vendor and still carries the older form.

Solution

throw new X(...)throw X(...) at all five sites. No behaviour change on any non-error path — the only difference is that these errors can now actually be caught.

Compatibility: nothing is affected. I checked the tree for catch clauses taking a pointer type and there are none, so no existing handler depended on the old behaviour.

Testing: compiled and running on 3 × Heltec V4 (ESP32-S3). No fault has been attributed to this change.


Found while porting upstream microReticulum changes into my fork. Like this project, my fork is developed with AI assistance under human direction — I've reviewed this change, and it's running on hardware as above.

Five sites threw a pointer to an exception rather than the exception itself.
catch (const std::exception&) does not match std::invalid_argument*, and
nothing in the tree catches by pointer, so these throws bypassed every handler,
unwound to std::terminate() -- a reboot on ESP32 -- and leaked the allocation.

Inherited from the vendored microReticulum snapshot (attermann 0.2.4);
attermann fixed this in 0.4.0.
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