fix: prevent panic in cache reset methods when cache is None#1337
Open
saschabuehrle wants to merge 1 commit intorust-lang:masterfrom
Open
fix: prevent panic in cache reset methods when cache is None#1337saschabuehrle wants to merge 1 commit intorust-lang:masterfrom
saschabuehrle wants to merge 1 commit intorust-lang:masterfrom
Conversation
Fixed panic in OnePassCache, HybridCache, and ReverseHybridCache reset methods when attempting to reset a None cache with a Some builder. The issue was that reset() checked if builder.0 was Some but then called self.0.as_mut().unwrap() without verifying self.0 was also Some. This could happen when a cache was created with ::none() but reset with a builder that had an engine. The fix checks if self.0 is Some before calling reset, and if None, creates a new cache from the builder's engine. Fixes rust-lang#1155
|
Sorry to interrupt, I wanted to let you know that this PR is most probably entirely AI-generated, including replies to your comments. Just see the batch of PRs they opened recently to form your own opinion. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Fixes #1155 —
meta::Cache::resetcan panic if called on a different regex than it was created with.Root Cause
The
resetmethods inOnePassCache,HybridCache, andReverseHybridCachechecked ifbuilder.0wasSomebut then calledself.0.as_mut().unwrap()without verifyingself.0was alsoSome. This could happen when a cache was created with::none()(which sets the internal cache toNone) but then reset with a builder that had an engine.Fix
The fix checks if
self.0isSomebefore calling reset:Some, reset the existing cacheNone, create a new cache from the builder's engineThis allows caches to be safely reset with any compatible regex, which is the intended behavior of the
resetmethod.Testing
The reproduction case from the issue now works without panicking:
Greetings, saschabuehrle