Skip to content

Commit

Permalink
coverity: remove dead code
Browse files Browse the repository at this point in the history
Found with: CID 1521533
Unsigned compared against 0 (NO_EFFECT)

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Feb 27, 2023
1 parent 03d34be commit b9d94e6
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,6 @@ void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruct
if (allocate64 > io.size()) {
throw Error(ErrorCode::kerInvalidMalloc);
}
// Overflow check
Internal::enforce(allocate64 <= std::numeric_limits<size_t>::max(), ErrorCode::kerCorruptedMetadata);
DataBuf buf(allocate64); // allocate a buffer
std::copy_n(dir.c_data(8), 4, buf.begin()); // copy dir[8:11] into buffer (short strings)

Expand Down
3 changes: 0 additions & 3 deletions src/pngchunk_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,6 @@ DataBuf PngChunk::readRawProfile(const DataBuf& text, bool iTXt) {
while ('0' <= *sp && *sp <= '9') {
// Compute the new length using unsigned long, so that we can check for overflow.
const size_t newlength = (10 * length) + (*sp - '0');
if (newlength > std::numeric_limits<size_t>::max()) {
return {}; // Integer overflow.
}
length = newlength;
sp++;
if (sp == eot) {
Expand Down
2 changes: 0 additions & 2 deletions src/preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,6 @@ DataBuf decodeBase64(const std::string& src) {
const unsigned long destSize = (validSrcSize * 3) / 4;

// allocate dest buffer
if (destSize > LONG_MAX)
return {}; // avoid integer overflow
DataBuf dest(destSize);

// decode
Expand Down
5 changes: 0 additions & 5 deletions src/rafimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ void RafImage::readMetadata() {

Internal::enforce(Safe::add(jpg_img_off_u32, jpg_img_len_u32) <= io_->size(), ErrorCode::kerCorruptedMetadata);

#if LONG_MAX < UINT_MAX
Internal::enforce(jpg_img_off_u32 <= std::numeric_limits<uint32_t>::max(), ErrorCode::kerCorruptedMetadata);
Internal::enforce(jpg_img_len_u32 <= std::numeric_limits<uint32_t>::max(), ErrorCode::kerCorruptedMetadata);
#endif

auto jpg_img_off = static_cast<long>(jpg_img_off_u32);
auto jpg_img_len = static_cast<long>(jpg_img_len_u32);

Expand Down
2 changes: 1 addition & 1 deletion src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ static const TagInfo* findTagInfo(uint16_t tag, IfdId group) {
const TagInfo* result = nullptr;
const TagInfo* tags = [=] {
if (group == IfdId::gpsId)
return group == IfdId::exifId ? Internal::exifTagList() : Internal::gpsTagList();
return Internal::gpsTagList();
return group == IfdId::exifId ? Internal::exifTagList() : nullptr;
}();
if (tags) {
Expand Down
2 changes: 1 addition & 1 deletion src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ std::ostream& TimeValue::write(std::ostream& os) const {
int64_t TimeValue::toInt64(size_t /*n*/) const {
// Returns number of seconds in the day in UTC.
auto result = static_cast<int64_t>(time_.hour - time_.tzHour) * 60 * 60;
result += (time_.minute - time_.tzMinute) * 60;
result += static_cast<int64_t>(time_.minute - time_.tzMinute) * 60;
result += time_.second;
if (result < 0) {
result += 86400;
Expand Down

0 comments on commit b9d94e6

Please sign in to comment.