{{ message }}
parser.load(string_view) does not respect view length when opening files#2659
Merged
lemire merged 1 commit intosimdjson:masterfrom Apr 3, 2026
Merged
Conversation
e63bf46 to
695a759
Compare
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.

Short title (summary)
parser.load(string_view)does not respect view length when opening filesDescription
parser.load(std::string_view)currently forwardspath.data()directly tostd::fopen, which treats the input as a null-terminated C string and ignores the view length.When the
string_viewrefers to a substring of a larger buffer, this can result in incorrect file resolution (e.g., attempting to open a suffixed path instead of the intended one).This change ensures that the provided
string_viewis respected by creating a null-terminated copy before callingfopen. The behavior is now consistent with user expectations and aligns with existing file-loading logic elsewhere in the codebase.Type of change
How to verify / test
std::string_viewover a larger backing string (valid path + suffix).parser.load(view)returnsIO_ERRORbecause the full backing string is used.parser.load(view)succeeds and produces the same result asparser.load(std::string).Checklist before submitting
Final notes
This is a minimal and localized change that ensures
std::string_viewis handled correctly when opening files. It avoids relying on implicit null-termination and improves consistency across the API without affecting existing valid usage.