diff options
author | David Robillard <d@drobilla.net> | 2007-03-18 06:07:08 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-03-18 06:07:08 +0000 |
commit | 99904735e066804358f1d0bd138a84f1e9ecda91 (patch) | |
tree | 71a924cf1660b5b00231275bd481bbd27094dd9b /libs/ardour/playlist.cc | |
parent | eb270e70a12c410cdd98585ad25bb6d8e384a4f5 (diff) |
Merged with trunk R1612.
git-svn-id: svn://localhost/ardour2/branches/midi@1614 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/playlist.cc')
-rw-r--r-- | libs/ardour/playlist.cc | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index db84b015bb..325ef27a18 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #include <set> @@ -1517,17 +1516,33 @@ Playlist::bump_name_once (string name) string newname; if ((period = name.find_last_of ('.')) == string::npos) { - newname = name; + newname = name; newname += ".1"; } else { - char buf[32]; - int version; - - sscanf (name.substr (period+1).c_str(), "%d", &version); - snprintf (buf, sizeof(buf), "%d", version+1); + int isnumber = 1; + const char *last_element = name.c_str() + period + 1; + for (size_t i = 0; i < strlen(last_element); i++) { + if (!isdigit(last_element[i])) { + isnumber = 0; + break; + } + } + + errno = 0; + long int version = strtol (name.c_str()+period+1, (char **)NULL, 10); + + if (isnumber == 0 || errno != 0) { + // last_element is not a number, or is too large + newname = name; + newname += ".1"; + } else { + char buf[32]; + + snprintf (buf, sizeof(buf), "%ld", version+1); - newname = name.substr (0, period+1); - newname += buf; + newname = name.substr (0, period+1); + newname += buf; + } } return newname; |