Changeset - r27010:cd38461243a2
[Not reviewed]
master
0 3 0
Peter Nelson - 17 months ago 2023-01-26 14:58:51
peter1138@openttd.org
Fix: Truncated music-set song names cause warning log.

The music-set does not need to be selected for this to occur.

Resolved by using std::string instead of fixed buffer for song names,
which avoids manual string copying and removes the length limit.
3 files changed with 4 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/base_media_base.h
Show inline comments
 
@@ -289,7 +289,7 @@ enum MusicTrackType {
 

	
 
/** Metadata about a music track. */
 
struct MusicSongInfo {
 
	char songname[32];       ///< name of song displayed in UI
 
	std::string songname;    ///< name of song displayed in UI
 
	byte tracknr;            ///< track number of song displayed in UI
 
	const char *filename;    ///< file on disk containing song (when used in MusicSet class, this pointer is owned by MD5File object for the file)
 
	MusicTrackType filetype; ///< decoder required for song file
src/music.cpp
Show inline comments
 
@@ -128,7 +128,6 @@ bool MusicSet::FillSetDetails(IniFile *i
 
		for (uint i = 0; i < lengthof(this->songinfo); i++) {
 
			const char *filename = this->files[i].filename;
 
			if (names == nullptr || StrEmpty(filename) || this->files[i].check_result == MD5File::CR_NO_FILE) {
 
				this->songinfo[i].songname[0] = '\0';
 
				continue;
 
			}
 

	
 
@@ -142,10 +141,9 @@ bool MusicSet::FillSetDetails(IniFile *i
 
				char *songname = GetMusicCatEntryName(filename, this->songinfo[i].cat_index);
 
				if (songname == nullptr) {
 
					Debug(grf, 0, "Base music set song missing from CAT file: {}/{}", filename, this->songinfo[i].cat_index);
 
					this->songinfo[i].songname[0] = '\0';
 
					continue;
 
				}
 
				strecpy(this->songinfo[i].songname, songname, lastof(this->songinfo[i].songname));
 
				this->songinfo[i].songname = songname;
 
				free(songname);
 
			} else {
 
				this->songinfo[i].filetype = MTT_STANDARDMIDI;
 
@@ -166,7 +164,7 @@ bool MusicSet::FillSetDetails(IniFile *i
 

	
 
			if (this->songinfo[i].filetype == MTT_STANDARDMIDI) {
 
				if (item != nullptr && item->value.has_value() && !item->value->empty()) {
 
					strecpy(this->songinfo[i].songname, item->value->c_str(), lastof(this->songinfo[i].songname));
 
					this->songinfo[i].songname = item->value.value();
 
				} else {
 
					Debug(grf, 0, "Base music set song name missing: {}", filename);
 
					return false;
src/music_gui.cpp
Show inline comments
 
@@ -43,7 +43,7 @@ struct MusicSystem {
 
		uint set_index;        ///< index of song in set
 

	
 
		PlaylistEntry(const MusicSet *set, uint set_index) : MusicSongInfo(set->songinfo[set_index]), set(set), set_index(set_index) { }
 
		bool IsValid() const { return !StrEmpty(this->songname); }
 
		bool IsValid() const { return !this->songname.empty(); }
 
	};
 
	typedef std::vector<PlaylistEntry> Playlist;
 

	
0 comments (0 inline, 0 general)