From 62aae6cffbd3ac84b5498f904cb23e677ea2c36b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 20 Jul 2022 18:50:29 +0200 Subject: [PATCH] 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. --- libs/ardour/io.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 50bc9079de..69e782c04f 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -65,11 +65,18 @@ using namespace PBD; const string IO::state_node_name = "IO"; PBD::Signal1 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());