diff options
author | whitequark <whitequark@whitequark.org> | 2020-06-09 11:05:35 +0000 |
---|---|---|
committer | whitequark <whitequark@whitequark.org> | 2020-06-09 11:05:35 +0000 |
commit | bbfe55a8d0a40eda2df8af0383c9175791377eb7 (patch) | |
tree | f8be815a179ac1f49c3550388c9d19efff013f1c /backends | |
parent | 74e3ac2449f521a50d5e88daa951acee1062e620 (diff) | |
download | yosys-bbfe55a8d0a40eda2df8af0383c9175791377eb7.tar.gz yosys-bbfe55a8d0a40eda2df8af0383c9175791377eb7.tar.bz2 yosys-bbfe55a8d0a40eda2df8af0383c9175791377eb7.zip |
cxxrtl: fix two buggy split_by functions.
Diffstat (limited to 'backends')
-rw-r--r-- | backends/cxxrtl/cxxrtl_backend.cc | 16 | ||||
-rw-r--r-- | backends/cxxrtl/cxxrtl_vcd.h | 14 |
2 files changed, 16 insertions, 14 deletions
diff --git a/backends/cxxrtl/cxxrtl_backend.cc b/backends/cxxrtl/cxxrtl_backend.cc index 2646f9371..4c04a2f14 100644 --- a/backends/cxxrtl/cxxrtl_backend.cc +++ b/backends/cxxrtl/cxxrtl_backend.cc @@ -474,14 +474,16 @@ std::vector<std::string> split_by(const std::string &str, const std::string &sep std::vector<std::string> result; size_t prev = 0; while (true) { - size_t curr = str.find_first_of(sep, prev + 1); - if (curr > str.size()) - curr = str.size(); - if (curr > prev + 1) - result.push_back(str.substr(prev, curr - prev)); - if (curr == str.size()) + size_t curr = str.find_first_of(sep, prev); + if (curr == std::string::npos) { + std::string part = str.substr(prev); + if (!part.empty()) result.push_back(part); break; - prev = curr; + } else { + std::string part = str.substr(prev, curr - prev); + if (!part.empty()) result.push_back(part); + prev = curr + 1; + } } return result; } diff --git a/backends/cxxrtl/cxxrtl_vcd.h b/backends/cxxrtl/cxxrtl_vcd.h index 5f5f612b5..f6b78bbf7 100644 --- a/backends/cxxrtl/cxxrtl_vcd.h +++ b/backends/cxxrtl/cxxrtl_vcd.h @@ -136,14 +136,14 @@ class vcd_writer { std::vector<std::string> hierarchy; size_t prev = 0; while (true) { - size_t curr = hier_name.find_first_of(' ', prev + 1); - if (curr > hier_name.size()) - curr = hier_name.size(); - if (curr > prev + 1) - hierarchy.push_back(hier_name.substr(prev, curr - prev)); - if (curr == hier_name.size()) + size_t curr = hier_name.find_first_of(' ', prev); + if (curr == std::string::npos) { + hierarchy.push_back(hier_name.substr(prev)); break; - prev = curr + 1; + } else { + hierarchy.push_back(hier_name.substr(prev, curr - prev)); + prev = curr + 1; + } } return hierarchy; } |