-
Notifications
You must be signed in to change notification settings - Fork 412
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
pbrt::SplitString triggers dereferencing asserts #108
Comments
Closed
mmp
added a commit
that referenced
this issue
Feb 15, 2021
Thanks for reporting this! I've rewritten the logic (and slightly simplified it) in a way that I think should fix this. Please let me know if it takes care of it for you, though. |
I can finally confirm that the rework fixed it. Thank you for the quick fix! |
Dolkar
pushed a commit
to Dolkar/pbrt-v4-myod-integration
that referenced
this issue
May 8, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Visual Studio (2019, 16.8.5) has asserts checking that dereferencing a string-view iterator occurs within the range of the string-view.
pbrt::SplitString()
expects the string-view to end with a'\0'
, however when constructingstd::string
the'\0'
character does not count as being part of the string even if space is allocated for it.For example,
So once
pbrt::SplitString("Geometry/Disks", '/')
has pushed the string"Disks"
,end
andbegin
now both point to the 15th character ofstr
(i.e. the'\0'
) which also corresponds tostr.end()
, so when runningif (*begin == ch)
it tries to get the character at index 14 which is no longer< str.size()
asstr.size() == 14
and the assert fails.Since the value at that position is guaranteed to be
'\0'
since C++11 (unless the user decided to modify it), the program will not end up reading undefined memory and will perform as expected, assuming thestring_view
was constructed fromstd::string
and not something else.It would probably be safer to change
if (*begin == ch)
toif (end != str.end() && *begin == ch)
.The text was updated successfully, but these errors were encountered: