Skip to content

Commit

Permalink
More conversions to size_t while removing static_casts
Browse files Browse the repository at this point in the history
  • Loading branch information
piponazo committed Mar 11, 2022
1 parent 65b42f9 commit b20e073
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 189 deletions.
8 changes: 4 additions & 4 deletions include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ namespace Exiv2 {

//! Native preview information. This is meant to be used only by the PreviewManager.
struct NativePreview {
long position_; //!< Position
uint32_t size_; //!< Size
uint32_t width_; //!< Width
uint32_t height_; //!< Height
size_t position_; //!< Position
size_t size_; //!< Size
size_t width_; //!< Width
size_t height_; //!< Height
std::string filter_; //!< Filter
std::string mimeType_; //!< MIME type
};
Expand Down
14 changes: 4 additions & 10 deletions include/exiv2/orfimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,15 @@ namespace Exiv2 {
with data in ORF format to the provided metadata containers.
See TiffParser::decode().
*/
static ByteOrder decode(
ExifData& exifData,
IptcData& iptcData,
XmpData& xmpData,
const byte* pData,
uint32_t size
);
static ByteOrder decode(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, const byte* pData,
size_t size);
/*!
@brief Encode metadata from the provided metadata to ORF format.
See TiffParser::encode().
*/
static WriteMethod encode(
BasicIo& io,
static WriteMethod encode(BasicIo& io,
const byte* pData,
uint32_t size,
size_t size,
ByteOrder byteOrder,
const ExifData& exifData,
const IptcData& iptcData,
Expand Down
2 changes: 1 addition & 1 deletion include/exiv2/pgfimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace Exiv2
//! Read Magick number. Only version >= 6 is supported.
static byte readPgfMagicNumber(BasicIo& iIo);
//! Read PGF Header size encoded in 32 bits integer.
uint32_t readPgfHeaderSize(BasicIo& iIo) const;
size_t readPgfHeaderSize(BasicIo& iIo) const;
//! Read header structure.
DataBuf readPgfHeaderStructure(BasicIo& iIo, uint32_t& width, uint32_t& height) const;
//@}
Expand Down
25 changes: 10 additions & 15 deletions include/exiv2/preview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ namespace Exiv2 {
/*!
@brief Preview image properties.
*/
struct EXIV2API PreviewProperties {
//! Preview image mime type.
std::string mimeType_;
//! Preview image extension.
std::string extension_;
//! Preview image size in bytes.
size_t size_;
//! Preview image width in pixels or 0 for unknown width.
uint32_t width_;
//! Preview image height in pixels or 0 for unknown height.
uint32_t height_;
//! Identifies type of preview image.
PreviewId id_;
struct EXIV2API PreviewProperties
{
std::string mimeType_; //!< Preview image mime type.
std::string extension_; //!< Preview image extension.
size_t size_; //!< Preview image size in bytes.
size_t width_; //!< Preview image width in pixels or 0 for unknown width.
size_t height_; //!< Preview image height in pixels or 0 for unknown height.
PreviewId id_; //!< Identifies type of preview image.
};

//! Container type to hold all preview images metadata.
Expand Down Expand Up @@ -97,11 +92,11 @@ namespace Exiv2 {
/*!
@brief Return the width of the preview image in pixels.
*/
uint32_t width() const;
size_t width() const;
/*!
@brief Return the height of the preview image in pixels.
*/
uint32_t height() const;
size_t height() const;
/*!
@brief Return the preview image type identifier.
*/
Expand Down
5 changes: 2 additions & 3 deletions include/exiv2/rw2image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ namespace Exiv2 {
with data in RW2 format to the provided metadata containers.
See TiffParser::decode().
*/
static ByteOrder decode(
ExifData& exifData,
static ByteOrder decode(ExifData& exifData,
IptcData& iptcData,
XmpData& xmpData,
const byte* pData,
uint32_t size
size_t size
);

}; // class Rw2Parser
Expand Down
5 changes: 2 additions & 3 deletions include/exiv2/tiffimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ namespace Exiv2 {
@return Write method used.
*/
static WriteMethod encode(
BasicIo& io,
static WriteMethod encode(BasicIo& io,
const byte* pData,
uint32_t size,
size_t size,
ByteOrder byteOrder,
const ExifData& exifData,
const IptcData& iptcData,
Expand Down
51 changes: 21 additions & 30 deletions src/makernote_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,8 @@ namespace Exiv2::Internal {
return false;
header_.alloc(sizeOfSignature());
header_.copyBytes(0, pData, header_.size());
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
0 != header_.cmpBytes(0, signature_, 6));
} // OlympusMnHeader::read
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 6));
}

size_t OlympusMnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const
{
Expand Down Expand Up @@ -277,9 +276,8 @@ namespace Exiv2::Internal {
return false;
header_.alloc(sizeOfSignature());
header_.copyBytes(0, pData, header_.size());
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
0 != header_.cmpBytes(0, signature_, 10));
} // Olympus2MnHeader::read
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 10));
}

size_t Olympus2MnHeader::write(IoWrapper& ioWrapper,
ByteOrder /*byteOrder*/) const
Expand Down Expand Up @@ -332,9 +330,8 @@ namespace Exiv2::Internal {
// Read offset to the IFD relative to the start of the makernote
// from the header. Note that we ignore the byteOrder argument
start_ = header_.read_uint32(8, byteOrder_);
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
0 != header_.cmpBytes(0, signature_, 8));
} // FujiMnHeader::read
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 8));
}

