Merge pull request #24371 from amerry/python-compiler-undefined-behaviour

Fix undefined behavior when Python plugin is given no args
reviewable/pr24411/r1
Richard Belleville 4 years ago committed by GitHub
commit b774020186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      src/compiler/python_generator_helpers.h

@ -138,11 +138,20 @@ StringVector get_all_comments(const DescriptorType* descriptor) {
inline void Split(const std::string& s, char delim,
std::vector<std::string>* append_to) {
auto current = s.begin();
while (current <= s.end()) {
auto next = std::find(current, s.end(), delim);
append_to->emplace_back(current, next);
current = next + 1;
if (s.empty()) {
// splitting an empty string logically produces a single-element list
append_to->emplace_back();
} else {
auto current = s.begin();
while (current < s.end()) {
const auto next = std::find(current, s.end(), delim);
append_to->emplace_back(current, next);
current = next;
if (current != s.end()) {
// it was the delimiter - need to be at the start of the next entry
++current;
}
}
}
}

Loading…
Cancel
Save