From c9d6e395689f119143f80acd0cf168618c781d2d Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 18 Feb 2024 16:06:12 -0800 Subject: [PATCH 1/9] use numeric_limits It's otherwise an implicit conversion. Signed-off-by: Rosen Penev --- src/EbmlMaster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EbmlMaster.cpp b/src/EbmlMaster.cpp index 31132842..7a27919b 100644 --- a/src/EbmlMaster.cpp +++ b/src/EbmlMaster.cpp @@ -104,7 +104,7 @@ std::uint64_t EbmlMaster::UpdateSize(const ShouldWrite & writeFilter, bool bForc SetSize_(0); if (!IsFiniteSize()) - return (0-1); + return std::numeric_limits::max(); if (!bForceRender) { assert(CheckMandatory()); @@ -117,7 +117,7 @@ std::uint64_t EbmlMaster::UpdateSize(const ShouldWrite & writeFilter, bool bForc const std::uint64_t SizeToAdd = Element->ElementSize(writeFilter); #if !defined(NDEBUG) if (static_cast(SizeToAdd) == (0-1)) - return (0-1); + return std::numeric_limits::max(); #endif // !NDEBUG SetSize_(GetSize() + SizeToAdd); } From 926b0385d750f16ad34d553e5474d227958adf76 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 9 Feb 2024 14:03:14 -0800 Subject: [PATCH 2/9] avoid EbmlCallbacksWithDefault copies A reference is good enough. It's read only anyway. Signed-off-by: Rosen Penev --- ebml/EbmlDate.h | 2 +- src/EbmlFloat.cpp | 2 +- src/EbmlSInteger.cpp | 2 +- src/EbmlString.cpp | 2 +- src/EbmlUInteger.cpp | 2 +- src/EbmlUnicodeString.cpp | 2 +- test/test_macros.cxx | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ebml/EbmlDate.h b/ebml/EbmlDate.h index 8153fd50..6c3b5775 100644 --- a/ebml/EbmlDate.h +++ b/ebml/EbmlDate.h @@ -22,7 +22,7 @@ class EBML_DLL_API EbmlDate : public EbmlElementDefaultSameStorage { if (classInfo.HasDefault()) { - auto def = static_cast &>(classInfo); + const auto& def = static_cast &>(classInfo); SetValue(def.DefaultValue()); } } diff --git a/src/EbmlFloat.cpp b/src/EbmlFloat.cpp index 3160454b..0d9ae786 100644 --- a/src/EbmlFloat.cpp +++ b/src/EbmlFloat.cpp @@ -19,7 +19,7 @@ EbmlFloat::EbmlFloat(const EbmlCallbacksDefault & classInfo, const EbmlF SetPrecision(prec); if (classInfo.HasDefault()) { - auto def = static_cast &>(classInfo); + const auto& def = static_cast &>(classInfo); SetValue(def.DefaultValue()); } } diff --git a/src/EbmlSInteger.cpp b/src/EbmlSInteger.cpp index edd4a854..ab6d19e6 100644 --- a/src/EbmlSInteger.cpp +++ b/src/EbmlSInteger.cpp @@ -34,7 +34,7 @@ EbmlSInteger::EbmlSInteger(const EbmlCallbacksDefault & classInfo) { if (classInfo.HasDefault()) { - auto def = static_cast &>(classInfo); + const auto& def = static_cast &>(classInfo); SetValue(def.DefaultValue()); } } diff --git a/src/EbmlString.cpp b/src/EbmlString.cpp index fec753f0..ac2fdab6 100644 --- a/src/EbmlString.cpp +++ b/src/EbmlString.cpp @@ -15,7 +15,7 @@ EbmlString::EbmlString(const EbmlCallbacksDefault & classInfo) { if (classInfo.HasDefault()) { - auto def = static_cast &>(classInfo); + const auto& def = static_cast &>(classInfo); SetValue(def.DefaultValue()); } } diff --git a/src/EbmlUInteger.cpp b/src/EbmlUInteger.cpp index 137d4af6..4ec8b5ca 100644 --- a/src/EbmlUInteger.cpp +++ b/src/EbmlUInteger.cpp @@ -17,7 +17,7 @@ EbmlUInteger::EbmlUInteger(const EbmlCallbacksDefault & classInfo { if (classInfo.HasDefault()) { - auto def = static_cast &>(classInfo); + const auto& def = static_cast &>(classInfo); SetValue(def.DefaultValue()); } } diff --git a/src/EbmlUnicodeString.cpp b/src/EbmlUnicodeString.cpp index b45fa30c..22ccfae2 100644 --- a/src/EbmlUnicodeString.cpp +++ b/src/EbmlUnicodeString.cpp @@ -104,7 +104,7 @@ EbmlUnicodeString::EbmlUnicodeString(const EbmlCallbacksDefault { if (classInfo.HasDefault()) { - auto def = static_cast &>(classInfo); + const auto& def = static_cast &>(classInfo); SetValue(UTFstring{def.DefaultValue()}); } } diff --git a/test/test_macros.cxx b/test/test_macros.cxx index 8aeb96d3..c31cad81 100644 --- a/test/test_macros.cxx +++ b/test/test_macros.cxx @@ -56,7 +56,7 @@ int main(void) return 1; UIntWithDefault test0; - auto ClassSpecWithDefault = test0.ElementSpec(); + const auto& ClassSpecWithDefault = test0.ElementSpec(); if (!ClassSpecWithDefault.HasDefault()) return 1; @@ -90,7 +90,7 @@ int main(void) return 1; UIntWithoutDefault testNoDefault0; - auto ClassSpecWithoutDefault = testNoDefault0.ElementSpec(); + const auto& ClassSpecWithoutDefault = testNoDefault0.ElementSpec(); if (ClassSpecWithoutDefault.HasDefault()) return 1; #ifdef TEST_COMPILATION_ERRORS From 378f99fe5e59d500eb9077f09b286f8cc9a6609e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 9 Feb 2024 14:14:54 -0800 Subject: [PATCH 3/9] avoid EbmlCallbacks copies Signed-off-by: Rosen Penev --- src/EbmlElement.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EbmlElement.cpp b/src/EbmlElement.cpp index 5526ac81..45499414 100644 --- a/src/EbmlElement.cpp +++ b/src/EbmlElement.cpp @@ -196,7 +196,7 @@ EbmlElement * EbmlElement::FindNextID(IOCallback & DataStream, const EbmlCallbac } const auto PossibleID = EbmlId(EbmlId::FromBuffer(PossibleId.data(), PossibleID_Length)); - auto Result = [=] { + auto Result = [&] { if (PossibleID != EBML_INFO_ID(ClassInfos)) { if (SizeFound == SizeUnknown) @@ -454,7 +454,7 @@ EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const Eb // parent elements if (EBML_CTX_MASTER(Context) != nullptr && aID == EBML_INFO_ID(*EBML_CTX_MASTER(Context))) { - auto Callbacks = *EBML_CTX_MASTER(Context); + const auto& Callbacks = *EBML_CTX_MASTER(Context); if (AsInfiniteSize && !Callbacks.CanHaveInfiniteSize()) return nullptr; LowLevel++; // already one level up (same as context) From dce2154be877b2cb7328807a992f6af631d5be53 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 9 Feb 2024 14:31:55 -0800 Subject: [PATCH 4/9] remove unnecessary semicolons the test change uses auto to mandate a semicolon. Signed-off-by: Rosen Penev --- test/test_id.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_id.cxx b/test/test_id.cxx index 17ce1c02..d95ce92f 100644 --- a/test/test_id.cxx +++ b/test/test_id.cxx @@ -9,13 +9,13 @@ static constexpr EbmlId MyId = EbmlId{0x654321}; class KaxTracks { public: - static const EbmlId & ClassId() { return MyId; }; + static const EbmlId & ClassId() { return MyId; } }; int main(void) { constexpr binary buf[4] = { 0x12, 0x34, 0x56, 0x78 }; - EbmlId frombuf(EbmlId::FromBuffer(buf, 4)); + auto frombuf = EbmlId(EbmlId::FromBuffer(buf, 4)); EbmlId fromint(0x12345678); From 36b0195d6642e97fad7423902d749fcf86d07747 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 9 Feb 2024 14:32:53 -0800 Subject: [PATCH 5/9] use nullptr Signed-off-by: Rosen Penev --- test/test_utfstring.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_utfstring.cxx b/test/test_utfstring.cxx index 8a7b4f23..33c78b11 100644 --- a/test/test_utfstring.cxx +++ b/test/test_utfstring.cxx @@ -36,7 +36,7 @@ int main(void) UTFstring invalid; invalid.SetUTF8( "\x1\xF6\x00" ); - UTFstring empty{0}; + UTFstring empty{nullptr}; if (empty.length() != 0) return 1; From fc0659e0bf7ddc9014cc7c7abb397e3f590b8cf1 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 16 Feb 2024 23:39:35 -0800 Subject: [PATCH 6/9] gcc: remove redundant tag Found with -Wredundant-tags Signed-off-by: Rosen Penev --- ebml/EbmlElement.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebml/EbmlElement.h b/ebml/EbmlElement.h index 9282463a..849ad89c 100644 --- a/ebml/EbmlElement.h +++ b/ebml/EbmlElement.h @@ -430,7 +430,7 @@ static inline EbmlElement & tEBML_SEM_CREATE(const EbmlSemantic & s) return s.Create(); } -using _GetSemanticContext = const class EbmlSemanticContext &(*)(); +using _GetSemanticContext = const EbmlSemanticContext &(*)(); /*! Context of the element From ecdc7f93de66593cb0247d0fb91a8d5b92c6f64d Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 9 Feb 2024 14:25:32 -0800 Subject: [PATCH 7/9] use C++ casting in macros Signed-off-by: Rosen Penev --- ebml/EbmlElement.h | 2 +- src/EbmlElement.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ebml/EbmlElement.h b/ebml/EbmlElement.h index 849ad89c..263a7b13 100644 --- a/ebml/EbmlElement.h +++ b/ebml/EbmlElement.h @@ -650,7 +650,7 @@ class EBML_DLL_API EbmlElement { private: std::size_t HeadSize() const { - return EBML_ID_LENGTH((const EbmlId&)*this) + CodedSizeLength(Size, SizeLength, bSizeIsFinite); + return EBML_ID_LENGTH(static_cast(*this)) + CodedSizeLength(Size, SizeLength, bSizeIsFinite); } /// return the size of the head, on reading/writing std::uint64_t Size; ///< the size of the data to write diff --git a/src/EbmlElement.cpp b/src/EbmlElement.cpp index 45499414..471b979c 100644 --- a/src/EbmlElement.cpp +++ b/src/EbmlElement.cpp @@ -518,7 +518,7 @@ filepos_t EbmlElement::MakeRenderHead(IOCallback & output, bool bKeepPosition) std::array FinalHead; // Class D + 64 bits coded size std::size_t FinalHeadSize; - FinalHeadSize = EBML_ID_LENGTH((const EbmlId&)*this); + FinalHeadSize = EBML_ID_LENGTH(static_cast(*this)); EbmlId(*this).Fill(FinalHead.data()); const unsigned int CodedSize = CodedSizeLength(Size, SizeLength, bSizeIsFinite); From 2f5ecf87f32d833d0ba3aa5bbdbe8a2bd62d5b25 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 18 Feb 2024 16:09:55 -0800 Subject: [PATCH 8/9] fix some implicit conversions Found with warning C4267 Signed-off-by: Rosen Penev --- src/MemIOCallback.cpp | 2 +- src/StdIOCallback.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MemIOCallback.cpp b/src/MemIOCallback.cpp index 25c202df..eaacf7c2 100644 --- a/src/MemIOCallback.cpp +++ b/src/MemIOCallback.cpp @@ -91,7 +91,7 @@ std::size_t MemIOCallback::write(IOCallback & IOToRead, std::size_t Size) } IOToRead.readFully(&dataBuffer[dataBufferPos], Size); dataBufferTotalSize = Size; - return Size; + return static_cast(Size); } } // namespace libebml diff --git a/src/StdIOCallback.cpp b/src/StdIOCallback.cpp index 083a8e07..d05c38c7 100644 --- a/src/StdIOCallback.cpp +++ b/src/StdIOCallback.cpp @@ -98,7 +98,7 @@ void StdIOCallback::setFilePointer(std::int64_t Offset,seek_mode Mode) std::size_t StdIOCallback::write(const void*Buffer,std::size_t Size) { assert(File!=nullptr); - const std::uint32_t Result = fwrite(Buffer,1,Size,File); + const size_t Result = fwrite(Buffer,1,Size,File); mCurrentPosition += Result; return Result; } From 1f22735c592059955ebc6731a08620b0d9c6fa32 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 17 Feb 2024 15:45:03 -0800 Subject: [PATCH 9/9] remove static_cast from lambda Just specify the return type. Signed-off-by: Rosen Penev --- src/EbmlElement.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/EbmlElement.cpp b/src/EbmlElement.cpp index 471b979c..b05ea67b 100644 --- a/src/EbmlElement.cpp +++ b/src/EbmlElement.cpp @@ -195,23 +195,22 @@ EbmlElement * EbmlElement::FindNextID(IOCallback & DataStream, const EbmlCallbac } while (_SizeLength == 0); } - const auto PossibleID = EbmlId(EbmlId::FromBuffer(PossibleId.data(), PossibleID_Length)); - auto Result = [&] { - if (PossibleID != EBML_INFO_ID(ClassInfos)) - { + auto Result = [&]() -> EbmlElement * { + auto pID = EbmlId(EbmlId::FromBuffer(PossibleId.data(), PossibleID_Length)); + if (pID != EBML_INFO_ID(ClassInfos)) { if (SizeFound == SizeUnknown) - return static_cast(nullptr); - return static_cast(new EbmlDummy(PossibleID)); + return nullptr; + return new EbmlDummy(pID); } if (SizeFound != SizeUnknown && MaxDataSize < SizeFound) - return static_cast(nullptr); + return nullptr; // check if the size is not all 1s if (SizeFound == SizeUnknown && !ClassInfos.CanHaveInfiniteSize()) - return static_cast(nullptr); + return nullptr; return &EBML_INFO_CREATE(ClassInfos); }(); - if (Result == nullptr) + if (!Result) return nullptr; if (!Result->SizeIsValid(SizeFound)) {