size_t FujiMnHeader::write(IoWrapper& ioWrapper,
ByteOrder /*byteOrder*/) const
Expand Down Expand Up @@ -437,8 +434,7 @@ namespace Exiv2::Internal {
return true;
} // Nikon3MnHeader::read

size_t Nikon3MnHeader::write(IoWrapper& ioWrapper,
ByteOrder byteOrder) const
size_t Nikon3MnHeader::write(IoWrapper& ioWrapper, ByteOrder byteOrder) const
{
assert(buf_.size() >= 10);

Expand All @@ -447,8 +443,8 @@ namespace Exiv2::Internal {
TiffHeader th(byteOrder);
DataBuf buf = th.write();
ioWrapper.write(buf.c_data(), buf.size());
return 10 + static_cast<uint32_t>(buf.size());
} // Nikon3MnHeader::write
return 10 + buf.size();
}

void Nikon3MnHeader::setByteOrder(ByteOrder byteOrder)
{
Expand Down Expand Up @@ -525,16 +521,14 @@ namespace Exiv2::Internal {
return sizeOfSignature();
}

bool PentaxDngMnHeader::read(const byte* pData,
size_t size,
ByteOrder /*byteOrder*/)
bool PentaxDngMnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrder*/)
{
if (!pData || size < sizeOfSignature()) return false;
if (!pData || size < sizeOfSignature())
return false;
header_.alloc(sizeOfSignature());
header_.copyBytes(0, pData, header_.size());
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
0 != header_.cmpBytes(0, signature_, 7));
} // PentaxDngMnHeader::read
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 7));
}

size_t PentaxDngMnHeader::write(IoWrapper& ioWrapper,
ByteOrder /*byteOrder*/) const
Expand Down Expand Up @@ -567,23 +561,20 @@ namespace Exiv2::Internal {
return sizeOfSignature();
}

bool PentaxMnHeader::read(const byte* pData,
size_t size,
ByteOrder /*byteOrder*/)
bool PentaxMnHeader::read(const byte* pData, size_t size, ByteOrder /*byteOrder*/)
{
if (!pData || size < sizeOfSignature()) return false;
if (!pData || size < sizeOfSignature())
return false;
header_.alloc(sizeOfSignature());
header_.copyBytes(0, pData, header_.size());
return !(static_cast<uint32_t>(header_.size()) < sizeOfSignature() ||
0 != header_.cmpBytes(0, signature_, 3));
} // PentaxMnHeader::read
return !(header_.size() < sizeOfSignature() || 0 != header_.cmpBytes(0, signature_, 3));
}

size_t PentaxMnHeader::write(IoWrapper& ioWrapper,
ByteOrder /*byteOrder*/) const
size_t PentaxMnHeader::write(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const
{
ioWrapper.write(signature_, sizeOfSignature());
return sizeOfSignature();
} // PentaxMnHeader::write
}

