Skip to content

Commit

Permalink
Merge remote-tracking branch 'neheb/as'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbunkus committed Mar 2, 2024
2 parents 8bb452a + 1f22735 commit 2eaeb0a
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ebml/EbmlDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EBML_DLL_API EbmlDate : public EbmlElementDefaultSameStorage<std::int64_t>
{
if (classInfo.HasDefault())
{
auto def = static_cast<const EbmlCallbacksWithDefault<std::int64_t> &>(classInfo);
const auto& def = static_cast<const EbmlCallbacksWithDefault<std::int64_t> &>(classInfo);
SetValue(def.DefaultValue());
}
}
Expand Down
4 changes: 2 additions & 2 deletions ebml/EbmlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<const EbmlId&>(*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
Expand Down
21 changes: 10 additions & 11 deletions src/EbmlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<EbmlElement *>(nullptr);
return static_cast<EbmlElement *>(new EbmlDummy(PossibleID));
return nullptr;
return new EbmlDummy(pID);
}
if (SizeFound != SizeUnknown && MaxDataSize < SizeFound)
return static_cast<EbmlElement *>(nullptr);
return nullptr;
// check if the size is not all 1s
if (SizeFound == SizeUnknown && !ClassInfos.CanHaveInfiniteSize())
return static_cast<EbmlElement *>(nullptr);
return nullptr;
return &EBML_INFO_CREATE(ClassInfos);
}();

if (Result == nullptr)
if (!Result)
return nullptr;

if (!Result->SizeIsValid(SizeFound)) {
Expand Down Expand Up @@ -454,7 +453,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)
Expand Down Expand Up @@ -518,7 +517,7 @@ filepos_t EbmlElement::MakeRenderHead(IOCallback & output, bool bKeepPosition)
std::array<binary, 4 + 8> FinalHead; // Class D + 64 bits coded size
std::size_t FinalHeadSize;

FinalHeadSize = EBML_ID_LENGTH((const EbmlId&)*this);
FinalHeadSize = EBML_ID_LENGTH(static_cast<const EbmlId&>(*this));
EbmlId(*this).Fill(FinalHead.data());

const unsigned int CodedSize = CodedSizeLength(Size, SizeLength, bSizeIsFinite);
Expand Down
2 changes: 1 addition & 1 deletion src/EbmlFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EbmlFloat::EbmlFloat(const EbmlCallbacksDefault<double> & classInfo, const EbmlF
SetPrecision(prec);
if (classInfo.HasDefault())
{
auto def = static_cast<const EbmlCallbacksWithDefault<double> &>(classInfo);
const auto& def = static_cast<const EbmlCallbacksWithDefault<double> &>(classInfo);
SetValue(def.DefaultValue());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/EbmlMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint64_t>::max();

if (!bForceRender) {
assert(CheckMandatory());
Expand All @@ -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<std::int64_t>(SizeToAdd) == (0-1))
return (0-1);
return std::numeric_limits<std::uint64_t>::max();
#endif // !NDEBUG
SetSize_(GetSize() + SizeToAdd);
}
Expand Down
2 changes: 1 addition & 1 deletion src/EbmlSInteger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ EbmlSInteger::EbmlSInteger(const EbmlCallbacksDefault<std::int64_t> & classInfo)
{
if (classInfo.HasDefault())
{
auto def = static_cast<const EbmlCallbacksWithDefault<std::int64_t> &>(classInfo);
const auto& def = static_cast<const EbmlCallbacksWithDefault<std::int64_t> &>(classInfo);
SetValue(def.DefaultValue());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/EbmlString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EbmlString::EbmlString(const EbmlCallbacksDefault<const char *> & classInfo)
{
if (classInfo.HasDefault())
{
auto def = static_cast<const EbmlCallbacksWithDefault<const char *> &>(classInfo);
const auto& def = static_cast<const EbmlCallbacksWithDefault<const char *> &>(classInfo);
SetValue(def.DefaultValue());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/EbmlUInteger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EbmlUInteger::EbmlUInteger(const EbmlCallbacksDefault<std::uint64_t> & classInfo
{
if (classInfo.HasDefault())
{
auto def = static_cast<const EbmlCallbacksWithDefault<std::uint64_t> &>(classInfo);
const auto& def = static_cast<const EbmlCallbacksWithDefault<std::uint64_t> &>(classInfo);
SetValue(def.DefaultValue());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/EbmlUnicodeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ EbmlUnicodeString::EbmlUnicodeString(const EbmlCallbacksDefault<const wchar_t *>
{
if (classInfo.HasDefault())
{
auto def = static_cast<const EbmlCallbacksWithDefault<const wchar_t *> &>(classInfo);
const auto& def = static_cast<const EbmlCallbacksWithDefault<const wchar_t *> &>(classInfo);
SetValue(UTFstring{def.DefaultValue()});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MemIOCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint32_t>(Size);
}

} // namespace libebml
2 changes: 1 addition & 1 deletion src/StdIOCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions test/test_id.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions test/test_macros.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_utfstring.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 2eaeb0a

Please sign in to comment.