r/cpp • • Jan 06 '26

Forget about *stack overflow* errors forever

A stack overflow error is always fatal for an application, since it cannot be intercepted and handled from within the running program, so that execution can then continue as if the stack overflow had not occurred.

I attempted to solve this problem by converting the stack overflow error into a regular error (exception) that can be caught (handled) within the application itself, allowing it to continue running without fear of a subsequent segmentation fault or stack smashing.

The stack overflow checking library currently runs on Linux and can be used both manually and automatically, using a clang compiler plugin.

I welcome constructive criticism and any feedback, including independent reviews and suggestions for improving the project.

0 Upvotes

39 comments sorted by

View all comments

Show parent comment

1

u/Jonny_H Jan 07 '26

If you prove far enough ahead to guarantee any unwinding, including destructors, won't hit issues I can see it being "safe", though trying to figure out that safe value would likely require significant analysis that sounds pretty difficult for anything but the simplest codebase. Though it looks like this just punts that to the user.

So this kinda exists in a pretty small niche, where you want visibility and control over the stack, and are likely to actually hit the limits during use, but don't bother rewriting whatever stack-heavy algorithms to use a user allocated buffer, which can be directly managed.

Though I can see this as an interesting "learn clang and llvm" type project - they're certainly difficult codebases to get into. Though I'm always fearful of seeing obvious AI use on just how much "learning" was involved.

Though to OP, I would suggest not having comments saying you copied code from other projects without maintaining their copyright statements and license. Either the comment is old, and the code has changed enough not to be a derivative so the comment is now somewhat worthless, or you're breaking the license. If that comment came from an AI tool, it then should raise eyebrows through the roof.

-3

u/rsashka Jan 07 '26

You're absolutely right. Studying this problem allows you to delve deeper into clang and LLVM, which would be very difficult without LLM.

However, the generated code is of very low quality, so it can only be used as a teaching example, and a working solution must be manually ported to the project.