Skip to content
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

Fix ad_utlity::strip() crash when the result is empty #87

Merged
merged 2 commits into from Aug 8, 2018
Merged

Fix ad_utlity::strip() crash when the result is empty #87

merged 2 commits into from Aug 8, 2018

Conversation

niklas88
Copy link
Member

@niklas88 niklas88 commented Aug 8, 2018

This PR adds a unit test triggering the bug mentioned in #86 as well as a minimal fix. For good measure it also adds a test for empty ad_utility::split() just to make sure we don't have a similar behavior there.

There are several other cleanups possible in the *strip() functions and I've already worked them out. However I think they should go in another PR to keep this one minimal and easy to review.

While we are here also add a test for similar case in
ad_utility::split() though that works and shows the same behaviour as
Python's string split()
Copy link

@naetherm naetherm left a comment

Choose a reason for hiding this comment

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

Added a small comment but apart from that seems good.

@@ -568,9 +568,9 @@ inline string rstrip(const string& text, const char* s) {
inline std::string strip(const std::string& text, char c) {
auto left = text.begin();
auto right = text.end(); // right is of course exclusive
for (; left != text.end() && *left == c; left++)
for (; left < text.end() && *left == c; left++)
Copy link

Choose a reason for hiding this comment

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

One could also use right instead of text.end() here.

@niklas88 niklas88 merged commit e2bd178 into ad-freiburg:master Aug 8, 2018
@niklas88 niklas88 deleted the fix-string-strip branch July 19, 2019 09:22
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.

None yet

2 participants