Skip to content

Conversation

@marek-hradil
Copy link

Fix on issue #17047.

Added static keyword, to not let the pointer be out of scope. However, my understanding of this functionality in cpp is poor, so happy to be corrected with some better engineering.

To consider: Isn't static also needed on line 1631, when constructing trigger_pattern?

@marek-hradil marek-hradil changed the title fix : Dangling pointer for non-empty stop words in lazy grammar construction fix : Dangling pointer for non-empty trigger words in lazy grammar construction Nov 6, 2025
@ggerganov
Copy link
Member

Yes, looks like a bug. But adding static is not the correct solution.

I think that simply keeping trigger_patterns in scope until grammar init is completed, should be enough.

@marek-hradil
Copy link
Author

@ggerganov that makes much more sense. I've edited that, can you have a look if it looks better now?

ggerganov
ggerganov previously approved these changes Nov 6, 2025
trigger_pattern += ")[\\s\\S]*";
const auto * trigger_pattern_c = trigger_pattern.c_str();
trigger_pattern_c = trigger_pattern.c_str();
trigger_patterns = &trigger_pattern_c;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a dangling pointer.

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.

3 participants