From: Moritz Bunkus Date: Sat, 20 Dec 2014 16:06:47 +0000 (+0100) Subject: cosmetics: re-indent KaxBlock::ReadData() after wrapping in try/catch block X-Git-Tag: release-1.4.2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2260fd14b5ab7d516e2c0d3b0651b485fbf4dfdf;p=libmatroska cosmetics: re-indent KaxBlock::ReadData() after wrapping in try/catch block --- diff --git a/src/KaxBlock.cpp b/src/KaxBlock.cpp index 20fd161..883f641 100644 --- a/src/KaxBlock.cpp +++ b/src/KaxBlock.cpp @@ -455,246 +455,246 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) SetValueIsSet(false); try { - if (ReadFully == SCOPE_ALL_DATA) { - Result = EbmlBinary::ReadData(input, ReadFully); - if (Result != GetSize()) - throw SafeReadIOCallback::EndOfStreamX(GetSize() - Result); - - binary *BufferStart = EbmlBinary::GetBuffer(); - - SafeReadIOCallback Mem(*this); - uint8 BlockHeadSize = 4; - - // update internal values - TrackNumber = Mem.GetUInt8(); - if ((TrackNumber & 0x80) == 0) { - // there is extra data - if ((TrackNumber & 0x40) == 0) { - // We don't support track numbers that large ! - throw SafeReadIOCallback::EndOfStreamX(0); + if (ReadFully == SCOPE_ALL_DATA) { + Result = EbmlBinary::ReadData(input, ReadFully); + if (Result != GetSize()) + throw SafeReadIOCallback::EndOfStreamX(GetSize() - Result); + + binary *BufferStart = EbmlBinary::GetBuffer(); + + SafeReadIOCallback Mem(*this); + uint8 BlockHeadSize = 4; + + // update internal values + TrackNumber = Mem.GetUInt8(); + if ((TrackNumber & 0x80) == 0) { + // there is extra data + if ((TrackNumber & 0x40) == 0) { + // We don't support track numbers that large ! + throw SafeReadIOCallback::EndOfStreamX(0); + } + TrackNumber = (TrackNumber & 0x3F) << 8; + TrackNumber += Mem.GetUInt8(); + BlockHeadSize++; + } else { + TrackNumber &= 0x7F; } - TrackNumber = (TrackNumber & 0x3F) << 8; - TrackNumber += Mem.GetUInt8(); - BlockHeadSize++; - } else { - TrackNumber &= 0x7F; - } - LocalTimecode = int16(Mem.GetUInt16BE()); - bLocalTimecodeUsed = true; + LocalTimecode = int16(Mem.GetUInt16BE()); + bLocalTimecodeUsed = true; - uint8 Flags = Mem.GetUInt8(); - if (EbmlId(*this) == EBML_ID(KaxSimpleBlock)) { - bIsKeyframe = (Flags & 0x80) != 0; - bIsDiscardable = (Flags & 0x01) != 0; - } - mInvisible = (Flags & 0x08) >> 3; - mLacing = LacingType((Flags & 0x06) >> 1); - - // put all Frames in the list - if (mLacing == LACING_NONE) { - FirstFrameLocation += Mem.GetPosition(); - DataBuffer * soloFrame = new DataBuffer(BufferStart + Mem.GetPosition(), GetSize() - BlockHeadSize); - myBuffers.push_back(soloFrame); - SizeList.resize(1); - SizeList[0] = GetSize() - BlockHeadSize; - } else { - // read the number of frames in the lace - uint32 LastBufferSize = GetSize() - BlockHeadSize - 1; // 1 for number of frame - uint8 FrameNum = Mem.GetUInt8(); // number of frames in the lace - 1 - // read the list of frame sizes - uint8 Index; - int32 FrameSize; - uint32 SizeRead; - uint64 SizeUnknown; - - SizeList.resize(FrameNum + 1); - - switch (mLacing) { - case LACING_XIPH: - for (Index=0; Index> 3; + mLacing = LacingType((Flags & 0x06) >> 1); + + // put all Frames in the list + if (mLacing == LACING_NONE) { + FirstFrameLocation += Mem.GetPosition(); + DataBuffer * soloFrame = new DataBuffer(BufferStart + Mem.GetPosition(), GetSize() - BlockHeadSize); + myBuffers.push_back(soloFrame); + SizeList.resize(1); + SizeList[0] = GetSize() - BlockHeadSize; + } else { + // read the number of frames in the lace + uint32 LastBufferSize = GetSize() - BlockHeadSize - 1; // 1 for number of frame + uint8 FrameNum = Mem.GetUInt8(); // number of frames in the lace - 1 + // read the list of frame sizes + uint8 Index; + int32 FrameSize; + uint32 SizeRead; + uint64 SizeUnknown; + + SizeList.resize(FrameNum + 1); + + switch (mLacing) { + case LACING_XIPH: + for (Index=0; IndexBuffer(); - binary *FrameEnd = FrameStart + myBuffers[Index]->Size(); - binary *ExpectedEnd = (Index + 1) < NumFrames ? myBuffers[Index + 1]->Buffer() : BufferEnd; + binary *BufferEnd = BufferStart + GetSize(); + size_t NumFrames = myBuffers.size(); - if ((FrameStart < BufferStart) || (FrameEnd > BufferEnd) || (FrameEnd != ExpectedEnd)) - throw SafeReadIOCallback::EndOfStreamX(0); - } + // Sanity checks for frame pointers and boundaries. + for (size_t Index = 0; Index < NumFrames; ++Index) { + binary *FrameStart = myBuffers[Index]->Buffer(); + binary *FrameEnd = FrameStart + myBuffers[Index]->Size(); + binary *ExpectedEnd = (Index + 1) < NumFrames ? myBuffers[Index + 1]->Buffer() : BufferEnd; - SetValueIsSet(); - } else if (ReadFully == SCOPE_PARTIAL_DATA) { - binary _TempHead[5]; - Result = input.read(_TempHead, 5); - if (Result != 5) - throw SafeReadIOCallback::EndOfStreamX(0); - binary *cursor = _TempHead; - binary *_tmpBuf; - uint8 BlockHeadSize = 4; - - // update internal values - TrackNumber = *cursor++; - if ((TrackNumber & 0x80) == 0) { - // there is extra data - if ((TrackNumber & 0x40) == 0) { - // We don't support track numbers that large ! - return Result; + if ((FrameStart < BufferStart) || (FrameEnd > BufferEnd) || (FrameEnd != ExpectedEnd)) + throw SafeReadIOCallback::EndOfStreamX(0); } - TrackNumber = (TrackNumber & 0x3F) << 8; - TrackNumber += *cursor++; - BlockHeadSize++; - } else { - TrackNumber &= 0x7F; - } - big_int16 b16; - b16.Eval(cursor); - LocalTimecode = int16(b16); - bLocalTimecodeUsed = true; - cursor += 2; - - if (EbmlId(*this) == EBML_ID(KaxSimpleBlock)) { - bIsKeyframe = (*cursor & 0x80) != 0; - bIsDiscardable = (*cursor & 0x01) != 0; - } - mInvisible = (*cursor & 0x08) >> 3; - mLacing = LacingType((*cursor++ & 0x06) >> 1); - if (cursor == &_TempHead[4]) { - _TempHead[0] = _TempHead[4]; - } else { - Result += input.read(_TempHead, 1); - } - - FirstFrameLocation += cursor - _TempHead; + SetValueIsSet(); + } else if (ReadFully == SCOPE_PARTIAL_DATA) { + binary _TempHead[5]; + Result = input.read(_TempHead, 5); + if (Result != 5) + throw SafeReadIOCallback::EndOfStreamX(0); + binary *cursor = _TempHead; + binary *_tmpBuf; + uint8 BlockHeadSize = 4; + + // update internal values + TrackNumber = *cursor++; + if ((TrackNumber & 0x80) == 0) { + // there is extra data + if ((TrackNumber & 0x40) == 0) { + // We don't support track numbers that large ! + return Result; + } + TrackNumber = (TrackNumber & 0x3F) << 8; + TrackNumber += *cursor++; + BlockHeadSize++; + } else { + TrackNumber &= 0x7F; + } - // put all Frames in the list - if (mLacing != LACING_NONE) { - // read the number of frames in the lace - uint32 LastBufferSize = GetSize() - BlockHeadSize - 1; // 1 for number of frame - uint8 FrameNum = _TempHead[0]; // number of frames in the lace - 1 - // read the list of frame sizes - uint8 Index; - int32 FrameSize; - uint32 SizeRead; - uint64 SizeUnknown; + big_int16 b16; + b16.Eval(cursor); + LocalTimecode = int16(b16); + bLocalTimecodeUsed = true; + cursor += 2; - SizeList.resize(FrameNum + 1); + if (EbmlId(*this) == EBML_ID(KaxSimpleBlock)) { + bIsKeyframe = (*cursor & 0x80) != 0; + bIsDiscardable = (*cursor & 0x01) != 0; + } + mInvisible = (*cursor & 0x08) >> 3; + mLacing = LacingType((*cursor++ & 0x06) >> 1); + if (cursor == &_TempHead[4]) { + _TempHead[0] = _TempHead[4]; + } else { + Result += input.read(_TempHead, 1); + } - switch (mLacing) { - case LACING_XIPH: - for (Index=0; Index