Fix warnings, improve coding style

This commit is contained in:
Martchus 2018-05-31 00:25:32 +02:00
parent a3bf8267ac
commit bf7428d066
2 changed files with 30 additions and 14 deletions

View File

@ -90,31 +90,45 @@ void Id3v1Tag::make(ostream &stream, Diagnostics &diag)
buffer[1] = 0x41;
buffer[2] = 0x47;
stream.write(buffer, 3);
// write text fields
writeValue(m_title, 30, buffer, stream, diag);
writeValue(m_artist, 30, buffer, stream, diag);
writeValue(m_album, 30, buffer, stream, diag);
writeValue(m_year, 4, buffer, stream, diag);
writeValue(m_comment, 28, buffer, stream, diag);
// write numeric fields
// set "default" values for numeric fields
buffer[0] = 0x0; // empty byte
buffer[1] = 0x0; // track nr
buffer[1] = 0x0; // track number
buffer[2] = 0x0; // genre
// track
// write track
if (!m_trackPos.isEmpty()) {
try {
buffer[1] = m_trackPos.toPositionInSet().position();
const auto position(m_trackPos.toPositionInSet().position());
if (position < 0x00 || position > 0xFF) {
throw ConversionException();
}
buffer[1] = static_cast<char>(position);
} catch (const ConversionException &) {
diag.emplace_back(
DiagLevel::Warning, "Track position field can not be set because given value can not be converted appropriately.", context);
}
}
// genre
// write genre
try {
buffer[2] = m_genre.toStandardGenreIndex();
const auto genreIndex(m_genre.toStandardGenreIndex());
if (genreIndex < 0x00 || genreIndex > 0xFF) {
throw ConversionException();
}
buffer[2] = static_cast<char>(genreIndex);
} catch (const ConversionException &) {
diag.emplace_back(DiagLevel::Warning, "Genre field can not be set because given value can not be converted appropriately.", context);
diag.emplace_back(DiagLevel::Warning,
"Genre field can not be set because given value can not be converted to a standard genre number supported by ID3v1.", context);
}
stream.write(buffer, 3);
stream.flush();
}

View File

@ -246,7 +246,7 @@ void Id3v2Tag::parse(istream &stream, const uint64 maximalSize, Diagnostics &dia
// prepare parsing
static const string context("parsing ID3v2 tag");
BinaryReader reader(&stream);
uint64 startOffset = stream.tellg();
const auto startOffset = static_cast<uint64>(stream.tellg());
// check whether the header is truncated
if (maximalSize && maximalSize < 10) {
@ -294,15 +294,15 @@ void Id3v2Tag::parse(istream &stream, const uint64 maximalSize, Diagnostics &dia
// how many bytes remain for frames and padding?
uint32 bytesRemaining = m_sizeExcludingHeader - m_extendedHeaderSize;
if (maximalSize && bytesRemaining > maximalSize) {
bytesRemaining = maximalSize;
bytesRemaining = static_cast<uint32>(maximalSize);
diag.emplace_back(DiagLevel::Critical, "Frames are truncated.", context);
}
// read frames
auto pos = stream.tellg();
auto pos = static_cast<uint64>(stream.tellg());
while (bytesRemaining) {
// seek to next frame
stream.seekg(pos);
stream.seekg(static_cast<streamoff>(pos));
// parse frame
Id3v2Frame frame;
try {
@ -335,7 +335,7 @@ void Id3v2Tag::parse(istream &stream, const uint64 maximalSize, Diagnostics &dia
}
if (maximalSize && m_size + 10 < maximalSize) {
// the footer does not provide additional information, just check the signature
stream.seekg(startOffset + (m_size += 10));
stream.seekg(static_cast<streamoff>(startOffset + (m_size += 10)));
if (reader.readUInt24LE() != 0x494433u) {
diag.emplace_back(DiagLevel::Critical, "Footer signature is invalid.", context);
}
@ -427,14 +427,16 @@ bool FrameComparer::operator()(const uint32 &lhsRef, const uint32 &rhsRef) const
if (rhs == Id3v2FrameIds::lTitle || rhs == Id3v2FrameIds::sTitle) {
return false;
}
bool lhstextfield = Id3v2FrameIds::isTextFrame(lhs);
bool rhstextfield = Id3v2FrameIds::isTextFrame(rhs);
const bool lhstextfield = Id3v2FrameIds::isTextFrame(lhs);
const bool rhstextfield = Id3v2FrameIds::isTextFrame(rhs);
if (lhstextfield && !rhstextfield) {
return true;
}
if (!lhstextfield && rhstextfield) {
return false;
}
if (lhs == Id3v2FrameIds::lCover || lhs == Id3v2FrameIds::sCover) {
return false;
}