SamsungMnHeader::SamsungMnHeader()
{
Expand Down
6 changes: 3 additions & 3 deletions src/olympusmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ namespace Exiv2::Internal {
return os << value;
}
if (value.count() == 1) {
auto l0 = static_cast<short>(value.toInt64(0));
auto l0 = value.toInt64(0);
if (l0 == 1) {
os << _("Auto");
}
Expand All @@ -1189,8 +1189,8 @@ namespace Exiv2::Internal {
}
}
else if (value.count() == 2) {
auto l0 = static_cast<short>(value.toInt64(0));
auto l1 = static_cast<short>(value.toInt64(1));
auto l0 = value.toInt64(0);
auto l1 = value.toInt64(1);
if (l0 == 1) {
switch (l1) {
case 0: os << _("Auto"); break;
Expand Down
20 changes: 7 additions & 13 deletions src/orfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ namespace Exiv2 {
throw Error(kerNotAnImage, "ORF");
}
clearMetadata();
ByteOrder bo =
OrfParser::decode(exifData_, iptcData_, xmpData_, io_->mmap(), static_cast<uint32_t>(io_->size()));
ByteOrder bo = OrfParser::decode(exifData_, iptcData_, xmpData_, io_->mmap(), io_->size());
setByteOrder(bo);
} // OrfImage::readMetadata
}

void OrfImage::writeMetadata()
{
Expand All @@ -102,13 +101,13 @@ namespace Exiv2 {
#endif
ByteOrder bo = byteOrder();
byte* pData = nullptr;
long size = 0;
size_t size = 0;
IoCloser closer(*io_);
if (io_->open() == 0) {
// Ensure that this is the correct image type
if (isOrfType(*io_, false)) {
pData = io_->mmap(true);
size = static_cast<long>(io_->size());
size = io_->size();
OrfHeader orfHeader;
if (0 == orfHeader.read(pData, 8)) {
bo = orfHeader.byteOrder();
Expand All @@ -122,13 +121,8 @@ namespace Exiv2 {
OrfParser::encode(*io_, pData, size, bo, exifData_, iptcData_, xmpData_); // may throw
} // OrfImage::writeMetadata

ByteOrder OrfParser::decode(
ExifData& exifData,
IptcData& iptcData,
XmpData& xmpData,
const byte* pData,
uint32_t size
)
ByteOrder OrfParser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, const byte* pData,
size_t size)
{
OrfHeader orfHeader;
return TiffParserWorker::decode(exifData,
Expand All @@ -144,7 +138,7 @@ namespace Exiv2 {
WriteMethod OrfParser::encode(
BasicIo& io,
const byte* pData,
uint32_t size,
size_t size,
ByteOrder byteOrder,
const ExifData& exifData,
const IptcData& iptcData,
Expand Down
27 changes: 13 additions & 14 deletions src/pgfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,12 @@ namespace Exiv2 {

readPgfMagicNumber(*io_);

uint32_t headerSize = readPgfHeaderSize(*io_);
size_t headerSize = readPgfHeaderSize(*io_);
readPgfHeaderStructure(*io_, pixelWidth_, pixelHeight_);

// And now, the most interesting, the user data byte array where metadata are stored as small image.

enforce(headerSize <= std::numeric_limits<uint32_t>::max() - 8, kerCorruptedMetadata);
#if LONG_MAX < UINT_MAX
enforce(headerSize + 8 <= static_cast<uint32_t>(std::numeric_limits<long>::max()),
kerCorruptedMetadata);
#endif
enforce(headerSize <= std::numeric_limits<size_t>::max() - 8, kerCorruptedMetadata);
long size = static_cast<long>(headerSize) + 8 - io_->tell();

#ifdef EXIV2_DEBUG_MESSAGES
Expand Down Expand Up @@ -181,7 +177,7 @@ namespace Exiv2 {
img->setIptcData(iptcData_);
img->setXmpData(xmpData_);
img->writeMetadata();
auto imgSize = static_cast<long>(img->io().size());
size_t imgSize = img->io().size();
DataBuf imgBuf = img->io().read(imgSize);

#ifdef EXIV2_DEBUG_MESSAGES
Expand All @@ -191,13 +187,15 @@ namespace Exiv2 {
//---------------------------------------------------------------

// Write PGF Signature.
if (outIo.write(pgfSignature, 3) != 3) throw Error(kerImageWriteFailed);
if (outIo.write(pgfSignature, 3) != 3)
throw Error(kerImageWriteFailed);

// Write Magic number.
if (outIo.putb(mnb) == EOF) throw Error(kerImageWriteFailed);
if (outIo.putb(mnb) == EOF)
throw Error(kerImageWriteFailed);

// Write new Header size.
uint32_t newHeaderSize = static_cast<uint32_t>(header.size()) + imgSize;
uint32_t newHeaderSize = static_cast<uint32_t>(header.size() + imgSize);
DataBuf buffer(4);
buffer.copyBytes(0, &newHeaderSize, 4);
byteSwap_(buffer,0,bSwap_);
Expand Down Expand Up @@ -248,7 +246,7 @@ namespace Exiv2 {
return b;
} // PgfImage::readPgfMagicNumber

uint32_t PgfImage::readPgfHeaderSize(BasicIo& iIo) const
size_t PgfImage::readPgfHeaderSize(BasicIo& iIo) const
{
DataBuf buffer(4);
const size_t bufRead = iIo.read(buffer.data(), buffer.size());
Expand All @@ -257,15 +255,16 @@ namespace Exiv2 {
if (bufRead != buffer.size())
throw Error(kerInputDataReadFailed);

auto headerSize = static_cast<int>(byteSwap_(buffer, 0, bSwap_));
if (headerSize <= 0 ) throw Error(kerNoImageInInputData);
auto headerSize = static_cast<size_t>(byteSwap_(buffer, 0, bSwap_));
if (headerSize == 0 )
throw Error(kerNoImageInInputData);

#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage: PGF header size : " << headerSize << " bytes\n";
#endif

return headerSize;
} // PgfImage::readPgfHeaderSize
}

DataBuf PgfImage::readPgfHeaderStructure(BasicIo& iIo, uint32_t& width, uint32_t& height) const
{
Expand Down
Loading

0 comments on commit b20e073

Please sign in to comment.