arun11299/cpp-subprocess

bug in util::join

Opened this issue · 2 comments

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());

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

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