From cf556850a7b463354bc1d09d16233e2329a527e2 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 12 Dec 2023 22:22:23 +0100 Subject: [PATCH 1/2] avoid warning about comparing signed/unsigned integers Using an `unsigned int` in the function is safe as all values assigned to it are > 0. Furthermore, logically the function cannot return a value < 1, therefore it should return an `unsigned int` or maybe `std::size_t` (as it deals with calculating a number of bytes a certain element is long) instead of an `int`, but that would change the API & ABI. --- src/EbmlElement.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EbmlElement.cpp b/src/EbmlElement.cpp index 362eb4c7..446d6ad8 100644 --- a/src/EbmlElement.cpp +++ b/src/EbmlElement.cpp @@ -92,7 +92,7 @@ int CodedSizeLength(std::uint64_t Length, unsigned int SizeLength, bool bSizeIsF */ int CodedSizeLengthSigned(std::int64_t Length, unsigned int SizeLength) { - int CodedSize; + unsigned int CodedSize; // prepare the head of the size (000...01xxxxxx) // optimal size if (Length > -64 && Length < 64) // 2^6 From 84a2b480d457b0e5ff795f2ad918ea86f21d54a0 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 12 Dec 2023 22:24:28 +0100 Subject: [PATCH 2/2] avoid warnings about having certain virtuals being hiding in derived classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the base class `EbmlElement` there's the `virtual operator const EbmlId &`. This one is overridden in derived classes in libmatroska (and in `EbmlDummy` as well) in order to return the EBML ID belonging to the concrete element's class in libmatroska. The classes in libmatroska don't derive directly from EbmlElement. Instead there's base-type-specific intermediate class (`EbmlUInteger`, `EBMLSInteger`, `EBMLString`, `EBMLUnicodeString`, `EbmlFloat`, `EbmlDate`). For example: `EbmlElement` ← `EbmlUInteger` ← `KaxTrackNumber` Some of these intermediate classes provide some non-`virtual` `operator`s themselves (e.g. an `operator std::uint64_t` for `EbmlUInteger`) but don't override the `virtual operator const EbmlId &` from the base class, `EbmlElement`. For regular functions this is a common mistake made by programmers, assuming that even though they're leaving out the `virtual` key word in the derived class the function from the derived class overrides the `virtual` function from the base class. However, due to different signatures they don't override; instead you now have two different functions in the same class. This is where the compiler comes in: `g++` 13.2.x emits a warning about this if the category `overloaded-virtual` is enabled. The fix is to tell the compiler that we're doing what we intend to here: we do not want to override the `virtual operator` from the base class; instead we intentionally introduce further, different non-`virtual` `operators`. We do this with a `using Base::operator …` directive. --- ebml/EbmlBinary.h | 1 + ebml/EbmlFloat.h | 1 + ebml/EbmlSInteger.h | 1 + ebml/EbmlString.h | 1 + ebml/EbmlUInteger.h | 1 + ebml/EbmlUnicodeString.h | 1 + 6 files changed, 6 insertions(+) diff --git a/ebml/EbmlBinary.h b/ebml/EbmlBinary.h index 7d54fbff..9cc380f5 100644 --- a/ebml/EbmlBinary.h +++ b/ebml/EbmlBinary.h @@ -80,6 +80,7 @@ class EBML_DLL_API EbmlBinary : public EbmlElement { SetValueIsSet(); } + using EbmlElement::operator const EbmlId &; operator const binary &() const; bool IsDefaultValue() const override { diff --git a/ebml/EbmlFloat.h b/ebml/EbmlFloat.h index 3c545584..26ac5f4b 100644 --- a/ebml/EbmlFloat.h +++ b/ebml/EbmlFloat.h @@ -78,6 +78,7 @@ class EBML_DLL_API EbmlFloat : public EbmlElement { bool IsSmallerThan(const EbmlElement *Cmp) const override; + using EbmlElement::operator const EbmlId &; operator float() const; operator double() const; diff --git a/ebml/EbmlSInteger.h b/ebml/EbmlSInteger.h index caa4361c..df2d1b00 100644 --- a/ebml/EbmlSInteger.h +++ b/ebml/EbmlSInteger.h @@ -70,6 +70,7 @@ class EBML_DLL_API EbmlSInteger : public EbmlElement { bool IsSmallerThan(const EbmlElement *Cmp) const override; + using EbmlElement::operator const EbmlId &; explicit operator std::int8_t() const; explicit operator std::int16_t() const; explicit operator std::int32_t() const; diff --git a/ebml/EbmlString.h b/ebml/EbmlString.h index 514c70ff..831e9fcd 100644 --- a/ebml/EbmlString.h +++ b/ebml/EbmlString.h @@ -58,6 +58,7 @@ class EBML_DLL_API EbmlString : public EbmlElement { filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; EbmlString & operator=(const std::string &); + using EbmlElement::operator const EbmlId &; explicit operator const std::string &() const; EbmlString &SetValue(std::string const &NewValue); diff --git a/ebml/EbmlUInteger.h b/ebml/EbmlUInteger.h index 89ca8e5f..cd01d571 100644 --- a/ebml/EbmlUInteger.h +++ b/ebml/EbmlUInteger.h @@ -68,6 +68,7 @@ class EBML_DLL_API EbmlUInteger : public EbmlElement { bool IsSmallerThan(const EbmlElement *Cmp) const override; + using EbmlElement::operator const EbmlId &; explicit operator std::uint8_t() const; explicit operator std::uint16_t() const; explicit operator std::uint32_t() const; diff --git a/ebml/EbmlUnicodeString.h b/ebml/EbmlUnicodeString.h index afc91c9a..96a9c4e3 100644 --- a/ebml/EbmlUnicodeString.h +++ b/ebml/EbmlUnicodeString.h @@ -108,6 +108,7 @@ class EBML_DLL_API EbmlUnicodeString : public EbmlElement { filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; EbmlUnicodeString & operator=(const UTFstring &); ///< platform dependant code + using EbmlElement::operator const EbmlId &; explicit operator const UTFstring &() const; EbmlUnicodeString &SetValue(UTFstring const &NewValue);