Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverity fixes #2673

Merged
merged 3 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pgfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void PgfImage::doWriteMetadata(BasicIo& outIo) {
// Write new Header size.
auto newHeaderSize = static_cast<uint32_t>(header.size() + imgSize);
DataBuf buffer(4);
std::copy_n(&newHeaderSize, 4, buffer.data());
*reinterpret_cast<uint32_t*>(buffer.data()) = newHeaderSize;
byteSwap_(buffer, 0, bSwap_);
if (outIo.write(buffer.c_data(), 4) != 4)
throw Error(ErrorCode::kerImageWriteFailed);
Expand Down
5 changes: 4 additions & 1 deletion src/quicktimevideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,9 +1155,12 @@ void QuickTimeVideo::timeToSampleDecoder() {
io_->readOrThrow(buf.data(), 4);
timeOfFrames = Safe::add(timeOfFrames, temp * buf.read_uint32(0, bigEndian));
}
if (currentStream_ == Video)
if (currentStream_ == Video) {
if (timeOfFrames == 0)
timeOfFrames = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neheb: Did coverity complain about a possible divide-by-zero? I'm not convinced it's a bug. We're using floating point arithmetic here, so it wouldn't cause a crash - it would just compute Inf or NaN.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's it. I'm not convinced it can be 0 based on the above code.

xmpData_["Xmp.video.FrameRate"] =
static_cast<double>(totalframes) * static_cast<double>(timeScale_) / static_cast<double>(timeOfFrames);
}
} // QuickTimeVideo::timeToSampleDecoder

void QuickTimeVideo::sampleDesc(size_t size) {
Expand Down
4 changes: 4 additions & 0 deletions src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ size_t TiffBinaryArray::addElement(size_t idx, const ArrayDef& def) {
auto sz = std::min<size_t>(def.size(tag, cfg()->group_), TiffEntryBase::doSize() - idx);
auto tc = TiffCreator::create(tag, cfg()->group_);
auto tp = dynamic_cast<TiffBinaryElement*>(tc.get());
if (!tp)
return 0;
// The assertion typically fails if a component is not configured in
// the TIFF structure table (TiffCreator::tiffTreeStruct_)
tp->setStart(pData() + idx);
Expand Down Expand Up @@ -917,6 +919,8 @@ size_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, size_t
size_t TiffDirectory::writeDirEntry(IoWrapper& ioWrapper, ByteOrder byteOrder, size_t offset,
TiffComponent* pTiffComponent, size_t valueIdx, size_t dataIdx, size_t& imageIdx) {
auto pDirEntry = dynamic_cast<TiffEntryBase*>(pTiffComponent);
if (!pDirEntry)
return 0;
byte buf[8];
us2Data(buf, pDirEntry->tag(), byteOrder);
us2Data(buf + 2, pDirEntry->tiffType(), byteOrder);
Expand Down
2 changes: 2 additions & 0 deletions src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ void TiffEncoder::visitDirectoryNext(TiffDirectory* object) {

uint32_t TiffEncoder::updateDirEntry(byte* buf, ByteOrder byteOrder, TiffComponent* pTiffComponent) {
auto pTiffEntry = dynamic_cast<TiffEntryBase*>(pTiffComponent);
if (!pTiffEntry)
return 0;
us2Data(buf + 2, pTiffEntry->tiffType(), byteOrder);
ul2Data(buf + 4, static_cast<uint32_t>(pTiffEntry->count()), byteOrder);
// Move data to offset field, if it fits and is not yet there.
Expand Down