From 2fda0a505d05ee440c8733a67037336e29a7b6d7 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 8 Aug 2021 01:20:39 +0200 Subject: [PATCH] Prevent showing warning about encoding wrongly when making ID3v1 fields Due to the fallthrough the warning would be printed in any case when using UTF-8 and not only if the BOM is actually written (as there are non-ASCII characters). This problem became apparent when using the tageditor's CLI with `--id3-init-on-create` to create an ID3v1 tag from ID3v2. Of course it doesn't help if there are actually non-ASCII characters present. --- id3/id3v1tag.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/id3/id3v1tag.cpp b/id3/id3v1tag.cpp index 0cb9bd1..25ef952 100644 --- a/id3/id3v1tag.cpp +++ b/id3/id3v1tag.cpp @@ -313,12 +313,12 @@ void Id3v1Tag::writeValue(const TagValue &value, size_t length, char *buffer, os // handle encoding auto *valueStart = buffer; auto valueLength = length; + auto hasProblematicEncoding = false; switch (value.dataEncoding()) { case TagTextEncoding::Latin1: - case TagTextEncoding::Unspecified: break; case TagTextEncoding::Utf8: - // write + // write UTF-8 BOM if the value contains non-ASCII characters for (const auto c : valueAsString) { if ((c & 0x80) == 0) { continue; @@ -328,10 +328,14 @@ void Id3v1Tag::writeValue(const TagValue &value, size_t length, char *buffer, os buffer[2] = static_cast(0xBF); valueStart += 3; valueLength -= 3; + hasProblematicEncoding = true; break; } - [[fallthrough]]; + break; default: + hasProblematicEncoding = true; + } + if (hasProblematicEncoding) { diag.emplace_back(DiagLevel::Warning, "The used encoding is unlikely to be supported by other software.", "making ID3v1 tag field"); }