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.
pull/495/head
Peter Nelson 1 year ago committed by PeterN
parent 2d3250923c
commit 1ec34acb51

@ -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

@ -128,7 +128,6 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_f
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 *ini, const char *path, const char *full_f
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 *ini, const char *path, const char *full_f
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;

@ -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;

Loading…
Cancel
Save