-
Notifications
You must be signed in to change notification settings - Fork 18
Fix stack overflow in ifc-printer when parsing self-referential types #89
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: main
Are you sure you want to change the base?
Changes from 2 commits
066e0de
f115a25
376ccde
e59b15a
d7ff312
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,9 +159,25 @@ namespace ifc::util { | |
|
|
||
| std::string get_string_if_possible(Loader& ctx, TypeIndex index) | ||
| { | ||
| if (not null(index)) | ||
| return ctx.reader.visit(index, TypeTranslator{ctx}); | ||
| return "no-type"; | ||
| if (null(index)) | ||
| return "no-type"; | ||
|
|
||
| // Check for cycles to prevent infinite recursion | ||
| if (ctx.processing_types.find(index) != ctx.processing_types.end()) { | ||
| return "..." + to_string(index); // Return a reference to break the cycle | ||
| } | ||
|
|
||
| // Mark this type as being processed | ||
| ctx.processing_types.insert(index); | ||
|
|
||
| try { | ||
| std::string result = ctx.reader.visit(index, TypeTranslator{ctx}); | ||
| ctx.processing_types.erase(index); | ||
| return result; | ||
| } catch (...) { | ||
| ctx.processing_types.erase(index); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The try/catch was for exception safety - ensuring the index is removed from
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I understand, but I think those changes are making the code worse:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're absolutely right. I've simplified the code by removing the RAII guard class and try/catch logic. The |
||
| throw; | ||
| } | ||
| } | ||
|
|
||
| // Load types as full blown nodes. | ||
|
|
||
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.
Why
mutable?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.
The
mutablekeyword was unnecessary sinceprocessing_typesis only accessed through non-const methods. Removed in commit 376ccde.