arun11299 / cpp-subprocess

Subprocessing with modern C++
Other
456 stars 90 forks source link

bug in util::join #35

Open klosworks opened 5 years ago

klosworks commented 5 years ago

The current definition is

  static inline
  std::string join(const std::vector<std::string>& vec,
                   const std::string& sep = " ")
  {
    std::string res;
    for (auto& elem : vec) res.append(elem + sep);
    res.erase(--res.end());
    return res;
  }

It assumes that the separator is exactly 1 character, which doesn't have to be the case because the sep argument is a string. Specifically this line is buggy:

    res.erase(--res.end());
arun11299 commented 5 years ago

Agree. Will fix it. Thanks for finding it out!

p4vook commented 8 months ago

Shouldn't this be closed? UPD: no, the bug appears to be still present