cpp-subprocess icon indicating copy to clipboard operation
cpp-subprocess copied to clipboard

bug in util::join

Open klosworks opened this issue 5 years ago • 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());

klosworks avatar Jul 03 '19 09:07 klosworks

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

arun11299 avatar Jul 08 '19 10:07 arun11299

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

p4vook avatar Jan 07 '24 00:01 p4vook