Consistently replace colons in IO/Port names

This fixes an issue when creating tracks or busses with a colon
in the name. Renaming those tracks later IO::set_name()
crashed in current_name.replace(std::string::npos,..).

`IO::build_legal_port_name` uses ";" instead of ":" while
`IO::set_name` replaced it with a "-".

Initially the IO name included the colon, so ports created
use a semicolon. But after renaming the IO, ::set_name() applies
the replacement and the IO's name is changed to include the "-".

This leads to a conflict with ports that already have the semicolon
in the port-name.
This commit is contained in:
Robin Gareus 2022-07-20 18:50:29 +02:00
parent 85f640c31a
commit 62aae6cffb
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -65,11 +65,18 @@ using namespace PBD;
const string IO::state_node_name = "IO";
PBD::Signal1<void,ChanCount> IO::PortCountChanged;
static std::string
legalize_io_name (std::string n)
{
replace_all (n, ":", "-");
return n;
}
/** @param default_type The type of port that will be created by ensure_io
* and friends if no type is explicitly requested (to avoid breakage).
*/
IO::IO (Session& s, const string& name, Direction dir, DataType default_type, bool sendish)
: SessionObject (s, name)
: SessionObject (s, legalize_io_name (name))
, _direction (dir)
, _default_type (default_type)
, _sendish (sendish)
@ -1137,7 +1144,7 @@ IO::set_name (const string& requested_name)
/* replace all colons in the name. i wish we didn't have to do this */
replace_all (name, ":", "-");
name = legalize_io_name (name);
for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
string current_name = i->name();
@ -1402,8 +1409,7 @@ IO::build_legal_port_name (DataType type)
/* colons are illegal in port names, so fix that */
string nom = _name.val();
replace_all (nom, ":", ";");
string nom = legalize_io_name (_name.val());
snprintf (&buf1[0], name_size+1, ("%.*s/%s"), limit, nom.c_str(), suffix.c_str());