Convert Exiv2::ErrorCode into an enum class

main
Luis Díaz Más 3 years ago committed by Luis Diaz
parent 5d08bb9bec
commit 96f7f2e4c5

@ -1385,14 +1385,14 @@ namespace {
cmdLine += std::string(" ") + formatArg(__argv[i]) ;
}
#endif
throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num)
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, Exiv2::toString(num)
+ ": " + _("Invalid command line:") + cmdLine);
}
std::string cmd(line.substr(cmdStart, cmdEnd-cmdStart));
CmdId cmdId = commandId(cmd);
if (cmdId == invalidCmdId) {
throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num)
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, Exiv2::toString(num)
+ ": " + _("Invalid command") + " `" + cmd + "'");
}
@ -1424,7 +1424,7 @@ namespace {
catch (const Exiv2::AnyError&) {}
}
if (metadataId == invalidMetadataId) {
throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num)
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, Exiv2::toString(num)
+ ": " + _("Invalid key") + " `" + key + "'");
}
}
@ -1444,7 +1444,7 @@ namespace {
if ( cmdId == reg
&& ( keyEnd == std::string::npos
|| valStart == std::string::npos)) {
throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num)
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, Exiv2::toString(num)
+ ": " + _("Invalid command line") + " " );
}
@ -1456,7 +1456,7 @@ namespace {
if (tmpType != Exiv2::invalidTypeId) {
valStart = line.find_first_not_of(delim, typeEnd+1);
if (valStart == std::string::npos) {
throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num)
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, Exiv2::toString(num)
+ ": " + _("Invalid command line") + " " );
}
type = tmpType;
@ -1483,7 +1483,7 @@ namespace {
if (cmdId == reg) {
if (value.empty()) {
throw Exiv2::Error(Exiv2::kerErrorMessage,
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage,
Exiv2::toString(num) + ": " + _("Empty value for key") + + " `" + key + "'");
}

@ -56,16 +56,16 @@ namespace Exiv2 {
//@{
void readMetadata() override;
/// @throws Error(kerWritingImageFormatUnsupported).
/// @throws Error(ErrorCode::kerWritingImageFormatUnsupported).
void writeMetadata() override;
/// @throws Error(kerInvalidSettingForImage)
/// @throws Error(ErrorCode::kerInvalidSettingForImage)
void setExifData(const ExifData& exifData) override;
/// @throws Error(kerInvalidSettingForImage)
/// @throws Error(ErrorCode::kerInvalidSettingForImage)
void setIptcData(const IptcData& iptcData) override;
/// @throws Error(kerInvalidSettingForImage)
/// @throws Error(ErrorCode::kerInvalidSettingForImage)
void setComment(std::string_view comment) override;
//@}

@ -60,7 +60,7 @@ namespace Exiv2 {
void printStructure(std::ostream& out, PrintStructureOption option, int depth) override;
/*!
@brief Not supported. CR2 format does not contain a comment.
Calling this function will throw an Error(kerInvalidSettingForImage).
Calling this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -61,7 +61,7 @@ namespace Exiv2 {
void writeMetadata() override;
/*!
@brief Not supported. CRW format does not contain IPTC metadata.
Calling this function will throw an Error(kerInvalidSettingForImage).
Calling this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setIptcData(const IptcData& iptcData) override;
//@}

@ -61,7 +61,7 @@ namespace Exiv2
void writeMetadata() override;
/*!
@brief Not supported.
Calling this function will throw an instance of Error(kerInvalidSettingForImage).
Calling this function will throw an instance of Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -146,33 +146,10 @@ namespace Exiv2 {
return os.str();
}
/*!
@brief Error class interface. Allows the definition and use of a hierarchy
of error classes which can all be handled in one catch block.
Inherits from the standard exception base-class, to make life
easier for library users (they have the option of catching most
things via std::exception).
*/
class EXIV2API AnyError : public std::exception {
public:
AnyError() = default;
AnyError(const AnyError& o) = default;
~AnyError() noexcept override = default;
///@brief Return the error code.
virtual int code() const noexcept = 0;
};
//! %AnyError output operator
inline std::ostream& operator<<(std::ostream& os, const AnyError& error)
{
return os << error.what();
}
//! Complete list of all Exiv2 error codes
enum ErrorCode {
kerGeneralError = -1,
enum class ErrorCode {
kerSuccess = 0,
kerGeneralError,
kerErrorMessage,
kerCallFailed,
kerNotAnImage,
@ -238,6 +215,28 @@ namespace Exiv2 {
kerMallocFailed,
};
/*!
@brief Error class interface. Allows the definition and use of a hierarchy
of error classes which can all be handled in one catch block.
Inherits from the standard exception base-class, to make life
easier for library users (they have the option of catching most
things via std::exception).
*/
class EXIV2API AnyError : public std::exception {
public:
AnyError() = default;
AnyError(const AnyError& o) = default;
~AnyError() noexcept override = default;
///@brief Return the error code.
virtual ErrorCode code() const noexcept = 0;
};
//! %AnyError output operator
inline std::ostream& operator<<(std::ostream& os, const AnyError& error)
{
return os << error.what();
}
/*!
@brief Simple error class used for exceptions. An output operator is
provided to print errors to a stream.
@ -268,7 +267,7 @@ namespace Exiv2 {
//! @name Accessors
//@{
inline int code() const noexcept override;
inline ErrorCode code() const noexcept override;
/*!
@brief Return the error message as a C-string. The pointer returned by what()
is valid only as long as the BasicError object exists.
@ -299,7 +298,7 @@ namespace Exiv2 {
// free functions, template and inline definitions
//! Return the error message for the error with code \em code.
const char* errMsg(int code);
const char* errMsg(ErrorCode code);
template<typename charT>
BasicError<charT>::BasicError(ErrorCode code)
@ -338,7 +337,7 @@ namespace Exiv2 {
BasicError<charT>::~BasicError() noexcept = default;
template <typename charT>
int BasicError<charT>::code() const noexcept
ErrorCode BasicError<charT>::code() const noexcept
{
return code_;
}

@ -52,22 +52,22 @@ namespace Exiv2 {
void readMetadata() override;
/*!
@brief Todo: Write metadata back to the image. This method is not
yet(?) implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported).
yet(?) implemented. Calling it will throw an Error(ErrorCode::kerWritingImageFormatUnsupported).
*/
void writeMetadata() override;
/*!
@brief Todo: Not supported yet(?). Calling this function will throw
an instance of Error(kerInvalidSettingForImage).
an instance of Error(ErrorCode::kerInvalidSettingForImage).
*/
void setExifData(const ExifData& exifData) override;
/*!
@brief Todo: Not supported yet(?). Calling this function will throw
an instance of Error(kerInvalidSettingForImage).
an instance of Error(ErrorCode::kerInvalidSettingForImage).
*/
void setIptcData(const IptcData& iptcData) override;
/*!
@brief Not supported. Calling this function will throw an instance
of Error(kerInvalidSettingForImage).
of Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -56,7 +56,7 @@ namespace Exiv2
/*!
@brief Todo: Not supported yet(?). Calling this function will throw
an instance of Error(kerInvalidSettingForImage).
an instance of Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -55,22 +55,22 @@ namespace Exiv2 {
void readMetadata() override;
/*!
@brief Todo: Write metadata back to the image. This method is not
yet implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported).
yet implemented. Calling it will throw an Error(ErrorCode::kerWritingImageFormatUnsupported).
*/
void writeMetadata() override;
/*!
@brief Todo: Not supported yet, requires writeMetadata(). Calling
this function will throw an Error(kerInvalidSettingForImage).
this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setExifData(const ExifData& exifData) override;
/*!
@brief Todo: Not supported yet, requires writeMetadata(). Calling
this function will throw an Error(kerInvalidSettingForImage).
this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setIptcData(const IptcData& iptcData) override;
/*!
@brief Not supported. MRW format does not contain a comment.
Calling this function will throw an Error(kerInvalidSettingForImage).
Calling this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -57,7 +57,7 @@ namespace Exiv2 {
void writeMetadata() override;
/*!
@brief Not supported. ORF format does not contain a comment.
Calling this function will throw an Error(kerInvalidSettingForImage).
Calling this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -51,7 +51,7 @@ namespace Exiv2 {
void readMetadata() override;
void writeMetadata() override;
/*!
@brief Not supported. Calling this function will throw an Error(kerInvalidSettingForImage).
@brief Not supported. Calling this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -48,22 +48,22 @@ namespace Exiv2 {
void readMetadata() override;
/*!
@brief Todo: Write metadata back to the image. This method is not
yet implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported).
yet implemented. Calling it will throw an Error(ErrorCode::kerWritingImageFormatUnsupported).
*/
void writeMetadata() override;
/*!
@brief Todo: Not supported yet, requires writeMetadata(). Calling
this function will throw an Error(kerInvalidSettingForImage).
this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setExifData(const ExifData& exifData) override;
/*!
@brief Todo: Not supported yet, requires writeMetadata(). Calling
this function will throw an Error(kerInvalidSettingForImage).
this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setIptcData(const IptcData& iptcData) override;
/*!
@brief Not supported. RAF format does not contain a comment.
Calling this function will throw an Error(kerInvalidSettingForImage).
Calling this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -46,22 +46,22 @@ namespace Exiv2 {
void readMetadata() override;
/*!
@brief Todo: Write metadata back to the image. This method is not
yet implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported).
yet implemented. Calling it will throw an Error(ErrorCode::kerWritingImageFormatUnsupported).
*/
void writeMetadata() override;
/*!
@brief Todo: Not supported yet, requires writeMetadata(). Calling
this function will throw an Error(kerInvalidSettingForImage).
this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setExifData(const ExifData& exifData) override;
/*!
@brief Todo: Not supported yet, requires writeMetadata(). Calling
this function will throw an Error(kerInvalidSettingForImage).
this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setIptcData(const IptcData& iptcData) override;
/*!
@brief Not supported. RW2 format does not contain a comment.
Calling this function will throw an Error(kerInvalidSettingForImage).
Calling this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -51,22 +51,22 @@ namespace Exiv2 {
void readMetadata() override;
/*!
@brief Todo: Write metadata back to the image. This method is not
yet(?) implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported).
yet(?) implemented. Calling it will throw an Error(ErrorCode::kerWritingImageFormatUnsupported).
*/
void writeMetadata() override;
/*!
@brief Todo: Not supported yet(?). Calling this function will throw
an instance of Error(kerInvalidSettingForImage).
an instance of Error(ErrorCode::kerInvalidSettingForImage).
*/
void setExifData(const ExifData& exifData) override;
/*!
@brief Todo: Not supported yet(?). Calling this function will throw
an instance of Error(kerInvalidSettingForImage).
an instance of Error(ErrorCode::kerInvalidSettingForImage).
*/
void setIptcData(const IptcData& iptcData) override;
/*!
@brief Not supported. Calling this function will throw an instance
of Error(kerInvalidSettingForImage).
of Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -57,7 +57,7 @@ namespace Exiv2 {
/*!
@brief Not supported. TIFF format does not contain a comment.
Calling this function will throw an Error(kerInvalidSettingForImage).
Calling this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -46,7 +46,7 @@ namespace Exiv2 {
//@}
/*!
@brief Not supported. Calling this function will throw an Error(kerInvalidSettingForImage).
@brief Not supported. Calling this function will throw an Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
void setIptcData(const IptcData& /*iptcData*/) override;

@ -45,7 +45,7 @@ namespace Exiv2 {
void writeMetadata() override;
/*!
@brief Not supported. XMP sidecar files do not contain a comment.
Calling this function will throw an instance of Error(kerInvalidSettingForImage).
Calling this function will throw an instance of Error(ErrorCode::kerInvalidSettingForImage).
*/
void setComment(std::string_view comment) override;
//@}

@ -74,14 +74,14 @@ try {
key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities");
auto pos = exifData.findKey(key);
if (pos == exifData.end())
throw Exiv2::Error(Exiv2::kerErrorMessage, "Key not found");
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Key not found");
// Get a pointer to a copy of the value
v = pos->getValue();
// Downcast the Value pointer to its actual type
auto prv = dynamic_cast<Exiv2::URationalValue*>(v.get());
if (!prv)
throw Exiv2::Error(Exiv2::kerErrorMessage, "Downcast failed");
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Downcast failed");
rv = Exiv2::URationalValue(*prv);
// Modify the value directly through the interface of URationalValue
@ -97,7 +97,7 @@ try {
// Delete the metadatum at iterator position pos
key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities");
pos = exifData.findKey(key);
if (pos == exifData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Key not found");
if (pos == exifData.end()) throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Key not found");
exifData.erase(pos);
std::cout << "Deleted key \"" << key << "\"\n";

@ -23,7 +23,7 @@ void httpcon(const std::string& url, bool useHttp1_0 = false) {
int serverCode = Exiv2::http(request,response,errors);
if (serverCode < 0 || serverCode >= 400 || !errors.empty()) {
throw Exiv2::Error(Exiv2::kerTiffDirectoryTooLarge, "Server", serverCode);
throw Exiv2::Error(Exiv2::ErrorCode::kerTiffDirectoryTooLarge, "Server", serverCode);
}
}
@ -31,14 +31,14 @@ void httpcon(const std::string& url, bool useHttp1_0 = false) {
void curlcon(const std::string& url, bool useHttp1_0 = false) {
CURL* curl = curl_easy_init();
if(!curl) {
throw Exiv2::Error(Exiv2::kerErrorMessage, "Unable to init libcurl.");
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Unable to init libcurl.");
}
// get the timeout value
std::string timeoutStr = Exiv2::getEnv(Exiv2::envTIMEOUT);
long timeout = atol(timeoutStr.c_str());
if (timeout == 0) {
throw Exiv2::Error(Exiv2::kerErrorMessage, "Timeout Environmental Variable must be a positive integer.");
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Timeout Environmental Variable must be a positive integer.");
}
std::string response;
@ -55,7 +55,7 @@ void curlcon(const std::string& url, bool useHttp1_0 = false) {
/* Perform the request, res will get the return code */
CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK) { // error happened
throw Exiv2::Error(Exiv2::kerErrorMessage, curl_easy_strerror(res));
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, curl_easy_strerror(res));
}
// get return code
@ -64,7 +64,7 @@ void curlcon(const std::string& url, bool useHttp1_0 = false) {
curl_easy_cleanup(curl);
if (returnCode >= 400 || returnCode < 0) {
throw Exiv2::Error(Exiv2::kerTiffDirectoryTooLarge, "Server", returnCode);
throw Exiv2::Error(Exiv2::ErrorCode::kerTiffDirectoryTooLarge, "Server", returnCode);
}
}
#endif

@ -30,7 +30,7 @@ try {
Exiv2::ExifData &ed = image->exifData();
if (ed.empty()) {
std::string error = file + ": No Exif data found in the file";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
std::cout << "Copy construction, non-intrusive changes\n";

@ -70,7 +70,7 @@ try {
Exiv2::ExifData &exifData = image->exifData();
if (exifData.empty()) {
std::string error("No Exif data found in file");
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
std::set<std::string> shortLong;

@ -51,11 +51,11 @@ int main(int argc, char* const argv[])
// copy fileIn from a remote location.
auto io = Exiv2::ImageFactory::createIo(fr);
if ( io->open() != 0 ) {
Error(Exiv2::kerFileOpenFailed, io->path(), "rb", strError());
Error(Exiv2::ErrorCode::kerFileOpenFailed, io->path(), "rb", strError());
}
FileIo output(f0);
if ( !output.open("wb") ) {
Error(Exiv2::kerFileOpenFailed, output.path() , "w+b", strError());
Error(Exiv2::ErrorCode::kerFileOpenFailed, output.path() , "w+b", strError());
}
size_t l = 0;
if ( !bytes.empty() ) {
@ -75,12 +75,12 @@ int main(int argc, char* const argv[])
FileIo fileIn(f0);
if (fileIn.open() != 0) {
throw Error(Exiv2::kerDataSourceOpenFailed, fileIn.path(), strError());
throw Error(Exiv2::ErrorCode::kerDataSourceOpenFailed, fileIn.path(), strError());
}
FileIo fileOut1(f1);
if (fileOut1.open("w+b") != 0) {
throw Error(Exiv2::kerFileOpenFailed, f1, "w+b", strError());
throw Error(Exiv2::ErrorCode::kerFileOpenFailed, f1, "w+b", strError());
}
MemIo memIo1;
@ -106,7 +106,7 @@ int main(int argc, char* const argv[])
// Create or overwrite the file, then close it
FileIo fileTest("iotest.txt");
if (fileTest.open("w+b") != 0) {
throw Error(Exiv2::kerFileOpenFailed, "iotest.txt", "w+b", strError());
throw Error(Exiv2::ErrorCode::kerFileOpenFailed, "iotest.txt", "w+b", strError());
}
fileTest.close();
@ -118,7 +118,7 @@ int main(int argc, char* const argv[])
memIo2.seek(0, BasicIo::beg);
FileIo fileOut2(f2);
if (fileOut2.open("w+b") != 0) {
throw Error(Exiv2::kerFileOpenFailed, f2, "w+b", strError());
throw Error(Exiv2::ErrorCode::kerFileOpenFailed, f2, "w+b", strError());
}
size_t readCount = 0;
@ -155,7 +155,7 @@ int WriteReadSeek(BasicIo &io)
const size_t size2 = std::strlen(tester2) + 1;
if (io.open() != 0) {
throw Error(Exiv2::kerDataSourceOpenFailed, io.path(), strError());
throw Error(Exiv2::ErrorCode::kerDataSourceOpenFailed, io.path(), strError());
}
IoCloser closer(io);
if (io.write(reinterpret_cast<const byte*>(tester1), size1) != size1) {
@ -218,7 +218,7 @@ int WriteReadSeek(BasicIo &io)
// open should seek to beginning
if (io.open() != 0) {
throw Error(Exiv2::kerDataSourceOpenFailed, io.path(), strError());
throw Error(Exiv2::ErrorCode::kerDataSourceOpenFailed, io.path(), strError());
}
std::memset(buf, -1, sizeof(buf));
if (io.read(buf, sizeof(buf)) != insert + size2) {

@ -25,7 +25,7 @@ try {
if (iptcData.empty()) {
std::string error(argv[1]);
error += ": No IPTC data found in the file";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
auto end = iptcData.end();

@ -72,7 +72,7 @@ bool processLine(const std::string& line, int num, IptcData &iptcData)
default:
std::ostringstream os;
os << "Unknown command (" << line.at(0) << ") at line " << num;
throw Error(kerErrorMessage, os.str());
throw Error(ErrorCode::kerErrorMessage, os.str());
}
return true;
}
@ -88,7 +88,7 @@ void processAdd(const std::string& line, int num, IptcData &iptcData)
dataStart == std::string::npos) {
std::ostringstream os;
os << "Invalid \'a\' command at line " << num;
throw Error(kerErrorMessage, os.str());
throw Error(ErrorCode::kerErrorMessage, os.str());
}
std::string key(line.substr(keyStart, keyEnd-keyStart));
@ -105,7 +105,7 @@ void processAdd(const std::string& line, int num, IptcData &iptcData)
int rc = iptcData.add(iptcKey, value.get());
if (rc) {
throw Error(kerErrorMessage, "Iptc dataset already exists and is not repeatable");
throw Error(ErrorCode::kerErrorMessage, "Iptc dataset already exists and is not repeatable");
}
}
@ -116,7 +116,7 @@ void processRemove(const std::string& line, int num, IptcData &iptcData)
if (keyStart == std::string::npos) {
std::ostringstream os;
os << "Invalid \'r\' command at line " << num;
throw Error(kerErrorMessage, os.str());
throw Error(ErrorCode::kerErrorMessage, os.str());
}
const std::string key( line.substr(keyStart) );
@ -139,7 +139,7 @@ void processModify(const std::string& line, int num, IptcData &iptcData)
dataStart == std::string::npos) {
std::ostringstream os;
os << "Invalid \'m\' command at line " << num;
throw Error(kerErrorMessage, os.str());
throw Error(ErrorCode::kerErrorMessage, os.str());
}
std::string key(line.substr(keyStart, keyEnd-keyStart));
@ -161,7 +161,7 @@ void processModify(const std::string& line, int num, IptcData &iptcData)
else {
int rc = iptcData.add(iptcKey, value.get());
if (rc) {
throw Error(kerErrorMessage, "Iptc dataset already exists and is not repeatable");
throw Error(ErrorCode::kerErrorMessage, "Iptc dataset already exists and is not repeatable");
}
}
}

@ -26,14 +26,14 @@ int main(int argc, char* const argv[])
// Read data file into data buffer
Exiv2::FileIo io(data);
if (io.open() != 0) {
throw Exiv2::Error(Exiv2::kerDataSourceOpenFailed, io.path(), Exiv2::strError());
throw Exiv2::Error(Exiv2::ErrorCode::kerDataSourceOpenFailed, io.path(), Exiv2::strError());
}
Exiv2::DataBuf buf(io.size());
std::cout << "Reading " << buf.size() << " bytes from " << data << "\n";
const size_t readBytes = io.read(buf.data(), buf.size());
if (readBytes != buf.size() || io.error() || io.eof()) {
throw Exiv2::Error(Exiv2::kerFailedToReadImageData);
throw Exiv2::Error(Exiv2::ErrorCode::kerFailedToReadImageData);
}
// Read metadata from file

@ -24,7 +24,7 @@ try {
FileIo file(path);
// Open the file in read mode
if (file.open("rb") != 0) {
throw Error(kerFileOpenFailed, path, "rb", strError());
throw Error(ErrorCode::kerFileOpenFailed, path, "rb", strError());
}
// Map it to memory
const Exiv2::byte* pData = file.mmap();

@ -26,7 +26,7 @@ int main(int argc, char* const argv[])
if (exifData.empty()) {
std::string error(argv[1]);
error += ": No Exif data found in the file";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
Exiv2::ExifKey key("Exif.Minolta.ThumbnailOffset");

@ -56,7 +56,7 @@ try {
if (exifReadData.empty()) {
std::string error(argv[1]);
error += ": No Exif data found in the file";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
auto end = exifReadData.end();
for (auto i = exifReadData.begin(); i != end; ++i) {
@ -82,19 +82,19 @@ try {
exifReadData["Exif.Image.Copyright"] = "Exiv2.org"; // AsciiValue
key = Exiv2::ExifKey("Exif.Image.Make");
auto pos = exifReadData.findKey(key);
if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Exif.Image.Make not found");
if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Exif.Image.Make not found");
exifReadData.erase(pos);
key = Exiv2::ExifKey("Exif.Image.DateTime");
pos = exifReadData.findKey(key);
if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Exif.Image.DateTime not found");
if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Exif.Image.DateTime not found");
exifReadData.erase(pos);
key = Exiv2::ExifKey("Exif.Canon.OwnerName");
pos = exifReadData.findKey(key);
if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Exif.Canon.OwnerName not found");
if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Exif.Canon.OwnerName not found");
exifReadData.erase(pos);
key = Exiv2::ExifKey("Exif.CanonCs.LensType");
pos = exifReadData.findKey(key);
if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Exif.CanonCs.LensType not found");
if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Exif.CanonCs.LensType not found");
exifReadData.erase(pos);
readTest->setExifData(exifReadData);
readTest->writeMetadata();

@ -47,25 +47,25 @@ void mini1(const char* path)
// Write nothing to a new structure, without a previous binary image
wm = ExifParser::encode(blob, nullptr, 0, bigEndian, exifData);
enforce(wm == wmIntrusive, Exiv2::kerErrorMessage, "encode returned an unexpected value");
enforce(wm == wmIntrusive, Exiv2::ErrorCode::kerErrorMessage, "encode returned an unexpected value");
assert(blob.empty());
std::cout << "Test 1: Writing empty Exif data without original binary data: ok.\n";
// Write nothing, this time with a previous binary image
DataBuf buf = readFile(path);
wm = ExifParser::encode(blob, buf.c_data(), buf.size(), bigEndian, exifData);
enforce(wm == wmIntrusive, Exiv2::kerErrorMessage, "encode returned an unexpected value");
enforce(wm == wmIntrusive, Exiv2::ErrorCode::kerErrorMessage, "encode returned an unexpected value");
assert(blob.empty());
std::cout << "Test 2: Writing empty Exif data with original binary data: ok.\n";
// Write something to a new structure, without a previous binary image
exifData["Exif.Photo.DateTimeOriginal"] = "Yesterday at noon";
wm = ExifParser::encode(blob, nullptr, 0, bigEndian, exifData);
enforce(wm == wmIntrusive, Exiv2::kerErrorMessage, "encode returned an unexpected value");
enforce(wm == wmIntrusive, Exiv2::ErrorCode::kerErrorMessage, "encode returned an unexpected value");
std::cout << "Test 3: Wrote non-empty Exif data without original binary data:\n";
exifData.clear();
ByteOrder bo = ExifParser::decode(exifData, &blob[0], blob.size());
enforce(bo == bigEndian, Exiv2::kerErrorMessage, "decode returned an unexpected value");
enforce(bo == bigEndian, Exiv2::ErrorCode::kerErrorMessage, "decode returned an unexpected value");
print(exifData);
}
@ -93,7 +93,7 @@ void print(const ExifData& exifData)
{
if (exifData.empty()) {
std::string error("No Exif data found in the file");
throw Exiv2::Error(kerErrorMessage, error);
throw Exiv2::Error(ErrorCode::kerErrorMessage, error);
}
auto end = exifData.end();
for (auto i = exifData.begin(); i != end; ++i) {

@ -13,7 +13,7 @@ int main()
#endif
try {
throw Exiv2::Error(Exiv2::kerGeneralError, "ARG1", "ARG2", "ARG3");
throw Exiv2::Error(Exiv2::ErrorCode::kerGeneralError, "ARG1", "ARG2", "ARG3");
}
catch (const Exiv2::Error& e) {
std::cout << "Caught Error '" << e.what() << "'\n";

@ -158,7 +158,7 @@ void testCase(const std::string& file1,
std::cerr << "---> Modifying Exif data\n";
auto pos = ed1.findKey(ek);
if (pos == ed1.end()) {
throw Error(kerErrorMessage, "Metadatum with key = " + ek.key() + " not found");
throw Error(ErrorCode::kerErrorMessage, "Metadatum with key = " + ek.key() + " not found");
}
pos->setValue(value);

@ -25,7 +25,7 @@ int main(int argc, char* const argv[])
if (xmpPacket.empty()) {
std::string error(argv[1]);
error += ": No XMP packet found in the file";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
std::cout << xmpPacket << "\n";

@ -24,12 +24,12 @@ try {
if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket)) {
std::string error(argv[1]);
error += ": Failed to parse file contents (XMP packet)";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
if (xmpData.empty()) {
std::string error(argv[1]);
error += ": No XMP properties found in the XMP packet";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
for (auto&& md : xmpData) {
std::cout << std::setfill(' ') << std::left << std::setw(44) << md.key() << " " << std::setw(9)

@ -25,12 +25,12 @@ try {
if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket)) {
std::string error(argv[1]);
error += ": Failed to parse file contents (XMP packet)";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
if (xmpData.empty()) {
std::string error(argv[1]);
error += ": No XMP properties found in the XMP packet";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
for (auto&& md : xmpData) {
std::cout << std::setfill(' ') << std::left << std::setw(44) << md.key() << " " << std::setw(9)
@ -42,14 +42,14 @@ try {
if (0 != Exiv2::XmpParser::encode(xmpPacket, xmpData)) {
std::string error(argv[1]);
error += ": Failed to encode the XMP data";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
Exiv2::FileIo file(filename);
if (file.open("wb") != 0) {
throw Exiv2::Error(Exiv2::kerFileOpenFailed, filename, "wb", Exiv2::strError());
throw Exiv2::Error(Exiv2::ErrorCode::kerFileOpenFailed, filename, "wb", Exiv2::strError());
}
if (file.write(reinterpret_cast<const Exiv2::byte*>(xmpPacket.data()), xmpPacket.size()) == 0) {
throw Exiv2::Error(Exiv2::kerCallFailed, filename, Exiv2::strError(), "FileIo::write");
throw Exiv2::Error(Exiv2::ErrorCode::kerCallFailed, filename, Exiv2::strError(), "FileIo::write");
}
Exiv2::XmpParser::terminate();
return 0;

@ -30,13 +30,13 @@ int main(int argc, char** argv)
if (xmpData.empty()) {
std::string error(argv[1]);
error += ": No XMP data found in the file";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
if (xmpData.empty())
{
std::string error(argv[1]);
error += ": No XMP properties found in the XMP packet";
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, error);
}
for (auto&& md : xmpData) {

@ -100,7 +100,7 @@ try {
// Deleting an XMP property
auto pos = xmpData.findKey(Exiv2::XmpKey("Xmp.dc.eight"));
if (pos == xmpData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Key not found");
if (pos == xmpData.end()) throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Key not found");
xmpData.erase(pos);
// -------------------------------------------------------------------------
@ -196,7 +196,7 @@ try {
// Serialize the XMP data and output the XMP packet
std::string xmpPacket;
if (0 != Exiv2::XmpParser::encode(xmpPacket, xmpData)) {
throw Exiv2::Error(Exiv2::kerErrorMessage, "Failed to serialize XMP data");
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Failed to serialize XMP data");
}
std::cout << xmpPacket << "\n";

@ -230,12 +230,12 @@ namespace Exiv2 {
{
assert(p_->fp_);
if (munmap() != 0) {
throw Error(kerCallFailed, path(), strError(), "munmap");
throw Error(ErrorCode::kerCallFailed, path(), strError(), "munmap");
}
p_->mappedLength_ = size();
p_->isWriteable_ = isWriteable;
if (p_->isWriteable_ && p_->switchMode(Impl::opWrite) != 0) {
throw Error(kerFailedToMapFileForReadWrite, path(), strError());
throw Error(ErrorCode::kerFailedToMapFileForReadWrite, path(), strError());
}
#if defined EXV_HAVE_MMAP && defined EXV_HAVE_MUNMAP
int prot = PROT_READ;
@ -244,7 +244,7 @@ namespace Exiv2 {
}
void* rc = ::mmap(nullptr, p_->mappedLength_, prot, MAP_SHARED, fileno(p_->fp_), 0);
if (MAP_FAILED == rc) {
throw Error(kerCallFailed, path(), strError(), "mmap");
throw Error(ErrorCode::kerCallFailed, path(), strError(), "mmap");
}
p_->pMappedArea_ = static_cast<byte*>(rc);
@ -265,28 +265,28 @@ namespace Exiv2 {
HANDLE hPh = GetCurrentProcess();
HANDLE hFd = (HANDLE)_get_osfhandle(fileno(p_->fp_));
if (hFd == INVALID_HANDLE_VALUE) {
throw Error(kerCallFailed, path(), "MSG1", "_get_osfhandle");
throw Error(ErrorCode::kerCallFailed, path(), "MSG1", "_get_osfhandle");
}
if (!DuplicateHandle(hPh, hFd, hPh, &p_->hFile_, 0, false, DUPLICATE_SAME_ACCESS)) {
throw Error(kerCallFailed, path(), "MSG2", "DuplicateHandle");
throw Error(ErrorCode::kerCallFailed, path(), "MSG2", "DuplicateHandle");
}
p_->hMap_ = CreateFileMapping(p_->hFile_, 0, flProtect, 0, (DWORD) p_->mappedLength_, 0);
if (p_->hMap_ == 0 ) {
throw Error(kerCallFailed, path(), "MSG3", "CreateFileMapping");
throw Error(ErrorCode::kerCallFailed, path(), "MSG3", "CreateFileMapping");
}
void* rc = MapViewOfFile(p_->hMap_, dwAccess, 0, 0, 0);
if (rc == 0) {
throw Error(kerCallFailed, path(), "MSG4", "CreateFileMapping");
throw Error(ErrorCode::kerCallFailed, path(), "MSG4", "CreateFileMapping");
}
p_->pMappedArea_ = static_cast<byte*>(rc);
#else
// Workaround for platforms without mmap: Read the file into memory
DataBuf buf(static_cast<long>(p_->mappedLength_));
if (read(buf.data(), buf.size()) != buf.size()) {
throw Error(kerCallFailed, path(), strError(), "FileIo::read");
throw Error(ErrorCode::kerCallFailed, path(), strError(), "FileIo::read");
}
if (error()) {
throw Error(kerCallFailed, path(), strError(), "FileIo::mmap");
throw Error(ErrorCode::kerCallFailed, path(), strError(), "FileIo::mmap");
}
p_->pMappedArea_ = buf.release().first;
p_->isMalloced_ = true;
@ -346,7 +346,7 @@ namespace Exiv2 {
if (open("a+b") != 0) {
// Remove the (temporary) file
fs::remove(fileIo->path().c_str());
throw Error(kerFileOpenFailed, path(), "a+b", strError());
throw Error(ErrorCode::kerFileOpenFailed, path(), "a+b", strError());
}
close();
@ -380,13 +380,13 @@ namespace Exiv2 {
fs::remove(fileIo->path().c_str());
}
else {
throw Error(kerFileRenameFailed, fileIo->path(), pf, strError());
throw Error(ErrorCode::kerFileRenameFailed, fileIo->path(), pf, strError());
}
}
}
else {
if (fileExists(pf) && ::remove(pf) != 0) {
throw Error(kerCallFailed, pf, strError(), "fs::remove");
throw Error(ErrorCode::kerCallFailed, pf, strError(), "fs::remove");
}
fs::rename(fileIo->path().c_str(), pf);
fs::remove(fileIo->path().c_str());
@ -394,7 +394,7 @@ namespace Exiv2 {
}
#else
if (fileExists(pf) && fs::remove(pf) != 0) {
throw Error(kerCallFailed, pf, strError(), "fs::remove");
throw Error(ErrorCode::kerCallFailed, pf, strError(), "fs::remove");
}
fs::rename(fileIo->path().c_str(), pf);
fs::remove(fileIo->path().c_str());
@ -404,14 +404,14 @@ namespace Exiv2 {
if (statOk && ::stat(pf, &buf2) == -1) {
statOk = false;
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << Error(kerCallFailed, pf, strError(), "::stat") << "\n";
EXV_WARNING << Error(ErrorCode::kerCallFailed, pf, strError(), "::stat") << "\n";
#endif
}
if (statOk && origStMode != buf2.st_mode) {
// Set original file permissions
if (::chmod(pf, origStMode) == -1) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << Error(kerCallFailed, pf, strError(), "::chmod") << "\n";
EXV_WARNING << Error(ErrorCode::kerCallFailed, pf, strError(), "::chmod") << "\n";
#endif
}
}
@ -420,10 +420,10 @@ namespace Exiv2 {
else {
// Generic handling, reopen both to reset to start
if (open("w+b") != 0) {
throw Error(kerFileOpenFailed, path(), "w+b", strError());
throw Error(ErrorCode::kerFileOpenFailed, path(), "w+b", strError());
}
if (src.open() != 0) {
throw Error(kerDataSourceOpenFailed, src.path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, src.path(), strError());
}
write(src);
src.close();
@ -431,13 +431,13 @@ namespace Exiv2 {
if (wasOpen) {
if (open(lastMode) != 0) {
throw Error(kerFileOpenFailed, path(), lastMode, strError());
throw Error(ErrorCode::kerFileOpenFailed, path(), lastMode, strError());
}
}
else close();
if (error() || src.error()) {
throw Error(kerTransferFailed, path(), strError());
throw Error(ErrorCode::kerTransferFailed, path(), strError());
}
} // FileIo::transfer
@ -530,11 +530,11 @@ namespace Exiv2 {
{
assert(p_->fp_);
if (static_cast<size_t>(rcount) > size())
throw Error(kerInvalidMalloc);
throw Error(ErrorCode::kerInvalidMalloc);
DataBuf buf(rcount);
size_t readCount = read(buf.data(), buf.size());
if (readCount == 0) {
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
}
buf.resize(readCount);
return buf;
@ -682,7 +682,7 @@ namespace Exiv2 {
size_t size = std::max(blockSize * (1 + need / blockSize), size_);
auto data = static_cast<byte*>(std::malloc(size));
if (!data) {
throw Error(kerMallocFailed);
throw Error(ErrorCode::kerMallocFailed);
}
if (data_) {
std::memcpy(data, data_, size_);
@ -700,7 +700,7 @@ namespace Exiv2 {
size_t want = blockSize * (1 + need / blockSize );
data_ = static_cast<byte*>(std::realloc(data_, want));
if (!data_) {
throw Error(kerMallocFailed);
throw Error(ErrorCode::kerMallocFailed);
}
sizeAlloced_ = want;
}
@ -756,13 +756,13 @@ namespace Exiv2 {
else {
// Generic reopen to reset position to start
if (src.open() != 0) {
throw Error(kerDataSourceOpenFailed, src.path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, src.path(), strError());
}
p_->idx_ = 0;
write(src);
src.close();
}
if (error() || src.error()) throw Error(kerMemoryTransferFailed, strError());
if (error() || src.error()) throw Error(ErrorCode::kerMemoryTransferFailed, strError());
}
size_t MemIo::write(BasicIo& src)
@ -910,12 +910,12 @@ namespace Exiv2 {
void XPathIo::ReadStdin() {
if (isatty(fileno(stdin)))
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
#ifdef _O_BINARY
// convert stdin to binary
if (_setmode(_fileno(stdin), _O_BINARY) == -1)
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
#endif
char readBuf[100*1024];
@ -932,7 +932,7 @@ namespace Exiv2 {
void XPathIo::ReadDataUri(const std::string& path) {
size_t base64Pos = path.find("base64,");
if (base64Pos == std::string::npos)
throw Error(kerErrorMessage, "No base64 data");
throw Error(ErrorCode::kerErrorMessage, "No base64 data");
std::string data = path.substr(base64Pos+7);
char* decodeData = new char[data.length()];
@ -940,7 +940,7 @@ namespace Exiv2 {
if (size > 0)
write((byte*)decodeData, size);
else
throw Error(kerErrorMessage, "Unable to decode base 64.");
throw Error(ErrorCode::kerErrorMessage, "Unable to decode base 64.");
delete[] decodeData;
}
@ -983,11 +983,11 @@ namespace Exiv2 {
if (prot == pStdin) {
if (isatty(fileno(stdin)))
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
#if defined(_MSC_VER) || defined(__MINGW__)
// convert stdin to binary
if (_setmode(_fileno(stdin), _O_BINARY) == -1)
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
#endif
std::ofstream fs(path.c_str(), std::ios::out | std::ios::binary | std::ios::trunc);
// read stdin and write to the temp file.
@ -1007,7 +1007,7 @@ namespace Exiv2 {
size_t base64Pos = orgPath.find("base64,");
if (base64Pos == std::string::npos) {
fs.close();
throw Error(kerErrorMessage, "No base64 data");
throw Error(ErrorCode::kerErrorMessage, "No base64 data");
}
std::string data = orgPath.substr(base64Pos+7);
@ -1018,7 +1018,7 @@ namespace Exiv2 {
fs.close();
} else {
fs.close();
throw Error(kerErrorMessage, "Unable to decode base 64.");
throw Error(ErrorCode::kerErrorMessage, "Unable to decode base 64.");
}
}
@ -1117,7 +1117,7 @@ namespace Exiv2 {
getDataByRange(static_cast<long>(lowBlock), static_cast<long>(highBlock), data);
rcount = data.length();
if (rcount == 0) {
throw Error(kerErrorMessage, "Data By Range is empty. Please check the permission.");
throw Error(ErrorCode::kerErrorMessage, "Data By Range is empty. Please check the permission.");
}
auto source = reinterpret_cast<byte*>(const_cast<char*>(data.c_str()));
size_t remain = rcount, totalRead = 0;
@ -1171,7 +1171,7 @@ namespace Exiv2 {
iBlock++;
}
} else if (length == 0) { // file is empty
throw Error(kerErrorMessage, "the file length is 0");
throw Error(ErrorCode::kerErrorMessage, "the file length is 0");
} else {
p_->size_ = static_cast<size_t>(length);
size_t nBlocks = (p_->size_ + p_->blockSize_ - 1) / p_->blockSize_;
@ -1284,7 +1284,7 @@ namespace Exiv2 {
DataBuf buf(rcount);
size_t readCount = read(buf.data(), buf.size());
if (readCount == 0) {
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
}
buf.resize(readCount);
return buf;
@ -1305,7 +1305,7 @@ namespace Exiv2 {
p_->populateBlocks(lowBlock, highBlock);
auto fakeData = static_cast<byte*>(std::calloc(p_->blockSize_, sizeof(byte)));
if (!fakeData) {
throw Error(kerErrorMessage, "Unable to allocate data");
throw Error(ErrorCode::kerErrorMessage, "Unable to allocate data");
}
size_t iBlock = lowBlock;
@ -1349,7 +1349,7 @@ namespace Exiv2 {
void RemoteIo::transfer(BasicIo& src)
{
if (src.open() != 0) {
throw Error(kerErrorMessage, "unable to open src when transferring");
throw Error(ErrorCode::kerErrorMessage, "unable to open src when transferring");
}
write(src);
src.close();
@ -1507,7 +1507,7 @@ namespace Exiv2 {
request["verb"] = "HEAD";
int serverCode = http(request, response, errors);
if (serverCode < 0 || serverCode >= 400 || !errors.empty()) {
throw Error(kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path);
throw Error(ErrorCode::kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path);
}
auto lengthIter = response.find("Content-Length");
@ -1532,7 +1532,7 @@ namespace Exiv2 {
int serverCode = http(request, responseDic, errors);
if (serverCode < 0 || serverCode >= 400 || !errors.empty()) {
throw Error(kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path);
throw Error(ErrorCode::kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path);
}
response = responseDic["body"];
}
@ -1541,7 +1541,7 @@ namespace Exiv2 {
{
std::string scriptPath(getEnv(envHTTPPOST));
if (scriptPath.empty()) {
throw Error(kerErrorMessage, "Please set the path of the server script to handle http post data to EXIV2_HTTP_POST environmental variable.");
throw Error(ErrorCode::kerErrorMessage, "Please set the path of the server script to handle http post data to EXIV2_HTTP_POST environmental variable.");
}
// standardize the path without "/" at the beginning.
@ -1584,7 +1584,7 @@ namespace Exiv2 {
int serverCode = http(request, response, errors);
if (serverCode < 0 || serverCode >= 400 || !errors.empty()) {
throw Error(kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path);
throw Error(ErrorCode::kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode), hostInfo_.Path);
}
}
@ -1646,7 +1646,7 @@ namespace Exiv2 {
CurlIo::CurlImpl::CurlImpl(const std::string& url, size_t blockSize) : Impl(url, blockSize), curl_(curl_easy_init())
{
if(!curl_) {
throw Error(kerErrorMessage, "Unable to init libcurl.");
throw Error(ErrorCode::kerErrorMessage, "Unable to init libcurl.");
}
// The default block size for FTP is much larger than other protocols
@ -1659,7 +1659,7 @@ namespace Exiv2 {
std::string timeout = getEnv(envTIMEOUT);
timeout_ = atol(timeout.c_str());
if (timeout_ == 0) {
throw Error(kerErrorMessage, "Timeout Environmental Variable must be a positive integer.");
throw Error(ErrorCode::kerErrorMessage, "Timeout Environmental Variable must be a positive integer.");
}
}
@ -1679,13 +1679,13 @@ namespace Exiv2 {
/* Perform the request, res will get the return code */
CURLcode res = curl_easy_perform(curl_);
if(res != CURLE_OK) { // error happened
throw Error(kerErrorMessage, curl_easy_strerror(res));
throw Error(ErrorCode::kerErrorMessage, curl_easy_strerror(res));
}
// get status
int serverCode;
curl_easy_getinfo (curl_, CURLINFO_RESPONSE_CODE, &serverCode); // get code
if (serverCode >= 400 || serverCode < 0) {
throw Error(kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode),path_);
throw Error(ErrorCode::kerFileOpenFailed, "http",Exiv2::Internal::stringFormat("%d",serverCode),path_);
}
// get length
double temp;
@ -1717,12 +1717,12 @@ namespace Exiv2 {
CURLcode res = curl_easy_perform(curl_);
if(res != CURLE_OK) {
throw Error(kerErrorMessage, curl_easy_strerror(res));
throw Error(ErrorCode::kerErrorMessage, curl_easy_strerror(res));
}
int serverCode;
curl_easy_getinfo(curl_, CURLINFO_RESPONSE_CODE, &serverCode); // get code
if (serverCode >= 400 || serverCode < 0) {
throw Error(kerFileOpenFailed, "http", Exiv2::Internal::stringFormat("%d", serverCode), path_);
throw Error(ErrorCode::kerFileOpenFailed, "http", Exiv2::Internal::stringFormat("%d", serverCode), path_);
}
}
@ -1730,7 +1730,7 @@ namespace Exiv2 {
{
std::string scriptPath(getEnv(envHTTPPOST));
if (scriptPath.empty()) {
throw Error(kerErrorMessage, "Please set the path of the server script to handle http post data to EXIV2_HTTP_POST environmental variable.");
throw Error(ErrorCode::kerErrorMessage, "Please set the path of the server script to handle http post data to EXIV2_HTTP_POST environmental variable.");
}
Exiv2::Uri hostInfo = Exiv2::Uri::Parse(path_);
@ -1767,12 +1767,12 @@ namespace Exiv2 {
CURLcode res = curl_easy_perform(curl_);
if(res != CURLE_OK) {
throw Error(kerErrorMessage, curl_easy_strerror(res));
throw Error(ErrorCode::kerErrorMessage, curl_easy_strerror(res));
}
int serverCode;
curl_easy_getinfo(curl_, CURLINFO_RESPONSE_CODE, &serverCode);
if (serverCode >= 400 || serverCode < 0) {
throw Error(kerFileOpenFailed, "http", Exiv2::Internal::stringFormat("%d", serverCode), path_);
throw Error(ErrorCode::kerFileOpenFailed, "http", Exiv2::Internal::stringFormat("%d", serverCode), path_);
}
}
@ -1785,7 +1785,7 @@ namespace Exiv2 {
if (p_->protocol_ == pHttp || p_->protocol_ == pHttps) {
return RemoteIo::write(data, wcount);
}
throw Error(kerErrorMessage, "doesnt support write for this protocol.");
throw Error(ErrorCode::kerErrorMessage, "doesnt support write for this protocol.");
}
size_t CurlIo::write(BasicIo& src)
@ -1793,7 +1793,7 @@ namespace Exiv2 {
if (p_->protocol_ == pHttp || p_->protocol_ == pHttps) {
return RemoteIo::write(src);
}
throw Error(kerErrorMessage, "doesnt support write for this protocol.");
throw Error(ErrorCode::kerErrorMessage, "doesnt support write for this protocol.");
}
CurlIo::CurlIo(const std::string& url, size_t blockSize)
@ -1810,16 +1810,16 @@ namespace Exiv2 {
{
FileIo file(path);
if (file.open("rb") != 0) {
throw Error(kerFileOpenFailed, path, "rb", strError());
throw Error(ErrorCode::kerFileOpenFailed, path, "rb", strError());
}
struct stat st;
if (0 != ::stat(path.c_str(), &st)) {
throw Error(kerCallFailed, path, strError(), "::stat");
throw Error(ErrorCode::kerCallFailed, path, strError(), "::stat");
}
DataBuf buf(st.st_size);
const size_t len = file.read(buf.data(), buf.size());
if (len != buf.size()) {
throw Error(kerCallFailed, path, strError(), "FileIo::read");
throw Error(ErrorCode::kerCallFailed, path, strError(), "FileIo::read");
}
return buf;
}
@ -1828,7 +1828,7 @@ namespace Exiv2 {
{
FileIo file(path);
if (file.open("wb") != 0) {
throw Error(kerFileOpenFailed, path, "wb", strError());
throw Error(ErrorCode::kerFileOpenFailed, path, "wb", strError());
}
return file.write(buf.c_data(), buf.size());
}

@ -173,7 +173,7 @@ namespace Exiv2
// never visit a box twice!
if ( depth == 0 ) visits_.clear();
if (visits_.find(address) != visits_.end() || visits_.size() > visits_max_) {
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
visits_.insert(address);
@ -186,7 +186,7 @@ namespace Exiv2
byte hdrbuf[2 * sizeof(uint32_t)];
size_t hdrsize = sizeof(hdrbuf);
enforce(hdrsize <= static_cast<size_t>(pbox_end - address), Exiv2::kerCorruptedMetadata);
enforce(hdrsize <= static_cast<size_t>(pbox_end - address), Exiv2::ErrorCode::kerCorruptedMetadata);
if (io_->read(reinterpret_cast<byte*>(&hdrbuf), sizeof(hdrbuf)) != sizeof(hdrbuf))
return pbox_end;
@ -205,7 +205,7 @@ namespace Exiv2
if (box_length == 1) {
// The box size is encoded as a uint64_t, so we need to read another 8 bytes.
hdrsize += 8;
enforce(hdrsize <= static_cast<size_t>(pbox_end - address), Exiv2::kerCorruptedMetadata);
enforce(hdrsize <= static_cast<size_t>(pbox_end - address), Exiv2::ErrorCode::kerCorruptedMetadata);
DataBuf data(8);
io_->read(data.data(), data.size());
box_length = data.read_uint64(0, endian_);
@ -213,8 +213,8 @@ namespace Exiv2
// read data in box and restore file position
long restore = io_->tell();
enforce(box_length >= hdrsize, Exiv2::kerCorruptedMetadata);
enforce(box_length - hdrsize <= static_cast<uint64_t>(pbox_end - restore), Exiv2::kerCorruptedMetadata);
enforce(box_length >= hdrsize, Exiv2::ErrorCode::kerCorruptedMetadata);
enforce(box_length - hdrsize <= static_cast<uint64_t>(pbox_end - restore), Exiv2::ErrorCode::kerCorruptedMetadata);
const auto buffer_size = static_cast<size_t>(box_length - hdrsize);
if (skipBox(box_type)) {
@ -236,7 +236,7 @@ namespace Exiv2
uint32_t flags = 0;
if (fullBox(box_type)) {
enforce(data.size() - skip >= 4, Exiv2::kerCorruptedMetadata);
enforce(data.size() - skip >= 4, Exiv2::ErrorCode::kerCorruptedMetadata);
flags = data.read_uint32(skip, endian_); // version/flags
version = static_cast<uint8_t>(flags >> 24);
flags &= 0x00ffffff;
@ -246,7 +246,7 @@ namespace Exiv2
switch (box_type) {
// See notes in skipBox()
case TAG_ftyp: {
enforce(data.size() >= 4, Exiv2::kerCorruptedMetadata);
enforce(data.size() >= 4, Exiv2::ErrorCode::kerCorruptedMetadata);
fileType_ = data.read_uint32(0, endian_);
if ( bTrace ) {
out << "brand: " << toAscii(fileType_);
@ -260,7 +260,7 @@ namespace Exiv2
bLF = false;
}
enforce(data.size() - skip >= 2, Exiv2::kerCorruptedMetadata);
enforce(data.size() - skip >= 2, Exiv2::ErrorCode::kerCorruptedMetadata);
uint16_t n = data.read_uint16(skip, endian_);
skip += 2;
@ -272,7 +272,7 @@ namespace Exiv2
// 8.11.6.2
case TAG_infe: { // .__._.__hvc1_ 2 0 0 1 0 1 0 0 104 118 99 49 0
enforce(data.size() - skip >= 8, Exiv2::kerCorruptedMetadata);
enforce(data.size() - skip >= 8, Exiv2::ErrorCode::kerCorruptedMetadata);
/* getLong (data.pData_+skip,endian_) ; */ skip += 4;
uint16_t ID = data.read_uint16(skip, endian_);
skip += 2;
@ -281,7 +281,7 @@ namespace Exiv2
// Check that the string has a '\0' terminator.
const char* str = data.c_str(skip);
const size_t maxlen = data.size() - skip;
enforce(maxlen > 0 && strnlen(str, maxlen) < maxlen, Exiv2::kerCorruptedMetadata);
enforce(maxlen > 0 && strnlen(str, maxlen) < maxlen, Exiv2::ErrorCode::kerCorruptedMetadata);
std::string name(str);
if (name.find("Exif") != std::string::npos) { // "Exif" or "ExifExif"
exifID_ = ID;
@ -330,7 +330,7 @@ namespace Exiv2
// 8.11.3.1
case TAG_iloc: {
enforce(data.size() - skip >= 2, Exiv2::kerCorruptedMetadata);
enforce(data.size() - skip >= 2, Exiv2::ErrorCode::kerCorruptedMetadata);
uint8_t u = data.read_uint8(skip++);
uint16_t offsetSize = u >> 4;
uint16_t lengthSize = u & 0xF;
@ -343,7 +343,7 @@ namespace Exiv2
#else
skip++;
#endif
enforce(data.size() - skip >= (version < 2u ? 2u : 4u), Exiv2::kerCorruptedMetadata);
enforce(data.size() - skip >= (version < 2u ? 2u : 4u), Exiv2::ErrorCode::kerCorruptedMetadata);
uint32_t itemCount = version < 2 ? data.read_uint16(skip, endian_)
: data.read_uint32(skip, endian_);
skip += version < 2 ? 2 : 4;
@ -357,8 +357,8 @@ namespace Exiv2
size_t base = skip;
for (uint32_t i = 0; i < itemCount; i++) {
skip = base + i * step; // move in 14, 16 or 18 byte steps
enforce(data.size() - skip >= (version > 2u ? 4u : 2u), Exiv2::kerCorruptedMetadata);
enforce(data.size() - skip >= step, Exiv2::kerCorruptedMetadata);
enforce(data.size() - skip >= (version > 2u ? 4u : 2u), Exiv2::ErrorCode::kerCorruptedMetadata);
enforce(data.size() - skip >= step, Exiv2::ErrorCode::kerCorruptedMetadata);
uint32_t ID = version > 2 ? data.read_uint32(skip, endian_)
: data.read_uint16(skip, endian_);
uint32_t offset = step==14 || step==16 ? data.read_uint32(skip + step - 8, endian_)
@ -381,7 +381,7 @@ namespace Exiv2
} break;
case TAG_ispe: {
enforce(data.size() - skip >= 12, Exiv2::kerCorruptedMetadata);
enforce(data.size() - skip >= 12, Exiv2::ErrorCode::kerCorruptedMetadata);
skip += 4;
uint32_t width = data.read_uint32(skip, endian_);
skip += 4;
@ -492,10 +492,10 @@ namespace Exiv2
void BmffImage::parseTiff(uint32_t root_tag, uint64_t length,uint64_t start)
{
enforce(start <= io_->size(), kerCorruptedMetadata);
enforce(length <= io_->size() - start, kerCorruptedMetadata);
enforce(start <= std::numeric_limits<uint64_t>::max(), kerCorruptedMetadata);
enforce(length <= std::numeric_limits<uint64_t>::max(), kerCorruptedMetadata);
enforce(start <= io_->size(), ErrorCode::kerCorruptedMetadata);
enforce(length <= io_->size() - start, ErrorCode::kerCorruptedMetadata);
enforce(start <= std::numeric_limits<uint64_t>::max(), ErrorCode::kerCorruptedMetadata);
enforce(length <= std::numeric_limits<uint64_t>::max(), ErrorCode::kerCorruptedMetadata);
// read and parse exif data
long restore = io_->tell();
@ -522,15 +522,15 @@ namespace Exiv2
void BmffImage::parseTiff(uint32_t root_tag, uint64_t length)
{
if (length > 8) {
enforce(length - 8 <= io_->size() - io_->tell(), kerCorruptedMetadata);
enforce(length - 8 <= std::numeric_limits<uint64_t>::max(), kerCorruptedMetadata);
enforce(length - 8 <= io_->size() - io_->tell(), ErrorCode::kerCorruptedMetadata);
enforce(length - 8 <= std::numeric_limits<uint64_t>::max(), ErrorCode::kerCorruptedMetadata);
DataBuf data(static_cast<size_t>(length) - 8);
const size_t bufRead = io_->read(data.data(), data.size());
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != data.size())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
Internal::TiffParserWorker::decode(exifData(), iptcData(), xmpData(),
data.c_data(), static_cast<uint32_t>(data.size()), root_tag,
@ -541,24 +541,24 @@ namespace Exiv2
void BmffImage::parseXmp(uint64_t length,uint64_t start)
{
if (length > 8) {
enforce(start <= io_->size(), kerCorruptedMetadata);
enforce(length <= io_->size() - start, kerCorruptedMetadata);
enforce(start <= io_->size(), ErrorCode::kerCorruptedMetadata);
enforce(length <= io_->size() - start, ErrorCode::kerCorruptedMetadata);
long restore = io_->tell() ;
enforce(start <= std::numeric_limits<uint64_t>::max(), kerCorruptedMetadata);
enforce(start <= std::numeric_limits<uint64_t>::max(), ErrorCode::kerCorruptedMetadata);
io_->seek(static_cast<long>(start),BasicIo::beg);
enforce(length < std::numeric_limits<uint64_t>::max(), kerCorruptedMetadata);
enforce(length < std::numeric_limits<uint64_t>::max(), ErrorCode::kerCorruptedMetadata);
DataBuf xmp(static_cast<size_t>(length+1));
xmp.write_uint8(static_cast<size_t>(length), 0); // ensure xmp is null terminated!
if ( io_->read(xmp.data(), static_cast<size_t>(length)) != length )
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
if ( io_->error() )
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
try {
Exiv2::XmpParser::decode(xmpData(), std::string(xmp.c_str()));
} catch (...) {
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
io_->seek(restore,BasicIo::beg);
@ -579,7 +579,7 @@ namespace Exiv2
long here = io_->tell();
enforce(here >= 0 &&
here <= std::numeric_limits<long>::max() - static_cast<long>(relative_position),
kerCorruptedMetadata);
ErrorCode::kerCorruptedMetadata);
NativePreview nativePreview;
nativePreview.position_ = here + static_cast<long>(relative_position);
nativePreview.width_ = data.read_uint16(width_offset, endian_);
@ -607,19 +607,19 @@ namespace Exiv2
void BmffImage::setComment(std::string_view /*comment*/)
{
// bmff files are read-only
throw(Error(kerInvalidSettingForImage, "Image comment", "BMFF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "BMFF"));
}
void BmffImage::openOrThrow()
{
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
// Ensure that this is the correct image type
if (!isBmffType(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "BMFF");
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "BMFF");
}
} // Bmff::openOrThrow();
@ -659,7 +659,7 @@ namespace Exiv2
case kpsXMP : {
std::string xmp;
if ( Exiv2::XmpParser::encode(xmp, xmpData()) ) {
throw Exiv2::Error(Exiv2::kerErrorMessage, "Failed to serialize XMP data");
throw Exiv2::Error(Exiv2::ErrorCode::kerErrorMessage, "Failed to serialize XMP data");
}
out << xmp;
} break;
@ -682,7 +682,7 @@ namespace Exiv2
void BmffImage::writeMetadata()
{
// bmff files are read-only
throw(Error(kerInvalidSettingForImage, "Image comment", "BMFF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "BMFF"));
} // BmffImage::writeMetadata
// *************************************************************************

@ -32,17 +32,17 @@ namespace Exiv2
void BmpImage::setExifData(const ExifData& /*exifData*/)
{
throw(Error(kerInvalidSettingForImage, "Exif metadata", "BMP"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Exif metadata", "BMP"));
}
void BmpImage::setIptcData(const IptcData& /*iptcData*/)
{
throw(Error(kerInvalidSettingForImage, "IPTC metadata", "BMP"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "IPTC metadata", "BMP"));
}
void BmpImage::setComment(std::string_view /*comment*/)
{
throw(Error(kerInvalidSettingForImage, "Image comment", "BMP"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "BMP"));
}
void BmpImage::readMetadata()
@ -51,15 +51,15 @@ namespace Exiv2
std::cerr << "Exiv2::BmpImage::readMetadata: Reading Windows bitmap file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isBmpType(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "BMP");
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "BMP");
}
clearMetadata();
@ -94,7 +94,7 @@ namespace Exiv2
void BmpImage::writeMetadata()
{
/// \todo implement me!
throw(Error(kerWritingImageFormatUnsupported, "BMP"));
throw(Error(ErrorCode::kerWritingImageFormatUnsupported, "BMP"));
}
// *************************************************************************

@ -2767,7 +2767,7 @@ namespace Exiv2::Internal {
if (!std::regex_search(lens.label_, base_match, lens_regex)) {
// this should never happen, as it would indicate the lens is specified incorrectly
// in the CanonCsLensType array
throw Error(kerErrorMessage, std::string("Lens regex didn't match for: ") + std::string(lens.label_));
throw Error(ErrorCode::kerErrorMessage, std::string("Lens regex didn't match for: ") + std::string(lens.label_));
}
auto tc = base_match[5].length() > 0 ? std::stof(base_match[5].str()) : 1.f;

@ -49,7 +49,8 @@ namespace Exiv2 {
void Cr2Image::printStructure(std::ostream& out, Exiv2::PrintStructureOption option,int depth)
{
if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError());
if (io_->open() != 0)
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
io_->seek(0,BasicIo::beg);
printTiffStructure(io(),out,option,depth-1);
}
@ -57,7 +58,7 @@ namespace Exiv2 {
void Cr2Image::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "CR2"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "CR2"));
}
void Cr2Image::readMetadata()
@ -66,13 +67,14 @@ namespace Exiv2 {
std::cerr << "Reading CR2 file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isCr2Type(*io_, false)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "CR2");
if (io_->error() || io_->eof())
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "CR2");
}
clearMetadata();
ByteOrder bo =

@ -52,7 +52,7 @@ namespace Exiv2 {
void CrwImage::setIptcData(const IptcData& /*iptcData*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "IPTC metadata", "CRW"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "IPTC metadata", "CRW"));
}
void CrwImage::readMetadata()
@ -61,13 +61,14 @@ namespace Exiv2 {
std::cerr << "Reading CRW file " << io_->path() << "\n";
#endif
if (io_->open()) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isCrwType(*io_, false)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotACrwImage);
if (io_->error() || io_->eof())
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotACrwImage);
}
clearMetadata();
DataBuf file(io().size());
@ -102,7 +103,7 @@ namespace Exiv2 {
// Write new buffer to file
auto tempIo = std::make_unique<MemIo>();
tempIo->write((!blob.empty() ? &blob[0] : nullptr), static_cast<long>(blob.size()));
tempIo->write((!blob.empty() ? &blob[0] : nullptr), blob.size());
io_->close();
io_->transfer(*tempIo); // may throw

@ -161,7 +161,7 @@ namespace Exiv2::Internal {
void CiffEntry::doAdd(UniquePtr /*component*/)
{
throw Error(kerFunctionNotSupported, "CiffEntry::add");
throw Error(ErrorCode::kerFunctionNotSupported, "CiffEntry::add");
} // CiffEntry::doAdd
void CiffDirectory::doAdd(UniquePtr component)
@ -171,7 +171,8 @@ namespace Exiv2::Internal {
void CiffHeader::read(const byte* pData, uint32_t size)
{
if (size < 14) throw Error(kerNotACrwImage);
if (size < 14) throw
Error(ErrorCode::kerNotACrwImage);
if (pData[0] == 'I' && pData[0] == pData[1]) {
byteOrder_ = littleEndian;
@ -180,12 +181,13 @@ namespace Exiv2::Internal {
byteOrder_ = bigEndian;
}
else {
throw Error(kerNotACrwImage);
throw Error(ErrorCode::kerNotACrwImage);
}
offset_ = getULong(pData + 2, byteOrder_);
if (offset_ < 14 || offset_ > size) throw Error(kerNotACrwImage);
if (offset_ < 14 || offset_ > size)
throw Error(ErrorCode::kerNotACrwImage);
if (std::memcmp(pData + 6, signature(), 8) != 0) {
throw Error(kerNotACrwImage);
throw Error(ErrorCode::kerNotACrwImage);
}
pPadding_.clear();
@ -211,7 +213,7 @@ namespace Exiv2::Internal {
ByteOrder byteOrder)
{
// We're going read 10 bytes. Make sure they won't be out-of-bounds.
enforce(size >= 10 && start <= size - 10, kerNotACrwImage);
enforce(size >= 10 && start <= size - 10, ErrorCode::kerNotACrwImage);
tag_ = getUShort(pData + start, byteOrder);
DataLocId dl = dataLocation();
@ -228,12 +230,12 @@ namespace Exiv2::Internal {
// bytes in memory.
if (offset_ < start) {
// Sub-region is before in memory.
enforce(size_ <= start - offset_, kerOffsetOutOfRange);
enforce(size_ <= start - offset_, ErrorCode::kerOffsetOutOfRange);
} else {
// Sub-region is after in memory.
enforce(offset_ >= start + 10, kerOffsetOutOfRange);
enforce(offset_ <= size, kerOffsetOutOfRange);
enforce(size_ <= size - offset_, kerOffsetOutOfRange);
enforce(offset_ >= start + 10, ErrorCode::kerOffsetOutOfRange);
enforce(offset_ <= size, ErrorCode::kerOffsetOutOfRange);
enforce(size_ <= size - offset_, ErrorCode::kerOffsetOutOfRange);
}
}
if (dl == directoryData) {
@ -260,7 +262,7 @@ namespace Exiv2::Internal {
std::cout << "Reading directory 0x" << std::hex << tag() << "\n";
#endif
if (this->offset() + this->size() > size)
throw Error(kerOffsetOutOfRange);
throw Error(ErrorCode::kerOffsetOutOfRange);
readDirectory(pData + offset(), this->size(), byteOrder);
#ifdef EXIV2_DEBUG_MESSAGES
@ -273,10 +275,10 @@ namespace Exiv2::Internal {
ByteOrder byteOrder)
{
if (size < 4)
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
uint32_t o = getULong(pData + size - 4, byteOrder);
if ( o > size-2 )
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
uint16_t count = getUShort(pData + o, byteOrder);
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Directory at offset " << std::dec << o
@ -284,7 +286,7 @@ namespace Exiv2::Internal {
#endif
o += 2;
if ( static_cast<uint32_t>(count) * 10 > size-o )
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
for (uint16_t i = 0; i < count; ++i) {
uint16_t tag = getUShort(pData + o, byteOrder);
@ -544,7 +546,7 @@ namespace Exiv2::Internal {
switch (tag & 0xc000) {
case 0x0000: return valueData;
case 0x4000: return directoryData;
default: throw Error(kerCorruptedMetadata);
default: throw Error(ErrorCode::kerCorruptedMetadata);
}
} // CiffComponent::dataLocation
@ -810,8 +812,8 @@ namespace Exiv2::Internal {
std::string groupName(Internal::groupName(ifdId));
const uint32_t component_size = ciffComponent.size();
enforce(component_size % 2 == 0, kerCorruptedMetadata);
enforce(component_size/2 <= static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()), kerCorruptedMetadata);
enforce(component_size % 2 == 0, ErrorCode::kerCorruptedMetadata);
enforce(component_size/2 <= static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()), ErrorCode::kerCorruptedMetadata);
const auto num_components = static_cast<uint16_t>(component_size / 2);
uint16_t c = 1;
while (c < num_components) {
@ -1117,7 +1119,7 @@ namespace Exiv2::Internal {
uint32_t size = 28;
if (cc) {
if (cc->size() < size)
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
size = cc->size();
}
DataBuf buf(size);

@ -378,7 +378,6 @@ namespace Exiv2 {
false, false, 0, 0, Exiv2::unsignedShort, IptcDataSets::application2, ""},
};
constexpr DataSet unknownDataSet{
0xffff, "Unknown dataset", N_("Unknown dataset"), N_("Unknown dataset"), false, true, 0,
0xffffffff, Exiv2::string, IptcDataSets::invalidRecord, N_("Unknown dataset"),
@ -489,7 +488,7 @@ namespace Exiv2 {
dataSet = records_[recordId][idx].number_;
} else {
if (!isHex(dataSetName, 4, "0x"))
throw Error(kerInvalidDataset, dataSetName);
throw Error(ErrorCode::kerInvalidDataset, dataSetName);
std::istringstream is(dataSetName);
is >> std::hex >> dataSet;
}
@ -610,7 +609,7 @@ namespace Exiv2 {
static const std::regex re(R"((\w+)(\.\w+){2})");
std::smatch sm;
if (!std::regex_match(key_, sm, re)) {
throw Error(kerInvalidKey, key_);
throw Error(ErrorCode::kerInvalidKey, key_);
}
// Get the family name, record name and dataSet name parts of the key
@ -619,7 +618,7 @@ namespace Exiv2 {
const std::string familyName = key_.substr(0, posDot1);
if (0 != strcmp(familyName.c_str(), familyName_)) {
throw Error(kerInvalidKey, key_);
throw Error(ErrorCode::kerInvalidKey, key_);
}
std::string recordName = key_.substr(posDot1+1, posDot2 - posDot1 - 1);

@ -95,7 +95,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to write to temporary file.\n";
#endif
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
}
@ -113,7 +113,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Internal error while determining current write position in temporary file.\n";
#endif
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
return static_cast<uint32_t>(pos);
}
@ -201,7 +201,7 @@ namespace {
EXV_WARNING << "Unable to handle read-only XMP metadata yet. Please provide your "
"sample EPS file to the Exiv2 project: http://dev.exiv2.org/projects/exiv2\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
// search for end of XMP trailer
@ -214,13 +214,13 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Found XMP header but incomplete XMP trailer.\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
}
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Found XMP header but no XMP trailer.\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
}
}
@ -230,7 +230,7 @@ namespace {
{
// open input file
if (io.open() != 0) {
throw Error(kerDataSourceOpenFailed, io.path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io.path(), strError());
}
IoCloser closer(io);
@ -256,7 +256,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Premature end of file after DOS EPS signature.\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
posEps = getULong(data + 4, littleEndian);
posEndEps = getULong(data + 8, littleEndian) + posEps;
@ -279,31 +279,31 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "DOS EPS file has both WMF and TIFF section. Only one of those is allowed.\n";
#endif
if (write) throw Error(kerImageWriteFailed);
if (write) throw Error(ErrorCode::kerImageWriteFailed);
}
if (sizeWmf == 0 && sizeTiff == 0) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "DOS EPS file has neither WMF nor TIFF section. Exactly one of those is required.\n";
#endif
if (write) throw Error(kerImageWriteFailed);
if (write) throw Error(ErrorCode::kerImageWriteFailed);
}
if (posEps < 30 || posEndEps > size) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "DOS EPS file has invalid position (" << posEps << ") or size (" << (posEndEps - posEps) << ") for EPS section.\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
if (sizeWmf != 0 && (posWmf < 30 || posWmf + sizeWmf > size)) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "DOS EPS file has invalid position (" << posWmf << ") or size (" << sizeWmf << ") for WMF section.\n";
#endif
if (write) throw Error(kerImageWriteFailed);
if (write) throw Error(ErrorCode::kerImageWriteFailed);
}
if (sizeTiff != 0 && (posTiff < 30 || posTiff + sizeTiff > size)) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "DOS EPS file has invalid position (" << posTiff << ") or size (" << sizeTiff << ") for TIFF section.\n";
#endif
if (write) throw Error(kerImageWriteFailed);
if (write) throw Error(ErrorCode::kerImageWriteFailed);
}
}
@ -315,7 +315,7 @@ namespace {
#endif
bool matched = std::find(epsFirstLine.begin(), epsFirstLine.end(), firstLine) != epsFirstLine.end();
if (!matched) {
throw Error(kerNotAnImage, "EPS");
throw Error(ErrorCode::kerNotAnImage, "EPS");
}
// determine line ending style of the first line
@ -323,7 +323,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Premature end of file after first line.\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
const std::string lineEnding(reinterpret_cast<const char*>(data + posEps + firstLine.size()), posSecondLine - (posEps + firstLine.size()));
#ifdef DEBUG
@ -378,14 +378,14 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Nested document at invalid position: " << startPos << "\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
if (startsWith(line, "%%BeginDocument:")) {
if (depth == maxDepth) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Document too deeply nested at position: " << startPos << "\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
depth++;
} else if (startsWith(line, "%%EndDocument")) {
@ -393,7 +393,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Unmatched EndDocument at position: " << startPos << "\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
depth--;
} else {
@ -424,12 +424,12 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Page at position " << startPos << " conflicts with implicit page at position: " << posPage << "\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Unable to handle multiple PostScript pages. Found second page at position: " << startPos << "\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
} else if (line == "%%BeginPageSetup") {
posBeginPageSetup = startPos;
} else if (!inRemovableEmbedding && line == "%Exiv2BeginXMP: Before %%EndPageSetup") {
@ -581,7 +581,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Unmatched BeginDocument (" << depth << "x)\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
// look for the unmarked trailers of some removable XMP embeddings
@ -601,7 +601,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Unable to find XMP embedding trailer ending at position: " << posXmpTrailerEnd << "\n";
#endif
if (write) throw Error(kerImageWriteFailed);
if (write) throw Error(ErrorCode::kerImageWriteFailed);
break;
}
removableEmbeddings.emplace_back(posXmpTrailer, posXmpTrailerEnd);
@ -625,7 +625,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Invalid line \"" << line << "\" at position: " << posContainsXmp << "\n";
#endif
throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData);
throw Error(write ? ErrorCode::kerImageWriteFailed : ErrorCode::kerFailedToReadImageData);
}
const bool deleteXmp = (write && xmpPacket.empty());
@ -672,7 +672,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Missing %begin_xml_packet in Photoshop EPS at position: " << xmpPos << "\n";
#endif
if (write) throw Error(kerImageWriteFailed);
if (write) throw Error(ErrorCode::kerImageWriteFailed);
}
}
if (!useFlexibleEmbedding) {
@ -693,7 +693,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "XMP metadata block is not removable at position: " << posOtherXmp << "\n";
#endif
if (write) throw Error(kerImageWriteFailed);
if (write) throw Error(ErrorCode::kerImageWriteFailed);
break;
}
}
@ -780,7 +780,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Unable to write to EPS files created by Adobe Illustrator 8.0 or older.\n";
#endif
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
// create temporary output file
@ -789,7 +789,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Unable to create temporary file for writing.\n";
#endif
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
#ifdef DEBUG
EXV_DEBUG << "readWriteEpsMetadata: Created temporary file " << tempIo->path() << "\n";
@ -836,7 +836,7 @@ namespace {
EXV_WARNING << "Internal error while assembling the result EPS document: "
"Unable to continue at position " << pos << " after skipping to position " << prevSkipPos << "\n";
#endif
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
writeTemp(tempIo, data + prevSkipPos, pos - prevSkipPos);
const size_t posLineEnd = readLine(line, data, pos, posEndEps);
@ -1025,7 +1025,7 @@ namespace {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Internal error while seeking in temporary file.\n";
#endif
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
byte dosEpsHeader[30];
dosEpsSignature.copy(reinterpret_cast<char*>(dosEpsHeader), dosEpsSignature.size());
@ -1066,7 +1066,7 @@ namespace Exiv2
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to write blank EPS image.\n";
#endif
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
}
}
@ -1079,7 +1079,7 @@ namespace Exiv2
void EpsImage::setComment(std::string_view /*comment*/)
{
throw Error(kerInvalidSettingForImage, "Image comment", "EPS");
throw Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "EPS");
}
void EpsImage::readMetadata()
@ -1096,7 +1096,7 @@ namespace Exiv2
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to decode XMP metadata.\n";
#endif
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
#ifdef DEBUG
@ -1115,7 +1115,7 @@ namespace Exiv2
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to encode XMP metadata.\n";
#endif
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
// write metadata

@ -15,137 +15,137 @@ namespace {
//! Helper structure defining an error message.
struct ErrMsg {
//! Comparison operator
bool operator==(int code) const { return code_ == code; }
bool operator==(Exiv2::ErrorCode code) const { return code_ == code; }
int code_; //!< Error code
Exiv2::ErrorCode code_; //!< Error code
const char* message_; //!< Error message
};
//! Complete list of Exiv2 exception error messages
const ErrMsg errList[] = {
{ Exiv2::kerGeneralError,
{ Exiv2::ErrorCode::kerGeneralError,
N_("Error %0: arg2=%2, arg3=%3, arg1=%1.") },
{ Exiv2::kerSuccess,
{ Exiv2::ErrorCode::kerSuccess,
N_("Success") },
{ Exiv2::kerErrorMessage,
{ Exiv2::ErrorCode::kerErrorMessage,
"%1" }, // %1=error message
{ Exiv2::kerCallFailed,
{ Exiv2::ErrorCode::kerCallFailed,
"%1: Call to `%3' failed: %2" }, // %1=path, %2=strerror, %3=function that failed
{ Exiv2::kerNotAnImage,
{ Exiv2::ErrorCode::kerNotAnImage,
N_("This does not look like a %1 image") }, // %1=Image type
{ Exiv2::kerInvalidDataset,
{ Exiv2::ErrorCode::kerInvalidDataset,
N_("Invalid dataset name '%1'") }, // %1=dataset name
{ Exiv2::kerInvalidRecord,
{ Exiv2::ErrorCode::kerInvalidRecord,
N_("Invalid record name '%1'") }, // %1=record name
{ Exiv2::kerInvalidKey,
{ Exiv2::ErrorCode::kerInvalidKey,
N_("Invalid key '%1'") }, // %1=key
{ Exiv2::kerInvalidTag,
{ Exiv2::ErrorCode::kerInvalidTag,
N_("Invalid tag name or ifdId `%1', ifdId %2") }, // %1=tag name, %2=ifdId
{ Exiv2::kerValueNotSet,
{ Exiv2::ErrorCode::kerValueNotSet,
N_("Value not set") },
{ Exiv2::kerDataSourceOpenFailed,
{ Exiv2::ErrorCode::kerDataSourceOpenFailed,
N_("%1: Failed to open the data source: %2") }, // %1=path, %2=strerror
{ Exiv2::kerFileOpenFailed,
{ Exiv2::ErrorCode::kerFileOpenFailed,
N_("%1: Failed to open file (%2): %3") }, // %1=path, %2=mode, %3=strerror
{ Exiv2::kerFileContainsUnknownImageType,
{ Exiv2::ErrorCode::kerFileContainsUnknownImageType,
N_("%1: The file contains data of an unknown image type") }, // %1=path
{ Exiv2::kerMemoryContainsUnknownImageType,
{ Exiv2::ErrorCode::kerMemoryContainsUnknownImageType,
N_("The memory contains data of an unknown image type") },
{ Exiv2::kerUnsupportedImageType,
{ Exiv2::ErrorCode::kerUnsupportedImageType,
N_("Image type %1 is not supported") }, // %1=image type
{ Exiv2::kerFailedToReadImageData,
{ Exiv2::ErrorCode::kerFailedToReadImageData,
N_("Failed to read image data") },
{ Exiv2::kerNotAJpeg,
{ Exiv2::ErrorCode::kerNotAJpeg,
N_("This does not look like a JPEG image") },
{ Exiv2::kerFailedToMapFileForReadWrite,
{ Exiv2::ErrorCode::kerFailedToMapFileForReadWrite,
N_("%1: Failed to map file for reading and writing: %2") }, // %1=path, %2=strerror
{ Exiv2::kerFileRenameFailed,
{ Exiv2::ErrorCode::kerFileRenameFailed,
N_("%1: Failed to rename file to %2: %3") }, // %1=old path, %2=new path, %3=strerror
{ Exiv2::kerTransferFailed,
{ Exiv2::ErrorCode::kerTransferFailed,
N_("%1: Transfer failed: %2") }, // %1=path, %2=strerror
{ Exiv2::kerMemoryTransferFailed,
{ Exiv2::ErrorCode::kerMemoryTransferFailed,
N_("Memory transfer failed: %1") }, // %1=strerror
{ Exiv2::kerInputDataReadFailed,
{ Exiv2::ErrorCode::kerInputDataReadFailed,
N_("Failed to read input data") },
{ Exiv2::kerImageWriteFailed,
{ Exiv2::ErrorCode::kerImageWriteFailed,
N_("Failed to write image") },
{ Exiv2::kerNoImageInInputData,
{ Exiv2::ErrorCode::kerNoImageInInputData,
N_("Input data does not contain a valid image") },
{ Exiv2::kerInvalidIfdId,
{ Exiv2::ErrorCode::kerInvalidIfdId,
N_("Invalid ifdId %1") }, // %1=ifdId
{ Exiv2::kerValueTooLarge,
{ Exiv2::ErrorCode::kerValueTooLarge,
N_("Entry::setValue: Value too large (tag=%1, size=%2, requested=%3)") }, // %1=tag, %2=dataSize, %3=required size
{ Exiv2::kerDataAreaValueTooLarge,
{ Exiv2::ErrorCode::kerDataAreaValueTooLarge,
N_("Entry::setDataArea: Value too large (tag=%1, size=%2, requested=%3)") }, // %1=tag, %2=dataAreaSize, %3=required size
{ Exiv2::kerOffsetOutOfRange,
{ Exiv2::ErrorCode::kerOffsetOutOfRange,
N_("Offset out of range") },
{ Exiv2::kerUnsupportedDataAreaOffsetType,
{ Exiv2::ErrorCode::kerUnsupportedDataAreaOffsetType,
N_("Unsupported data area offset type") },
{ Exiv2::kerInvalidCharset,
{ Exiv2::ErrorCode::kerInvalidCharset,
N_("Invalid charset: `%1'") }, // %1=charset name
{ Exiv2::kerUnsupportedDateFormat,
{ Exiv2::ErrorCode::kerUnsupportedDateFormat,
N_("Unsupported date format") },
{ Exiv2::kerUnsupportedTimeFormat,
{ Exiv2::ErrorCode::kerUnsupportedTimeFormat,
N_("Unsupported time format") },
{ Exiv2::kerWritingImageFormatUnsupported,
{ Exiv2::ErrorCode::kerWritingImageFormatUnsupported,
N_("Writing to %1 images is not supported") }, // %1=image format
{ Exiv2::kerInvalidSettingForImage,
{ Exiv2::ErrorCode::kerInvalidSettingForImage,
N_("Setting %1 in %2 images is not supported") }, // %1=metadata type, %2=image format
{ Exiv2::kerNotACrwImage,
{ Exiv2::ErrorCode::kerNotACrwImage,
N_("This does not look like a CRW image") },
{ Exiv2::kerFunctionNotSupported,
{ Exiv2::ErrorCode::kerFunctionNotSupported,
N_("%1: Not supported") }, // %1=function
{ Exiv2::kerNoNamespaceInfoForXmpPrefix,
{ Exiv2::ErrorCode::kerNoNamespaceInfoForXmpPrefix,
N_("No namespace info available for XMP prefix `%1'") }, // %1=prefix
{ Exiv2::kerNoPrefixForNamespace,
{ Exiv2::ErrorCode::kerNoPrefixForNamespace,
N_("No prefix registered for namespace `%2', needed for property path `%1'") }, // %1=namespace
{ Exiv2::kerTooLargeJpegSegment,
{ Exiv2::ErrorCode::kerTooLargeJpegSegment,
N_("Size of %1 JPEG segment is larger than 65535 bytes") }, // %1=type of metadata (Exif, IPTC, JPEG comment)
{ Exiv2::kerUnhandledXmpdatum,
{ Exiv2::ErrorCode::kerUnhandledXmpdatum,
N_("Unhandled Xmpdatum %1 of type %2") }, // %1=key, %2=value type
{ Exiv2::kerUnhandledXmpNode,
{ Exiv2::ErrorCode::kerUnhandledXmpNode,
N_("Unhandled XMP node %1 with opt=%2") }, // %1=key, %2=XMP Toolkit option flags
{ Exiv2::kerXMPToolkitError,
{ Exiv2::ErrorCode::kerXMPToolkitError,
N_("XMP Toolkit error %1: %2") }, // %1=XMP_Error::GetID(), %2=XMP_Error::GetErrMsg()
{ Exiv2::kerDecodeLangAltPropertyFailed,
{ Exiv2::ErrorCode::kerDecodeLangAltPropertyFailed,
N_("Failed to decode Lang Alt property %1 with opt=%2") }, // %1=property path, %3=XMP Toolkit option flags
{ Exiv2::kerDecodeLangAltQualifierFailed,
{ Exiv2::ErrorCode::kerDecodeLangAltQualifierFailed,
N_("Failed to decode Lang Alt qualifier %1 with opt=%2") }, // %1=qualifier path, %3=XMP Toolkit option flags
{ Exiv2::kerEncodeLangAltPropertyFailed,
{ Exiv2::ErrorCode::kerEncodeLangAltPropertyFailed,
N_("Failed to encode Lang Alt property %1") }, // %1=key
{ Exiv2::kerPropertyNameIdentificationFailed,
{ Exiv2::ErrorCode::kerPropertyNameIdentificationFailed,
N_("Failed to determine property name from path %1, namespace %2") }, // %1=property path, %2=namespace
{ Exiv2::kerSchemaNamespaceNotRegistered,
{ Exiv2::ErrorCode::kerSchemaNamespaceNotRegistered,
N_("Schema namespace %1 is not registered with the XMP Toolkit") }, // %1=namespace
{ Exiv2::kerNoNamespaceForPrefix,
{ Exiv2::ErrorCode::kerNoNamespaceForPrefix,
N_("No namespace registered for prefix `%1'") }, // %1=prefix
{ Exiv2::kerAliasesNotSupported,
{ Exiv2::ErrorCode::kerAliasesNotSupported,
N_("Aliases are not supported. Please send this XMP packet to ahuggel@gmx.net `%1', `%2', `%3'") }, // %1=namespace, %2=property path, %3=value
{ Exiv2::kerInvalidXmpText,
{ Exiv2::ErrorCode::kerInvalidXmpText,
N_("Invalid XmpText type `%1'") }, // %1=type
{ Exiv2::kerTooManyTiffDirectoryEntries,
{ Exiv2::ErrorCode::kerTooManyTiffDirectoryEntries,
N_("TIFF directory %1 has too many entries") }, // %1=TIFF directory name
{ Exiv2::kerMultipleTiffArrayElementTagsInDirectory,
{ Exiv2::ErrorCode::kerMultipleTiffArrayElementTagsInDirectory,
N_("Multiple TIFF array element tags %1 in one directory") }, // %1=tag number
{ Exiv2::kerWrongTiffArrayElementTagType,
{ Exiv2::ErrorCode::kerWrongTiffArrayElementTagType,
N_("TIFF array element tag %1 has wrong type") }, // %1=tag number
{ Exiv2::kerInvalidKeyXmpValue,
{ Exiv2::ErrorCode::kerInvalidKeyXmpValue,
N_("%1 has invalid XMP value type `%2'") }, // %1=key, %2=value type
{ Exiv2::kerInvalidIccProfile,
{ Exiv2::ErrorCode::kerInvalidIccProfile,
N_("Not a valid ICC Profile") },
{ Exiv2::kerTiffDirectoryTooLarge,
{ Exiv2::ErrorCode::kerTiffDirectoryTooLarge,
N_("tiff directory length is too large") },
{ Exiv2::kerInvalidTypeValue,
{ Exiv2::ErrorCode::kerInvalidTypeValue,
N_("invalid type in tiff structure") },
{ Exiv2::kerInvalidLangAltValue,
{ Exiv2::ErrorCode::kerInvalidLangAltValue,
N_("Invalid LangAlt value `%1'") }, // %1=value
{ Exiv2::kerInvalidMalloc,
{ Exiv2::ErrorCode::kerInvalidMalloc,
N_("invalid memory allocation request") },
{ Exiv2::kerCorruptedMetadata,
{ Exiv2::ErrorCode::kerCorruptedMetadata,
N_("corrupted image metadata") },
{ Exiv2::kerArithmeticOverflow,
{ Exiv2::ErrorCode::kerArithmeticOverflow,
N_("Arithmetic operation overflow") },
{ Exiv2::kerMallocFailed,
{ Exiv2::ErrorCode::kerMallocFailed,
N_("Memory allocation failed")}
};
@ -196,7 +196,7 @@ namespace Exiv2 {
std::string::size_type pos;
pos = msg.find("%0");
if (pos != std::string::npos) {
msg.replace(pos, 2, toString(code_));
msg.replace(pos, 2, toString(static_cast<int>(code_)));
}
if (count_ > 0) {
pos = msg.find("%1");
@ -222,7 +222,7 @@ namespace Exiv2 {
template class EXIV2API BasicError<char>;
#endif
const char* errMsg(int code)
const char* errMsg(ErrorCode code)
{
const ErrMsg* em = find(errList, code);
return em ? em->message_ : "";

@ -205,7 +205,7 @@ namespace Exiv2 {
const Value& Exifdatum::value() const
{
if (!value_)
throw Error(kerValueNotSet);
throw Error(ErrorCode::kerValueNotSet);
return *value_;
}

@ -243,7 +243,7 @@ namespace Exiv2 {
char buf[n];
std::memset(buf, 0x0, n);
const int ret = strerror_r(error, buf, n);
enforce(ret != ERANGE, Exiv2::kerCallFailed);
enforce(ret != ERANGE, Exiv2::ErrorCode::kerCallFailed);
#endif
os << buf;
// Issue# 908.

@ -26,19 +26,19 @@ namespace Exiv2 {
void GifImage::setExifData(const ExifData& /*exifData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "Exif metadata", "GIF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Exif metadata", "GIF"));
}
void GifImage::setIptcData(const IptcData& /*iptcData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "IPTC metadata", "GIF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "IPTC metadata", "GIF"));
}
void GifImage::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "GIF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "GIF"));
}
void GifImage::readMetadata()
@ -48,14 +48,14 @@ namespace Exiv2 {
#endif
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isGifType(*io_, true))
{
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "GIF");
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "GIF");
}
clearMetadata();
@ -70,7 +70,7 @@ namespace Exiv2 {
void GifImage::writeMetadata()
{
// Todo: implement me!
throw(Error(kerWritingImageFormatUnsupported, "GIF"));
throw(Error(ErrorCode::kerWritingImageFormatUnsupported, "GIF"));
} // GifImage::writeMetadata
// *************************************************************************

@ -132,7 +132,7 @@ namespace Exiv2 {
void Image::printStructure(std::ostream&, PrintStructureOption,int /*depth*/)
{
throw Error(kerUnsupportedImageType, io_->path());
throw Error(ErrorCode::kerUnsupportedImageType, io_->path());
}
bool Image::isStringType(uint16_t type)
@ -306,14 +306,14 @@ namespace Exiv2 {
do {
// Read top of directory
io.seekOrThrow(start, BasicIo::beg, kerCorruptedMetadata);
io.readOrThrow(dir.data(), 2, kerCorruptedMetadata);
io.seekOrThrow(start, BasicIo::beg, ErrorCode::kerCorruptedMetadata);
io.readOrThrow(dir.data(), 2, ErrorCode::kerCorruptedMetadata);
uint16_t dirLength = byteSwap2(dir,0,bSwap);
// Prevent infinite loops. (GHSA-m479-7frc-gqqg)
enforce(dirLength > 0, kerCorruptedMetadata);
enforce(dirLength > 0, ErrorCode::kerCorruptedMetadata);
if ( dirLength > 500 ) // tooBig
throw Error(kerTiffDirectoryTooLarge);
throw Error(ErrorCode::kerTiffDirectoryTooLarge);
if ( bFirst && bPrint ) {
out << Internal::indent(depth) << Internal::stringFormat("STRUCTURE OF TIFF FILE (%c%c): ",c,c) << io.path() << std::endl;
@ -322,7 +322,7 @@ namespace Exiv2 {
// Read the dictionary
for ( int i = 0 ; i < dirLength ; i ++ ) {
if ( visits.find(io.tell()) != visits.end() ) { // #547
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
visits.insert(io.tell());
@ -333,7 +333,7 @@ namespace Exiv2 {
}
bFirst = false;
io.readOrThrow(dir.data(), 12, kerCorruptedMetadata);
io.readOrThrow(dir.data(), 12, ErrorCode::kerCorruptedMetadata);
uint16_t tag = byteSwap2(dir,0,bSwap);
uint16_t type = byteSwap2(dir,2,bSwap);
uint32_t count = byteSwap4(dir,4,bSwap);
@ -342,7 +342,7 @@ namespace Exiv2 {
// Break for unknown tag types else we may segfault.
if ( !typeValid(type) ) {
EXV_ERROR << "invalid type in tiff structure" << type << std::endl;
throw Error(kerInvalidTypeValue);
throw Error(ErrorCode::kerInvalidTypeValue);
}
std::string sp; // output spacer
@ -367,11 +367,11 @@ namespace Exiv2 {
// #55 and #56 memory allocation crash test/data/POC8
const uint64_t allocate64 = static_cast<uint64_t>(size) * count + pad + 20;
if ( allocate64 > io.size() ) {
throw Error(kerInvalidMalloc);
throw Error(ErrorCode::kerInvalidMalloc);
}
// Overflow check
enforce(allocate64 <= static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()), kerCorruptedMetadata);
enforce(allocate64 <= static_cast<uint64_t>(std::numeric_limits<long>::max()), kerCorruptedMetadata);
enforce(allocate64 <= static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()), ErrorCode::kerCorruptedMetadata);
enforce(allocate64 <= static_cast<uint64_t>(std::numeric_limits<long>::max()), ErrorCode::kerCorruptedMetadata);
const auto allocate = static_cast<long>(allocate64);
DataBuf buf(allocate); // allocate a buffer
buf.copyBytes(0, dir.c_data(8), 4); // copy dir[8:11] into buffer (short strings)
@ -382,9 +382,9 @@ namespace Exiv2 {
if ( bOffsetIsPointer ) { // read into buffer
const long restore = io.tell(); // save
io.seekOrThrow(offset, BasicIo::beg, kerCorruptedMetadata); // position
io.readOrThrow(buf.data(), count_x_size, kerCorruptedMetadata); // read
io.seekOrThrow(restore, BasicIo::beg, kerCorruptedMetadata); // restore
io.seekOrThrow(offset, BasicIo::beg, ErrorCode::kerCorruptedMetadata); // position
io.readOrThrow(buf.data(), count_x_size, ErrorCode::kerCorruptedMetadata); // read
io.seekOrThrow(restore, BasicIo::beg, ErrorCode::kerCorruptedMetadata); // restore
}
if ( bPrint ) {
@ -426,20 +426,20 @@ namespace Exiv2 {
const long restore = io.tell();
offset = byteSwap4(buf,k*size,bSwap);
printIFDStructure(io,out,option,offset,bSwap,c,depth);
io.seekOrThrow(restore, BasicIo::beg, kerCorruptedMetadata);
io.seekOrThrow(restore, BasicIo::beg, ErrorCode::kerCorruptedMetadata);
}
} else if ( option == kpsRecursive && tag == 0x83bb /* IPTCNAA */ ) {
if (count > 0) {
if (static_cast<size_t>(Safe::add(count, offset)) > io.size()) {
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
const long restore = io.tell();
io.seekOrThrow(offset, BasicIo::beg, kerCorruptedMetadata); // position
io.seekOrThrow(offset, BasicIo::beg, ErrorCode::kerCorruptedMetadata); // position
std::vector<byte> bytes(count) ; // allocate memory
// TODO: once we have C++11 use bytes.data()
io.readOrThrow(&bytes[0], count, kerCorruptedMetadata);
io.seekOrThrow(restore, BasicIo::beg, kerCorruptedMetadata);
io.readOrThrow(&bytes[0], count, ErrorCode::kerCorruptedMetadata);
io.seekOrThrow(restore, BasicIo::beg, ErrorCode::kerCorruptedMetadata);
// TODO: once we have C++11 use bytes.data()
IptcData::printStructure(out, makeSliceUntil(&bytes[0], count), depth);
}
@ -449,8 +449,8 @@ namespace Exiv2 {
uint32_t jump= 10 ;
byte bytes[20] ;
const auto chars = reinterpret_cast<const char*>(&bytes[0]);
io.seekOrThrow(offset, BasicIo::beg, kerCorruptedMetadata); // position
io.readOrThrow(bytes, jump, kerCorruptedMetadata) ; // read
io.seekOrThrow(offset, BasicIo::beg, ErrorCode::kerCorruptedMetadata); // position
io.readOrThrow(bytes, jump, ErrorCode::kerCorruptedMetadata) ; // read
bytes[jump]=0 ;
bool bNikon = ::strcmp("Nikon" ,chars) == 0;
@ -460,17 +460,17 @@ namespace Exiv2 {
// tag is an embedded tiff
const long byteslen = count-jump;
DataBuf bytes(byteslen); // allocate a buffer
io.readOrThrow(bytes.data(), byteslen, kerCorruptedMetadata); // read
io.readOrThrow(bytes.data(), byteslen, ErrorCode::kerCorruptedMetadata); // read
MemIo memIo(bytes.c_data(), byteslen) ; // create a file
printTiffStructure(memIo,out,option,depth);
} else {
// tag is an IFD
uint32_t punt = bSony ? 12 : 0 ;
io.seekOrThrow(0, BasicIo::beg, kerCorruptedMetadata); // position
io.seekOrThrow(0, BasicIo::beg, ErrorCode::kerCorruptedMetadata); // position
printIFDStructure(io,out,option,offset+punt,bSwap,c,depth);
}
io.seekOrThrow(restore, BasicIo::beg, kerCorruptedMetadata); // restore
io.seekOrThrow(restore, BasicIo::beg, ErrorCode::kerCorruptedMetadata); // restore
}
}
@ -483,7 +483,7 @@ namespace Exiv2 {
}
}
if ( start ) {
io.readOrThrow(dir.data(), 4, kerCorruptedMetadata);
io.readOrThrow(dir.data(), 4, ErrorCode::kerCorruptedMetadata);
start = byteSwap4(dir,0,bSwap);
}
} while (start) ;
@ -502,7 +502,7 @@ namespace Exiv2 {
DataBuf dir(dirSize);
// read header (we already know for certain that we have a Tiff file)
io.readOrThrow(dir.data(), 8, kerCorruptedMetadata);
io.readOrThrow(dir.data(), 8, ErrorCode::kerCorruptedMetadata);
auto c = static_cast<char>(dir.read_uint8(0));
bool bSwap = ( c == 'M' && isLittleEndianPlatform() )
|| ( c == 'I' && isBigEndianPlatform() )
@ -598,7 +598,7 @@ namespace Exiv2 {
void Image::setXmpPacket(const std::string& xmpPacket)
{
if ( XmpParser::decode(xmpData_, xmpPacket) ) {
throw Error(kerInvalidXMP);
throw Error(ErrorCode::kerInvalidXMP);
}
xmpPacket_ = xmpPacket;
}
@ -638,11 +638,11 @@ namespace Exiv2 {
{
if ( bTestValid ) {
if (iccProfile.size() < static_cast<long>(sizeof(long))) {
throw Error(kerInvalidIccProfile);
throw Error(ErrorCode::kerInvalidIccProfile);
}
const size_t size = iccProfile.read_uint32(0, bigEndian);
if (size != iccProfile.size()) {
throw Error(kerInvalidIccProfile);
throw Error(ErrorCode::kerInvalidIccProfile);
}
}
iccProfile_ = std::move(iccProfile);
@ -755,7 +755,7 @@ namespace Exiv2 {
{
const Registry* r = find(registry, type);
if (!r)
throw Error(kerUnsupportedImageType, static_cast<int>(type));
throw Error(ErrorCode::kerUnsupportedImageType, static_cast<int>(type));
AccessMode am = amNone;
switch (metadataId) {
case mdNone:
@ -839,7 +839,7 @@ namespace Exiv2 {
{
auto image = open(ImageFactory::createIo(path, useCurl)); // may throw
if (!image)
throw Error(kerFileContainsUnknownImageType, path);
throw Error(ErrorCode::kerFileContainsUnknownImageType, path);
return image;
}
@ -848,14 +848,14 @@ namespace Exiv2 {
auto io = std::make_unique<MemIo>(data, size);
auto image = open(std::move(io)); // may throw
if (!image)
throw Error(kerMemoryContainsUnknownImageType);
throw Error(ErrorCode::kerMemoryContainsUnknownImageType);
return image;
}
Image::UniquePtr ImageFactory::open(BasicIo::UniquePtr io)
{
if (io->open() != 0) {
throw Error(kerDataSourceOpenFailed, io->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io->path(), strError());
}
for (unsigned int i = 0; registry[i].imageType_ != ImageType::none; ++i) {
if (registry[i].isThisType_(*io, false)) {
@ -870,14 +870,14 @@ namespace Exiv2 {
auto fileIo = std::make_unique<FileIo>(path);
// Create or overwrite the file, then close it
if (fileIo->open("w+b") != 0) {
throw Error(kerFileOpenFailed, path, "w+b", strError());
throw Error(ErrorCode::kerFileOpenFailed, path, "w+b", strError());
}
fileIo->close();
BasicIo::UniquePtr io(std::move(fileIo));
auto image = create(type, std::move(io));
if (!image)
throw Error(kerUnsupportedImageType, static_cast<int>(type));
throw Error(ErrorCode::kerUnsupportedImageType, static_cast<int>(type));
return image;
}
@ -886,7 +886,7 @@ namespace Exiv2 {
auto io = std::make_unique<MemIo>();
auto image = create(type, std::move(io));
if (!image)
throw Error(kerUnsupportedImageType, static_cast<int>(type));
throw Error(ErrorCode::kerUnsupportedImageType, static_cast<int>(type));
return image;
}

@ -131,7 +131,7 @@ namespace Exiv2 {
const Value& Iptcdatum::value() const
{
if (!value_)
throw Error(kerValueNotSet);
throw Error(ErrorCode::kerValueNotSet);
return *value_;
}
@ -287,12 +287,12 @@ namespace Exiv2 {
char buff[100];
uint16_t record = bytes.at(i + 1);
uint16_t dataset = bytes.at(i + 2);
enforce(bytes.size() - i >= 5, kerCorruptedMetadata);
enforce(bytes.size() - i >= 5, ErrorCode::kerCorruptedMetadata);
uint16_t len = getUShort(bytes.subSlice(i + 3, bytes.size()), bigEndian);
snprintf(buff, sizeof(buff), " %6d | %7d | %-24s | %6d | ", record, dataset,
Exiv2::IptcDataSets::dataSetName(dataset, record).c_str(), len);
enforce(bytes.size() - i >= 5 + static_cast<size_t>(len), kerCorruptedMetadata);
enforce(bytes.size() - i >= 5 + static_cast<size_t>(len), ErrorCode::kerCorruptedMetadata);
out << buff << Internal::binaryToString(makeSlice(bytes, i + 5, i + 5 + (len > 40 ? 40 : len)))
<< (len > 40 ? "..." : "")
<< std::endl;

@ -137,7 +137,7 @@ namespace Exiv2
void Jp2Image::setComment(std::string_view /*comment*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "Image comment", "JP2"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "JP2"));
}
static void lf(std::ostream& out,bool& bLF)
@ -176,7 +176,7 @@ static void boxes_check(size_t b,size_t m)
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata box maximum exceeded" << std::endl;
#endif
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
}
@ -187,14 +187,14 @@ static void boxes_check(size_t b,size_t m)
#endif
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isJp2Type(*io_, true))
{
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "JPEG-2000");
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "JPEG-2000");
}
Jp2BoxHeader box = {0,0};
@ -216,7 +216,7 @@ static void boxes_check(size_t b,size_t m)
<< " length: " << box.length
<< std::endl;
#endif
enforce(box.length <= sizeof(box)+io_->size()-io_->tell() , Exiv2::kerCorruptedMetadata);
enforce(box.length <= sizeof(box)+io_->size()-io_->tell() , Exiv2::ErrorCode::kerCorruptedMetadata);
if (box.length == 0) return ;
@ -240,7 +240,7 @@ static void boxes_check(size_t b,size_t m)
subBox.length = getLong(reinterpret_cast<byte*>(&subBox.length), bigEndian);
subBox.type = getLong(reinterpret_cast<byte*>(&subBox.type), bigEndian);
if (subBox.length > io_->size() ) {
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: "
@ -257,7 +257,7 @@ static void boxes_check(size_t b,size_t m)
const size_t data_length = Safe::add(subBox.length, static_cast<uint32_t>(8));
// data_length makes no sense if it is larger than the rest of the file
if (data_length > io_->size() - io_->tell()) {
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
DataBuf data(data_length);
io_->read(data.data(), data.size());
@ -265,7 +265,7 @@ static void boxes_check(size_t b,size_t m)
// subtracting pad from data.size() is safe:
// data.size() is at least 8 and pad = 3
if (iccLength > data.size() - pad) {
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
DataBuf icc(iccLength);
icc.copyBytes(0, data.c_data(pad), icc.size());
@ -299,7 +299,7 @@ static void boxes_check(size_t b,size_t m)
io_->seek(restore,BasicIo::beg);
if ( io_->seek(subBox.length, Exiv2::BasicIo::cur) != 0 ) {
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
restore = io_->tell();
}
@ -324,11 +324,11 @@ static void boxes_check(size_t b,size_t m)
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: Exif data found" << std::endl ;
#endif
enforce(box.length >= sizeof(box) + sizeof(uuid), kerCorruptedMetadata);
enforce(box.length >= sizeof(box) + sizeof(uuid), ErrorCode::kerCorruptedMetadata);
rawData.alloc(box.length - (sizeof(box) + sizeof(uuid)));
bufRead = io_->read(rawData.data(), rawData.size());
if (io_->error()) throw Error(kerFailedToReadImageData);
if (bufRead != rawData.size()) throw Error(kerInputDataReadFailed);
if (io_->error()) throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != rawData.size()) throw Error(ErrorCode::kerInputDataReadFailed);
if (rawData.size() > 8) // "II*\0long"
{
@ -378,11 +378,11 @@ static void boxes_check(size_t b,size_t m)
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: Iptc data found" << std::endl;
#endif
enforce(box.length >= sizeof(box) + sizeof(uuid), kerCorruptedMetadata);
enforce(box.length >= sizeof(box) + sizeof(uuid), ErrorCode::kerCorruptedMetadata);
rawData.alloc(box.length - (sizeof(box) + sizeof(uuid)));
bufRead = io_->read(rawData.data(), rawData.size());
if (io_->error()) throw Error(kerFailedToReadImageData);
if (bufRead != rawData.size()) throw Error(kerInputDataReadFailed);
if (io_->error()) throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != rawData.size()) throw Error(ErrorCode::kerInputDataReadFailed);
if (IptcParser::decode(iptcData_, rawData.c_data(), static_cast<uint32_t>(rawData.size())))
{
@ -398,13 +398,13 @@ static void boxes_check(size_t b,size_t m)
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: Xmp data found" << std::endl;
#endif
enforce(box.length >= sizeof(box) + sizeof(uuid), kerCorruptedMetadata);
enforce(box.length >= sizeof(box) + sizeof(uuid), ErrorCode::kerCorruptedMetadata);
rawData.alloc(box.length - static_cast<uint32_t>(sizeof(box) + sizeof(uuid)));
bufRead = io_->read(rawData.data(), rawData.size());
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != rawData.size())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
xmpPacket_.assign(rawData.c_str(), rawData.size());
std::string::size_type idx = xmpPacket_.find_first_of('<');
@ -434,7 +434,7 @@ static void boxes_check(size_t b,size_t m)
// Move to the next box.
io_->seek(static_cast<long>(position - sizeof(box) + box.length), BasicIo::beg);
if (io_->error()) throw Error(kerFailedToReadImageData);
if (io_->error()) throw Error(ErrorCode::kerFailedToReadImageData);
}
} // Jp2Image::readMetadata
@ -442,13 +442,13 @@ static void boxes_check(size_t b,size_t m)
void Jp2Image::printStructure(std::ostream& out, PrintStructureOption option, int depth)
{
if (io_->open() != 0)
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
// Ensure that this is the correct image type
if (!isJp2Type(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAJpeg);
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
bool bPrint = option == kpsBasic || option == kpsRecursive;
@ -474,7 +474,7 @@ static void boxes_check(size_t b,size_t m)
long position = io_->tell();
box.length = getLong(reinterpret_cast<byte*>(&box.length), bigEndian);
box.type = getLong(reinterpret_cast<byte*>(&box.type), bigEndian);
enforce(box.length <= sizeof(box)+io_->size()-io_->tell() , Exiv2::kerCorruptedMetadata);
enforce(box.length <= sizeof(box)+io_->size()-io_->tell() , Exiv2::ErrorCode::kerCorruptedMetadata);
if (bPrint) {
out << Internal::stringFormat("%8ld | %8ld | ", position - sizeof(box),
@ -499,7 +499,7 @@ static void boxes_check(size_t b,size_t m)
subBox.type = getLong(reinterpret_cast<byte*>(&subBox.type), bigEndian);
if (subBox.length < sizeof(box) || subBox.length > io_->size() - io_->tell()) {
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
DataBuf data(subBox.length - sizeof(box));
@ -515,7 +515,7 @@ static void boxes_check(size_t b,size_t m)
const size_t pad = 3; // don't know why there are 3 padding bytes
// Bounds-check for the `getULong()` below, which reads 4 bytes, starting at `pad`.
enforce(data.size() >= pad + 4, kerCorruptedMetadata);
enforce(data.size() >= pad + 4, ErrorCode::kerCorruptedMetadata);
if (bPrint) {
out << " | pad:";
@ -527,7 +527,7 @@ static void boxes_check(size_t b,size_t m)
if (bPrint) {
out << " | iccLength:" << iccLength;
}
enforce(iccLength <= data.size() - pad, kerCorruptedMetadata);
enforce(iccLength <= data.size() - pad, ErrorCode::kerCorruptedMetadata);
if (bICC) {
out.write(data.c_str(pad), iccLength);
}
@ -556,13 +556,13 @@ static void boxes_check(size_t b,size_t m)
}
DataBuf rawData;
enforce(box.length >= sizeof(uuid) + sizeof(box), kerCorruptedMetadata);
enforce(box.length >= sizeof(uuid) + sizeof(box), ErrorCode::kerCorruptedMetadata);
rawData.alloc(box.length - sizeof(uuid) - sizeof(box));
const size_t bufRead = io_->read(rawData.data(), rawData.size());
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != rawData.size())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
if (bPrint) {
out << Internal::binaryToString(
@ -597,7 +597,7 @@ static void boxes_check(size_t b,size_t m)
// Move to the next box.
io_->seek(static_cast<long>(position - sizeof(box) + box.length), BasicIo::beg);
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bPrint)
lf(out, bLF);
}
@ -608,7 +608,7 @@ static void boxes_check(size_t b,size_t m)
{
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
auto tempIo = std::make_unique<MemIo>();
@ -630,16 +630,16 @@ static void boxes_check(size_t b,size_t m)
DataBuf output(boxBuf.size() + iccProfile_.size() + 100); // allocate sufficient space
long outlen = sizeof(Jp2BoxHeader) ; // now many bytes have we written to output?
long inlen = sizeof(Jp2BoxHeader) ; // how many bytes have we read from boxBuf?
enforce(sizeof(Jp2BoxHeader) <= output.size(), Exiv2::kerCorruptedMetadata);
enforce(sizeof(Jp2BoxHeader) <= output.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
auto pBox = reinterpret_cast<const Jp2BoxHeader*>(boxBuf.c_data());
uint32_t length = getLong(reinterpret_cast<const byte*>(&pBox->length), bigEndian);
enforce(length <= output.size(), Exiv2::kerCorruptedMetadata);
enforce(length <= output.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
uint32_t count = sizeof (Jp2BoxHeader);
auto p = boxBuf.c_str();
bool bWroteColor = false ;
while ( count < length && !bWroteColor ) {
enforce(sizeof(Jp2BoxHeader) <= length - count, Exiv2::kerCorruptedMetadata);
enforce(sizeof(Jp2BoxHeader) <= length - count, Exiv2::ErrorCode::kerCorruptedMetadata);
auto pSubBox = reinterpret_cast<const Jp2BoxHeader*>(p + count);
// copy data. pointer could be into a memory mapped file which we will decode!
@ -652,8 +652,8 @@ static void boxes_check(size_t b,size_t m)
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Jp2Image::encodeJp2Header subbox: "<< toAscii(subBox.type) << " length = " << subBox.length << std::endl;
#endif
enforce(subBox.length > 0, Exiv2::kerCorruptedMetadata);
enforce(subBox.length <= length - count, Exiv2::kerCorruptedMetadata);
enforce(subBox.length > 0, Exiv2::ErrorCode::kerCorruptedMetadata);
enforce(subBox.length <= length - count, Exiv2::ErrorCode::kerCorruptedMetadata);
count += subBox.length;
newBox.type = subBox.type;
} else {
@ -669,7 +669,7 @@ static void boxes_check(size_t b,size_t m)
const char* pad = "\x01\x00\x00\x00\x00\x00\x10\x00\x00\x05\x1cuuid";
uint32_t psize = 15;
newlen = sizeof(newBox) + psize ;
enforce(newlen <= output.size() - outlen, Exiv2::kerCorruptedMetadata);
enforce(newlen <= output.size() - outlen, Exiv2::ErrorCode::kerCorruptedMetadata);
ul2Data(reinterpret_cast<byte*>(&newBox.length), psize, bigEndian);
ul2Data(reinterpret_cast<byte*>(&newBox.type), newBox.type, bigEndian);
output.copyBytes(outlen ,&newBox ,sizeof(newBox));
@ -678,7 +678,7 @@ static void boxes_check(size_t b,size_t m)
const char* pad = "\x02\x00\x00";
uint32_t psize = 3;
newlen = sizeof(newBox) + psize + static_cast<uint32_t>(iccProfile_.size());
enforce(newlen <= static_cast<size_t>(output.size() - outlen), Exiv2::kerCorruptedMetadata);
enforce(newlen <= static_cast<size_t>(output.size() - outlen), Exiv2::ErrorCode::kerCorruptedMetadata);
ul2Data(reinterpret_cast<byte*>(&newBox.length), newlen, bigEndian);
ul2Data(reinterpret_cast<byte*>(&newBox.type), newBox.type, bigEndian);
output.copyBytes(outlen ,&newBox ,sizeof(newBox) );
@ -686,7 +686,7 @@ static void boxes_check(size_t b,size_t m)
output.copyBytes(outlen+sizeof(newBox)+psize,iccProfile_.c_data(),iccProfile_.size());
}
} else {
enforce(newlen <= static_cast<size_t>(output.size() - outlen), Exiv2::kerCorruptedMetadata);
enforce(newlen <= static_cast<size_t>(output.size() - outlen), Exiv2::ErrorCode::kerCorruptedMetadata);
output.copyBytes(outlen,boxBuf.c_data(inlen),subBox.length);
}
@ -708,8 +708,8 @@ static void boxes_check(size_t b,size_t m)
void Jp2Image::doWriteMetadata(BasicIo& outIo)
{
if (!io_->isopen()) throw Error(kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(kerImageWriteFailed);
if (!io_->isopen()) throw Error(ErrorCode::kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(ErrorCode::kerImageWriteFailed);
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Writing JPEG-2000 file " << io_->path() << std::endl;
@ -719,12 +719,12 @@ static void boxes_check(size_t b,size_t m)
// Ensure that this is the correct image type
if (!isJp2Type(*io_, true))
{
if (io_->error() || io_->eof()) throw Error(kerInputDataReadFailed);
throw Error(kerNoImageInInputData);
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerInputDataReadFailed);
throw Error(ErrorCode::kerNoImageInInputData);
}
// Write JPEG2000 Signature.
if (outIo.write(Jp2Signature, 12) != 12) throw Error(kerImageWriteFailed);
if (outIo.write(Jp2Signature, 12) != 12) throw Error(ErrorCode::kerImageWriteFailed);
Jp2BoxHeader box = {0,0};
@ -743,9 +743,9 @@ static void boxes_check(size_t b,size_t m)
// Read chunk header.
size_t bufRead = io_->read(bheaderBuf.data(), bheaderBuf.size());
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != bheaderBuf.size())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
// Decode box header.
@ -768,11 +768,11 @@ static void boxes_check(size_t b,size_t m)
if (box.length < 8)
{
// box is broken, so there is nothing we can do here
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
// Prevent a malicious file from causing a large memory allocation.
enforce(box.length - 8 <= static_cast<size_t>(io_->size() - io_->tell()), kerCorruptedMetadata);
enforce(box.length - 8 <= static_cast<size_t>(io_->size() - io_->tell()), ErrorCode::kerCorruptedMetadata);
// Read whole box : Box header + Box data (not fixed size - can be null).
DataBuf boxBuf(box.length); // Box header (8 bytes) + box data.
@ -784,14 +784,14 @@ static void boxes_check(size_t b,size_t m)
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Error reading source file" << std::endl;
#endif
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
if (bufRead != (box.length - 8)) {
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Cannot read source file data" << std::endl;
#endif
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
}
switch(box.type)
@ -804,7 +804,7 @@ static void boxes_check(size_t b,size_t m)
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Write JP2Header box (length: " << box.length << ")" << std::endl;
#endif
if (outIo.write(newBuf.data(), newBuf.size()) != newBuf.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write all updated metadata here, just after JP2Header.
@ -831,7 +831,7 @@ static void boxes_check(size_t b,size_t m)
<< boxData.size() << std::endl;
#endif
if (outIo.write(boxData.c_data(), boxData.size()) != boxData.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
}
@ -854,7 +854,7 @@ static void boxes_check(size_t b,size_t m)
<< boxData.size() << std::endl;
#endif
if (outIo.write(boxData.c_data(), boxData.size()) != boxData.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
}
@ -883,7 +883,7 @@ static void boxes_check(size_t b,size_t m)
<< boxData.size() << ")" << std::endl;
#endif
if (outIo.write(boxData.c_data(), boxData.size()) != boxData.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
break;
@ -891,7 +891,7 @@ static void boxes_check(size_t b,size_t m)
case kJp2BoxTypeUuid:
{
enforce(boxBuf.size() >= 24, Exiv2::kerCorruptedMetadata);
enforce(boxBuf.size() >= 24, Exiv2::ErrorCode::kerCorruptedMetadata);
if (boxBuf.cmpBytes(8, kJp2UuidExif, 16) == 0)
{
#ifdef EXIV2_DEBUG_MESSAGES
@ -916,7 +916,7 @@ static void boxes_check(size_t b,size_t m)
std::cout << "Exiv2::Jp2Image::doWriteMetadata: write Uuid box (length: " << box.length << ")" << std::endl;
#endif
if (outIo.write(boxBuf.c_data(), boxBuf.size()) != boxBuf.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
break;
}
@ -927,7 +927,7 @@ static void boxes_check(size_t b,size_t m)
std::cout << "Exiv2::Jp2Image::doWriteMetadata: write box (length: " << box.length << ")" << std::endl;
#endif
if (outIo.write(boxBuf.c_data(), boxBuf.size()) != boxBuf.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
break;
}

@ -287,12 +287,12 @@ namespace Exiv2 {
{
int rc = 0; // Todo: this should be the return value
if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError());
if (io_->open() != 0) throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isThisType(*io_, true)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAJpeg);
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
clearMetadata();
int search = 6 ; // Exif, ICC, XMP, Comment, IPTC, SOF
@ -303,23 +303,23 @@ namespace Exiv2 {
bool foundIccData = false;
// Read section marker
byte marker = advanceToMarker(kerNotAJpeg);
byte marker = advanceToMarker(ErrorCode::kerNotAJpeg);
while (marker != sos_ && marker != eoi_ && search > 0) {
// 2-byte buffer for reading the size.
byte sizebuf[2];
uint16_t size = 0; // Size of the segment, including the 2-byte size field
if (markerHasLength(marker)) {
io_->readOrThrow(sizebuf, 2, kerFailedToReadImageData);
io_->readOrThrow(sizebuf, 2, ErrorCode::kerFailedToReadImageData);
size = getUShort(sizebuf, bigEndian);
enforce(size >= 2, kerFailedToReadImageData);
enforce(size >= 2, ErrorCode::kerFailedToReadImageData);
}
// Read the rest of the segment.
DataBuf buf(size);
/// \todo check if it makes sense to check for size
if (size > 0) {
io_->readOrThrow(buf.data(2), size - 2, kerFailedToReadImageData);
io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData);
buf.copyBytes(0, sizebuf, 2);
}
@ -407,7 +407,7 @@ namespace Exiv2 {
// #1286 profile can be padded
size_t icc_size = size-2-14;
if (chunk==1 && chunks==1) {
enforce(s <= static_cast<uint32_t>(icc_size), kerInvalidIccProfile);
enforce(s <= static_cast<uint32_t>(icc_size), ErrorCode::kerInvalidIccProfile);
icc_size = s;
}
@ -431,7 +431,7 @@ namespace Exiv2 {
// Read the beginning of the next segment
try {
marker = advanceToMarker(kerFailedToReadImageData);
marker = advanceToMarker(ErrorCode::kerFailedToReadImageData);
} catch (Error&) {
rc = 5;
break;
@ -479,12 +479,12 @@ namespace Exiv2 {
void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, int depth)
{
if (io_->open() != 0)
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
// Ensure that this is the correct image type
if (!isThisType(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAJpeg);
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
bool bPrint = option == kpsBasic || option == kpsRecursive;
@ -517,7 +517,7 @@ namespace Exiv2 {
bool bExtXMP = false;
// Read section marker
byte marker = advanceToMarker(kerNotAJpeg);
byte marker = advanceToMarker(ErrorCode::kerNotAJpeg);
bool done = false;
bool first = true;
@ -535,18 +535,18 @@ namespace Exiv2 {
byte sizebuf[2];
uint16_t size = 0;
if (markerHasLength(marker)) {
io_->readOrThrow(sizebuf, 2, kerFailedToReadImageData);
io_->readOrThrow(sizebuf, 2, ErrorCode::kerFailedToReadImageData);
size = getUShort(sizebuf, bigEndian);
// `size` is the size of the segment, including the 2-byte size field
// that we just read.
enforce(size >= 2, kerFailedToReadImageData);
enforce(size >= 2, ErrorCode::kerFailedToReadImageData);
}
// Read the rest of the segment.
DataBuf buf(size);
if (size > 0) {
assert(size >= 2); // enforced above
io_->readOrThrow(buf.data(2), size - 2, kerFailedToReadImageData);
io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData);
buf.copyBytes(0, sizebuf, 2);
}
@ -596,7 +596,7 @@ namespace Exiv2 {
start = 2 + 35 + 32 + 4 + 4; // Adobe Spec, p19
}
enforce(start <= size, kerInvalidXmpText);
enforce(start <= size, ErrorCode::kerInvalidXmpText);
out.write(reinterpret_cast<const char*>(&xmp[start]), size - start);
done = !bExtXMP;
} else if (option == kpsIccProfile && signature == iccId_) {
@ -709,7 +709,7 @@ namespace Exiv2 {
if (marker != sos_) {
// Read the beginning of the next segment
marker = advanceToMarker(kerNoImageInInputData);
marker = advanceToMarker(ErrorCode::kerNoImageInInputData);
REPORT_MARKER;
}
done |= marker == eoi_ || marker == sos_;
@ -764,16 +764,16 @@ namespace Exiv2 {
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << start << ":" << length << std::endl;
#endif
io_->seekOrThrow(start, BasicIo::beg, kerFailedToReadImageData);
io_->seekOrThrow(start, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
DataBuf buf(length);
io_->readOrThrow(buf.data(), buf.size(), kerFailedToReadImageData);
io_->readOrThrow(buf.data(), buf.size(), ErrorCode::kerFailedToReadImageData);
tempIo->write(buf.c_data(), buf.size());
}
}
io_->seekOrThrow(0, BasicIo::beg, kerFailedToReadImageData);
io_->seekOrThrow(0, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
io_->transfer(*tempIo); // may throw
io_->seekOrThrow(0, BasicIo::beg, kerFailedToReadImageData);
io_->seekOrThrow(0, BasicIo::beg, ErrorCode::kerFailedToReadImageData);
readMetadata();
}
} // JpegBase::printStructure
@ -781,7 +781,7 @@ namespace Exiv2 {
void JpegBase::writeMetadata()
{
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
auto tempIo = std::make_unique<MemIo>();
@ -797,18 +797,18 @@ namespace Exiv2 {
byte sizebuf[2];
uint16_t size = 0;
if (markerHasLength(marker)) {
io_->readOrThrow(sizebuf, 2, kerFailedToReadImageData);
io_->readOrThrow(sizebuf, 2, ErrorCode::kerFailedToReadImageData);
size = getUShort(sizebuf, bigEndian);
// `size` is the size of the segment, including the 2-byte size field
// that we just read.
enforce(size >= 2, kerFailedToReadImageData);
enforce(size >= 2, ErrorCode::kerFailedToReadImageData);
}
// Read the rest of the segment.
DataBuf buf(size);
if (size > 0) {
assert(size >= 2); // enforced above
io_->readOrThrow(buf.data(2), size - 2, kerFailedToReadImageData);
io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData);
buf.copyBytes(0, sizebuf, 2);
}
return buf;
@ -817,15 +817,15 @@ namespace Exiv2 {
void JpegBase::doWriteMetadata(BasicIo& outIo)
{
if (!io_->isopen())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
if (!outIo.isopen())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Ensure that this is the correct image type
if (!isThisType(*io_, true)) {
if (io_->error() || io_->eof())
throw Error(kerInputDataReadFailed);
throw Error(kerNoImageInInputData);
throw Error(ErrorCode::kerInputDataReadFailed);
throw Error(ErrorCode::kerNoImageInInputData);
}
// Used to initialize search variables such as skipCom.
@ -849,10 +849,10 @@ namespace Exiv2 {
// Write image header
if (writeHeader(outIo))
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Read section marker
byte marker = advanceToMarker(kerNoImageInInputData);
byte marker = advanceToMarker(ErrorCode::kerNoImageInInputData);
// First find segments of interest. Normally app0 is first and we want
// to insert after it. But if app0 comes after com, app1 and app13 then
@ -916,12 +916,12 @@ namespace Exiv2 {
comPos = count;
++search;
}
marker = advanceToMarker(kerNoImageInInputData);
marker = advanceToMarker(ErrorCode::kerNoImageInInputData);
++count;
}
if (!foundCompletePsData && !psBlob.empty())
throw Error(kerNoImageInInputData);
throw Error(ErrorCode::kerNoImageInInputData);
search += skipApp13Ps3.size() + skipApp2Icc.size();
if (comPos == 0) {
@ -942,9 +942,9 @@ namespace Exiv2 {
if (!comment_.empty())
++search;
io_->seekOrThrow(seek, BasicIo::beg, kerNoImageInInputData);
io_->seekOrThrow(seek, BasicIo::beg, ErrorCode::kerNoImageInInputData);
count = 0;
marker = advanceToMarker(kerNoImageInInputData);
marker = advanceToMarker(ErrorCode::kerNoImageInInputData);
// To simplify this a bit, new segments are inserts at either the start
// or right after app0. This is standard in most jpegs, but has the
@ -977,17 +977,17 @@ namespace Exiv2 {
tmpBuf[1] = app1_;
if (exifSize > 0xffff - 8)
throw Error(kerTooLargeJpegSegment, "Exif");
throw Error(ErrorCode::kerTooLargeJpegSegment, "Exif");
us2Data(tmpBuf.data() + 2, static_cast<uint16_t>(exifSize + 8), bigEndian);
std::memcpy(tmpBuf.data() + 4, exifId_, 6);
if (outIo.write(tmpBuf.data(), 10) != 10)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write new Exif data buffer
if (outIo.write(pExifData, exifSize) != exifSize)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
--search;
}
}
@ -1006,18 +1006,18 @@ namespace Exiv2 {
tmpBuf[1] = app1_;
if (xmpPacket_.size() > 0xffff - 31)
throw Error(kerTooLargeJpegSegment, "XMP");
throw Error(ErrorCode::kerTooLargeJpegSegment, "XMP");
us2Data(tmpBuf.data() + 2, static_cast<uint16_t>(xmpPacket_.size() + 31), bigEndian);
std::memcpy(tmpBuf.data() + 4, xmpId_, 29);
if (outIo.write(tmpBuf.data(), 33) != 33)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write new XMP packet
if (outIo.write(reinterpret_cast<const byte*>(xmpPacket_.data()),
xmpPacket_.size()) != xmpPacket_.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
--search;
}
@ -1032,7 +1032,7 @@ namespace Exiv2 {
size_t size = iccProfile_.size();
assert(size > 0); // Because iccProfileDefined() == true
if (size >= 255 * chunk_size)
throw Error(kerTooLargeJpegSegment, "IccProfile");
throw Error(ErrorCode::kerTooLargeJpegSegment, "IccProfile");
const size_t chunks = 1 + (size - 1) / chunk_size;
assert(chunks <= 255); // Because size < 255 * chunk_size
for (size_t chunk = 0; chunk < chunks; chunk++) {
@ -1041,11 +1041,11 @@ namespace Exiv2 {
// write JPEG marker (2 bytes)
if (outIo.write(tmpBuf.data(), 2) != 2)
throw Error(kerImageWriteFailed); // JPEG Marker
throw Error(ErrorCode::kerImageWriteFailed); // JPEG Marker
// write length (2 bytes). length includes the 2 bytes for the length
us2Data(tmpBuf.data() + 2, static_cast<uint16_t>(2 + 14 + bytes), bigEndian);
if (outIo.write(tmpBuf.data() + 2, 2) != 2)
throw Error(kerImageWriteFailed); // JPEG Length
throw Error(ErrorCode::kerImageWriteFailed); // JPEG Length
// write the ICC_PROFILE header (14 bytes)
uint8_t pad[2];
@ -1054,9 +1054,9 @@ namespace Exiv2 {
outIo.write(reinterpret_cast<const byte*>(iccId_), 12);
outIo.write(reinterpret_cast<const byte*>(pad), 2);
if (outIo.write(iccProfile_.c_data(chunk * chunk_size), bytes) != bytes)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
--search;
}
@ -1090,15 +1090,15 @@ namespace Exiv2 {
us2Data(tmpBuf.data() + 2, static_cast<uint16_t>(chunkSize + 16), bigEndian);
std::memcpy(tmpBuf.data() + 4, Photoshop::ps3Id_, 14);
if (outIo.write(tmpBuf.data(), 18) != 18)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write next chunk of the Photoshop IRB data buffer
if (outIo.write(chunkStart, chunkSize) != chunkSize)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
chunkStart += chunkSize;
}
@ -1113,18 +1113,18 @@ namespace Exiv2 {
tmpBuf[1] = com_;
if (comment_.length() > 0xffff - 3)
throw Error(kerTooLargeJpegSegment, "JPEG comment");
throw Error(ErrorCode::kerTooLargeJpegSegment, "JPEG comment");
us2Data(tmpBuf.data() + 2, static_cast<uint16_t>(comment_.length() + 3), bigEndian);
if (outIo.write(tmpBuf.data(), 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(reinterpret_cast<byte*>(const_cast<char*>(comment_.data())),
comment_.length()) != comment_.length())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.putb(0) == EOF)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
--search;
}
--search;
@ -1142,15 +1142,15 @@ namespace Exiv2 {
tmpBuf[0] = 0xff;
tmpBuf[1] = marker;
if (outIo.write(tmpBuf.data(), 2) != 2)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(buf.c_data(), buf.size()) != buf.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
// Next marker
marker = advanceToMarker(kerNoImageInInputData);
marker = advanceToMarker(ErrorCode::kerNoImageInInputData);
++count;
}
@ -1163,16 +1163,16 @@ namespace Exiv2 {
tmpBuf[0] = 0xff;
tmpBuf[1] = marker;
if (outIo.write(tmpBuf, 2) != 2)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
DataBuf buf(4096);
size_t readSize = 0;
while ((readSize = io_->read(buf.data(), buf.size()))) {
if (outIo.write(buf.c_data(), readSize) != readSize)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
} // JpegBase::doWriteMetadata

@ -46,19 +46,19 @@ namespace Exiv2 {
void MrwImage::setExifData(const ExifData& /*exifData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "Exif metadata", "MRW"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Exif metadata", "MRW"));
}
void MrwImage::setIptcData(const IptcData& /*iptcData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "IPTC metadata", "MRW"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "IPTC metadata", "MRW"));
}
void MrwImage::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "MRW"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "MRW"));
}
void MrwImage::readMetadata()
@ -67,13 +67,13 @@ namespace Exiv2 {
std::cerr << "Reading MRW file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isMrwType(*io_, false)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "MRW");
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "MRW");
}
clearMetadata();
@ -85,21 +85,21 @@ namespace Exiv2 {
uint32_t const end = getULong(tmp + 4, bigEndian);
pos += len;
enforce(pos <= end, kerFailedToReadImageData);
enforce(pos <= end, ErrorCode::kerFailedToReadImageData);
io_->read(tmp, len);
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
while (memcmp(tmp + 1, "TTW", 3) != 0) {
uint32_t const siz = getULong(tmp + 4, bigEndian);
enforce(siz <= end - pos, kerFailedToReadImageData);
enforce(siz <= end - pos, ErrorCode::kerFailedToReadImageData);
pos += siz;
io_->seek(siz, BasicIo::cur);
enforce(!io_->error() && !io_->eof(), kerFailedToReadImageData);
enforce(!io_->error() && !io_->eof(), ErrorCode::kerFailedToReadImageData);
enforce(len <= end - pos, kerFailedToReadImageData);
enforce(len <= end - pos, ErrorCode::kerFailedToReadImageData);
pos += len;
io_->read(tmp, len);
enforce(!io_->error() && !io_->eof(), kerFailedToReadImageData);
enforce(!io_->error() && !io_->eof(), ErrorCode::kerFailedToReadImageData);
}
const uint32_t siz = getULong(tmp + 4, bigEndian);
@ -108,10 +108,10 @@ namespace Exiv2 {
// greater than io_->size() then it is definitely invalid. But the
// exact bounds checking is done by the call to io_->read, which
// will fail if there are fewer than siz bytes left to read.
enforce(siz <= io_->size(), kerFailedToReadImageData);
enforce(siz <= io_->size(), ErrorCode::kerFailedToReadImageData);
DataBuf buf(siz);
io_->read(buf.data(), buf.size());
enforce(!io_->error() && !io_->eof(), kerFailedToReadImageData);
enforce(!io_->error() && !io_->eof(), ErrorCode::kerFailedToReadImageData);
ByteOrder bo = TiffParser::decode(exifData_,
iptcData_,
@ -124,7 +124,7 @@ namespace Exiv2 {
void MrwImage::writeMetadata()
{
// Todo: implement me!
throw(Error(kerWritingImageFormatUnsupported, "MRW"));
throw(Error(ErrorCode::kerWritingImageFormatUnsupported, "MRW"));
} // MrwImage::writeMetadata
// *************************************************************************

@ -53,17 +53,17 @@ namespace Exiv2 {
void OrfImage::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "ORF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "ORF"));
}
void OrfImage::printStructure(std::ostream& out, PrintStructureOption option, int depth) {
out << "ORF IMAGE" << std::endl;
if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError());
if (io_->open() != 0) throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
// Ensure that this is the correct image type
if ( imageType() == ImageType::none )
if (!isOrfType(*io_, false)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAJpeg);
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
io_->seek(0,BasicIo::beg);
@ -77,13 +77,13 @@ namespace Exiv2 {
std::cerr << "Reading ORF file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isOrfType(*io_, false)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "ORF");
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "ORF");
}
clearMetadata();
ByteOrder bo =

@ -81,14 +81,14 @@ namespace Exiv2 {
#endif
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isPgfType(*io_, true))
{
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "PGF");
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "PGF");
}
clearMetadata();
@ -99,10 +99,10 @@ namespace Exiv2 {
// 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);
enforce(headerSize <= std::numeric_limits<uint32_t>::max() - 8, ErrorCode::kerCorruptedMetadata);
#if LONG_MAX < UINT_MAX
enforce(headerSize + 8 <= static_cast<uint32_t>(std::numeric_limits<long>::max()),
kerCorruptedMetadata);
ErrorCode::kerCorruptedMetadata);
#endif
long size = static_cast<long>(headerSize) + 8 - io_->tell();
@ -111,16 +111,16 @@ namespace Exiv2 {
#endif
if (size < 0 || static_cast<size_t>(size) > io_->size())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
if (size == 0)
return;
DataBuf imgData(size);
const size_t bufRead = io_->read(imgData.data(), imgData.size());
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != imgData.size())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
auto image = Exiv2::ImageFactory::open(imgData.c_data(), imgData.size());
image->readMetadata();
@ -133,7 +133,7 @@ namespace Exiv2 {
{
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
auto tempIo = std::make_unique<MemIo>();
@ -146,8 +146,8 @@ namespace Exiv2 {
void PgfImage::doWriteMetadata(BasicIo& outIo)
{
if (!io_->isopen()) throw Error(kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(kerImageWriteFailed);
if (!io_->isopen()) throw Error(ErrorCode::kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(ErrorCode::kerImageWriteFailed);
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage::doWriteMetadata: Writing PGF file " << io_->path() << "\n";
@ -157,8 +157,8 @@ namespace Exiv2 {
// Ensure that this is the correct image type
if (!isPgfType(*io_, true))
{
if (io_->error() || io_->eof()) throw Error(kerInputDataReadFailed);
throw Error(kerNoImageInInputData);
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerInputDataReadFailed);
throw Error(ErrorCode::kerNoImageInInputData);
}
// Ensure PGF version.
@ -185,17 +185,17 @@ namespace Exiv2 {
//---------------------------------------------------------------
// Write PGF Signature.
if (outIo.write(pgfSignature, 3) != 3) throw Error(kerImageWriteFailed);
if (outIo.write(pgfSignature, 3) != 3) throw Error(ErrorCode::kerImageWriteFailed);
// Write Magic number.
if (outIo.putb(mnb) == EOF) throw Error(kerImageWriteFailed);
if (outIo.putb(mnb) == EOF) throw Error(ErrorCode::kerImageWriteFailed);
// Write new Header size.
uint32_t newHeaderSize = static_cast<uint32_t>(header.size()) + imgSize;
DataBuf buffer(4);
buffer.copyBytes(0, &newHeaderSize, 4);
byteSwap_(buffer,0,bSwap_);
if (outIo.write(buffer.c_data(), 4) != 4) throw Error(kerImageWriteFailed);
if (outIo.write(buffer.c_data(), 4) != 4) throw Error(ErrorCode::kerImageWriteFailed);
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage: new PGF header size : " << newHeaderSize << " bytes\n";
@ -208,11 +208,11 @@ namespace Exiv2 {
// Write Header data.
if (outIo.write(header.c_data(), header.size()) != header.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write new metadata byte array.
if (outIo.write(imgBuf.c_data(), imgBuf.size()) != imgBuf.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Copy the rest of PGF image data.
@ -220,16 +220,16 @@ namespace Exiv2 {
size_t readSize = 0;
while ((readSize=io_->read(buf.data(), buf.size())))
{
if (outIo.write(buf.c_data(), readSize) != readSize) throw Error(kerImageWriteFailed);
if (outIo.write(buf.c_data(), readSize) != readSize) throw Error(ErrorCode::kerImageWriteFailed);
}
if (outIo.error()) throw Error(kerImageWriteFailed);
if (outIo.error()) throw Error(ErrorCode::kerImageWriteFailed);
} // PgfImage::doWriteMetadata
byte PgfImage::readPgfMagicNumber(BasicIo& iIo)
{
byte b = iIo.getb();
if (iIo.error()) throw Error(kerFailedToReadImageData);
if (iIo.error()) throw Error(ErrorCode::kerFailedToReadImageData);
if (b < 0x36) // 0x36 = '6'.
{
@ -247,12 +247,12 @@ namespace Exiv2 {
DataBuf buffer(4);
const size_t bufRead = iIo.read(buffer.data(), buffer.size());
if (iIo.error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != buffer.size())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
auto headerSize = static_cast<int>(byteSwap_(buffer, 0, bSwap_));
if (headerSize <= 0 ) throw Error(kerNoImageInInputData);
if (headerSize <= 0 ) throw Error(ErrorCode::kerNoImageInInputData);
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage: PGF header size : " << headerSize << " bytes\n";
@ -266,9 +266,9 @@ namespace Exiv2 {
DataBuf header(16);
size_t bufRead = iIo.read(header.data(), header.size());
if (iIo.error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != header.size())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
DataBuf work(8); // don't disturb the binary data - doWriteMetadata reuses it
work.copyBytes(0,header.c_data(),8);
@ -288,8 +288,8 @@ namespace Exiv2 {
header.alloc(16 + 256*3);
bufRead = iIo.read(header.data(16), 256*3);
if (iIo.error()) throw Error(kerFailedToReadImageData);
if (bufRead != 256*3) throw Error(kerInputDataReadFailed);
if (iIo.error()) throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != 256*3) throw Error(ErrorCode::kerInputDataReadFailed);
}
return header;

@ -81,11 +81,11 @@ namespace Exiv2::Internal {
// From a tEXt, zTXt, or iTXt chunk, we get the keyword which is null terminated.
const size_t offset = stripHeader ? 8ul : 0ul;
if (data.size() <= offset)
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
auto it = std::find(data.cbegin() + offset, data.cend(), 0);
if (it == data.cend())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
return {data.c_data() + offset, std::distance(data.cbegin(), it) - offset};
}
@ -95,7 +95,7 @@ namespace Exiv2::Internal {
DataBuf arr;
if (type == zTXt_Chunk) {
enforce(data.size() >= Safe::add(keysize, nullSeparators), Exiv2::kerCorruptedMetadata);
enforce(data.size() >= Safe::add(keysize, nullSeparators), ErrorCode::kerCorruptedMetadata);
// Extract a deflate compressed Latin-1 text chunk
@ -106,17 +106,17 @@ namespace Exiv2::Internal {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngChunk::parseTXTChunk: Non-standard zTXt compression method.\n";
#endif
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
// compressed string after the compression technique spec
const byte* compressedText = data.c_data(keysize + nullSeparators);
size_t compressedTextSize = data.size() - keysize - nullSeparators;
enforce(compressedTextSize < data.size(), kerCorruptedMetadata);
enforce(compressedTextSize < data.size(), ErrorCode::kerCorruptedMetadata);
zlibUncompress(compressedText, static_cast<uint32_t>(compressedTextSize), arr);
} else if (type == tEXt_Chunk) {
enforce(data.size() >= Safe::add(keysize, static_cast<size_t>(1)), Exiv2::kerCorruptedMetadata);
enforce(data.size() >= Safe::add(keysize, static_cast<size_t>(1)), ErrorCode::kerCorruptedMetadata);
// Extract a non-compressed Latin-1 text chunk
// the text comes after the key, but isn't null terminated
@ -125,9 +125,9 @@ namespace Exiv2::Internal {
arr = DataBuf(text, textsize);
} else if (type == iTXt_Chunk) {
enforce(data.size() > Safe::add(keysize, static_cast<size_t>(3)), Exiv2::kerCorruptedMetadata);
enforce(data.size() > Safe::add(keysize, static_cast<size_t>(3)), ErrorCode::kerCorruptedMetadata);
const size_t nullCount = std::count(data.c_data(keysize + 3), data.c_data(data.size()-1), '\0');
enforce(nullCount >= nullSeparators, Exiv2::kerCorruptedMetadata);
enforce(nullCount >= nullSeparators, ErrorCode::kerCorruptedMetadata);
// Extract a deflate compressed or uncompressed UTF-8 text chunk
@ -136,8 +136,8 @@ namespace Exiv2::Internal {
// we get the compression method after the compression flag
const byte compressionMethod = data.read_uint8(keysize + 2);
enforce(compressionFlag == 0x00 || compressionFlag == 0x01, Exiv2::kerCorruptedMetadata);
enforce(compressionMethod == 0x00, Exiv2::kerCorruptedMetadata);
enforce(compressionFlag == 0x00 || compressionFlag == 0x01, ErrorCode::kerCorruptedMetadata);
enforce(compressionMethod == 0x00, ErrorCode::kerCorruptedMetadata);
// language description string after the compression technique spec
const size_t languageTextMaxSize = data.size() - keysize - 3;
@ -145,7 +145,7 @@ namespace Exiv2::Internal {
const size_t languageTextSize = languageText.size();
enforce(data.size() >= Safe::add(Safe::add(keysize, static_cast<size_t>(4)), languageTextSize),
Exiv2::kerCorruptedMetadata);
ErrorCode::kerCorruptedMetadata);
// translated keyword string after the language description
std::string translatedKeyText = string_from_unterminated(
data.c_str(keysize + 3 + languageTextSize + 1), data.size() - (keysize + 3 + languageTextSize + 1));
@ -154,7 +154,7 @@ namespace Exiv2::Internal {
if ((compressionFlag == 0x00) || (compressionFlag == 0x01 && compressionMethod == 0x00)) {
enforce(Safe::add(keysize + 3 + languageTextSize + 1,
Safe::add(translatedKeyTextSize, static_cast<size_t>(1))) <= data.size(),
Exiv2::kerCorruptedMetadata);
ErrorCode::kerCorruptedMetadata);
const byte* text = data.c_data(keysize + 3 + languageTextSize + 1 + translatedKeyTextSize + 1);
const auto textsize = static_cast<long>(
@ -180,13 +180,13 @@ namespace Exiv2::Internal {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngChunk::parseTXTChunk: Non-standard iTXt compression method.\n";
#endif
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
} else {
#ifdef DEBUG
std::cerr << "Exiv2::PngChunk::parseTXTChunk: We found a field, not expected though\n";
#endif
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
return arr;
@ -383,12 +383,12 @@ namespace Exiv2::Internal {
}
} else {
// something bad happened
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
} while (zlibResult == Z_BUF_ERROR);
if (zlibResult != Z_OK) {
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
} // PngChunk::zlibUncompress
@ -416,11 +416,11 @@ namespace Exiv2::Internal {
compressedLen *= 2;
// DoS protection. Cap max compressed size
if (compressedLen > 131072)
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
break;
default:
// Something bad happened
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
} while (zlibResult == Z_BUF_ERROR);
@ -565,7 +565,7 @@ namespace Exiv2::Internal {
return {};
}
enforce(length <= static_cast<size_t>(eot - sp) / 2, Exiv2::kerCorruptedMetadata);
enforce(length <= static_cast<size_t>(eot - sp) / 2, Exiv2::ErrorCode::kerCorruptedMetadata);
// Allocate space
if (length == 0) {
@ -587,7 +587,7 @@ namespace Exiv2::Internal {
size_t nibbles = length * 2;
for (size_t i = 0; i < nibbles; i++) {
enforce(sp < eot, Exiv2::kerCorruptedMetadata);
enforce(sp < eot, Exiv2::ErrorCode::kerCorruptedMetadata);
while (*sp < '0' || (*sp > '9' && *sp < 'a') || *sp > 'f') {
if (*sp == '\0') {
#ifdef EXIV2_DEBUG_MESSAGES
@ -597,7 +597,7 @@ namespace Exiv2::Internal {
}
sp++;
enforce(sp < eot, Exiv2::kerCorruptedMetadata);
enforce(sp < eot, Exiv2::ErrorCode::kerCorruptedMetadata);
}
if (i % 2 == 0)

@ -190,10 +190,10 @@ namespace Exiv2 {
void PngImage::printStructure(std::ostream& out, PrintStructureOption option, int depth)
{
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
if (!isPngType(*io_, true)) {
throw Error(kerNotAnImage, "PNG");
throw Error(ErrorCode::kerNotAnImage, "PNG");
}
char chType[5];
@ -224,9 +224,9 @@ namespace Exiv2 {
size_t bufRead = io_->read(cheaderBuf.data(), cheaderBuf.size());
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != cheaderBuf.size())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
// Decode chunk data length.
const uint32_t dataOffset = cheaderBuf.read_uint32(0, Exiv2::bigEndian);
@ -240,12 +240,12 @@ namespace Exiv2 {
|| dataOffset > uint32_t(0x7FFFFFFF)
|| dataOffset > imgSize - restore
){
throw Exiv2::Error(kerFailedToReadImageData);
throw Exiv2::Error(ErrorCode::kerFailedToReadImageData);
}
DataBuf buff(dataOffset);
bufRead = io_->read(buff.data(),dataOffset);
enforce(bufRead == dataOffset, kerFailedToReadImageData);
enforce(bufRead == dataOffset, ErrorCode::kerFailedToReadImageData);
io_->seek(restore, BasicIo::beg);
// format output
@ -265,7 +265,7 @@ namespace Exiv2 {
io_->seek(dataOffset, BasicIo::cur);// jump to checksum
byte checksum[4];
bufRead = io_->read(checksum,4);
enforce(bufRead == 4, kerFailedToReadImageData);
enforce(bufRead == 4, ErrorCode::kerFailedToReadImageData);
io_->seek(restore, BasicIo::beg) ;// restore file pointer
out << Internal::stringFormat("%8d | %-5s |%8d | ", static_cast<uint32_t>(address), chType,
@ -297,15 +297,15 @@ namespace Exiv2 {
if( bDump ) {
DataBuf dataBuf;
enforce(dataOffset < std::numeric_limits<uint32_t>::max(), kerFailedToReadImageData);
enforce(dataOffset < std::numeric_limits<uint32_t>::max(), ErrorCode::kerFailedToReadImageData);
DataBuf data(dataOffset + 1ul);
data.write_uint8(dataOffset, 0);
bufRead = io_->read(data.data(), dataOffset);
enforce(bufRead == dataOffset, kerFailedToReadImageData);
enforce(bufRead == dataOffset, ErrorCode::kerFailedToReadImageData);
io_->seek(restore, BasicIo::beg);
size_t name_l = std::strlen(data.c_str()) +
1; // leading string length
enforce(name_l < dataOffset, kerCorruptedMetadata);
enforce(name_l < dataOffset, ErrorCode::kerCorruptedMetadata);
auto start = static_cast<uint32_t>(name_l);
bool bLF = false;
@ -379,7 +379,7 @@ namespace Exiv2 {
}
io_->seek(dataOffset+4, BasicIo::cur);// jump past checksum
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
}
}
@ -391,10 +391,10 @@ namespace Exiv2 {
#endif
const size_t bufRead = io.read(buffer.data(), buffer.size());
if (io.error()) {
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
if (bufRead != buffer.size()) {
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
}
}
@ -405,11 +405,11 @@ namespace Exiv2 {
#endif
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
if (!isPngType(*io_, true)) {
throw Error(kerNotAnImage, "PNG");
throw Error(ErrorCode::kerNotAnImage, "PNG");
}
clearMetadata();
@ -426,7 +426,7 @@ namespace Exiv2 {
if (pos == -1 ||
chunkLength > uint32_t(0x7FFFFFFF) ||
chunkLength > imgSize - pos) {
throw Exiv2::Error(kerFailedToReadImageData);
throw Exiv2::Error(ErrorCode::kerFailedToReadImageData);
}
std::string chunkType(cheaderBuf.c_str(4), 4);
@ -468,12 +468,12 @@ namespace Exiv2 {
uint32_t iccOffset = 0;
do {
enforce(iccOffset < 80 && iccOffset < chunkLength,
Exiv2::kerCorruptedMetadata);
Exiv2::ErrorCode::kerCorruptedMetadata);
} while(chunkData.read_uint8(iccOffset++) != 0x00);
profileName_ = std::string(chunkData.c_str(), iccOffset-1);
++iccOffset; // +1 = 'compressed' flag
enforce(iccOffset <= chunkLength, Exiv2::kerCorruptedMetadata);
enforce(iccOffset <= chunkLength, Exiv2::ErrorCode::kerCorruptedMetadata);
zlibToDataBuf(chunkData.c_data(iccOffset), chunkLength - iccOffset, iccProfile_);
#ifdef EXIV2_DEBUG_MESSAGES
@ -495,7 +495,7 @@ namespace Exiv2 {
#endif
io_->seek(chunkLength + 4 , BasicIo::cur);
if (io_->error() || io_->eof()) {
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
}
} // PngImage::readMetadata
@ -504,7 +504,7 @@ namespace Exiv2 {
{
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
auto tempIo = std::make_unique<MemIo>();
@ -518,9 +518,9 @@ namespace Exiv2 {
void PngImage::doWriteMetadata(BasicIo& outIo)
{
if (!io_->isopen())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
if (!outIo.isopen())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: Writing PNG file " << io_->path() << "\n";
@ -528,12 +528,12 @@ namespace Exiv2 {
#endif
if (!isPngType(*io_, true)) {
throw Error(kerNoImageInInputData);
throw Error(ErrorCode::kerNoImageInInputData);
}
// Write PNG Signature.
if (outIo.write(pngSignature, 8) != 8)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
DataBuf cheaderBuf(8); // Chunk header : 4 bytes (data size) + 4 bytes (chunk type).
@ -542,15 +542,15 @@ namespace Exiv2 {
// Read chunk header.
size_t bufRead = io_->read(cheaderBuf.data(), 8);
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != 8)
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
// Decode chunk data length.
uint32_t dataOffset = cheaderBuf.read_uint32(0, Exiv2::bigEndian);
if (dataOffset > 0x7FFFFFFF)
throw Exiv2::Error(kerFailedToReadImageData);
throw Exiv2::Error(ErrorCode::kerFailedToReadImageData);
// Read whole chunk : Chunk header + Chunk data (not fixed size - can be null) + CRC (4 bytes).
@ -558,9 +558,9 @@ namespace Exiv2 {
chunkBuf.copyBytes(0, cheaderBuf.c_data(), 8); // Copy header.
bufRead = io_->read(chunkBuf.data(8), dataOffset + 4); // Extract chunk data + CRC
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (bufRead != static_cast<size_t>(dataOffset) + 4)
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
char szChunk[5];
memcpy(szChunk,cheaderBuf.c_data(4),4);
@ -573,7 +573,7 @@ namespace Exiv2 {
std::cout << "Exiv2::PngImage::doWriteMetadata: Write IEND chunk (length: " << dataOffset << ")\n";
#endif
if (outIo.write(chunkBuf.data(), chunkBuf.size()) != chunkBuf.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
return;
}
if (!strcmp(szChunk, "eXIf")) {
@ -584,7 +584,7 @@ namespace Exiv2 {
std::cout << "Exiv2::PngImage::doWriteMetadata: Write IHDR chunk (length: " << dataOffset << ")\n";
#endif
if (outIo.write(chunkBuf.data(), chunkBuf.size()) != chunkBuf.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write all updated metadata here, just after IHDR.
if (!comment_.empty())
@ -592,7 +592,7 @@ namespace Exiv2 {
// Update Comment data to a new PNG chunk
std::string chunk = PngChunk::makeMetadataChunk(comment_, mdComment);
if (outIo.write(reinterpret_cast<const byte*>(chunk.data()), chunk.size()) != chunk.size()) {
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
}
@ -607,7 +607,7 @@ namespace Exiv2 {
std::string(reinterpret_cast<const char*>(&blob[0]), blob.size());
std::string chunk = PngChunk::makeMetadataChunk(rawExif, mdExif);
if (outIo.write(reinterpret_cast<const byte*>(chunk.data()), chunk.size()) != chunk.size()) {
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
}
}
@ -620,7 +620,7 @@ namespace Exiv2 {
std::string rawIptc(newPsData.c_str(), newPsData.size());
std::string chunk = PngChunk::makeMetadataChunk(rawIptc, mdIptc);
if (outIo.write(reinterpret_cast<const byte*>(chunk.data()), chunk.size()) != chunk.size()) {
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
}
}
@ -649,7 +649,7 @@ namespace Exiv2 {
|| outIo.write (compressed.c_data(),compressed.size()) != compressed.size()
|| outIo.write(crc,4) != 4
){
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: build iCCP"
@ -670,7 +670,7 @@ namespace Exiv2 {
std::string chunk = PngChunk::makeMetadataChunk(xmpPacket_, mdXmp);
if (outIo.write(reinterpret_cast<const byte*>(chunk.data()), chunk.size()) !=
chunk.size()) {
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
}
} else if (!strcmp(szChunk, "tEXt") || !strcmp(szChunk, "zTXt") || !strcmp(szChunk, "iTXt") ||
@ -692,7 +692,7 @@ namespace Exiv2 {
<< " chunk (length: " << dataOffset << ")" << std::endl;
#endif
if (outIo.write(chunkBuf.c_data(), chunkBuf.size()) != chunkBuf.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
} else {
// Write all others chunk as well.
@ -701,7 +701,7 @@ namespace Exiv2 {
<< " chunk (length: " << dataOffset << ")" << std::endl;
#endif
if (outIo.write(chunkBuf.c_data(), chunkBuf.size()) != chunkBuf.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
}
@ -722,7 +722,7 @@ namespace Exiv2 {
bool isPngType(BasicIo& iIo, bool advance)
{
if (iIo.error() || iIo.eof()) {
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
}
const int32_t len = 8;
byte buf[len];

@ -433,7 +433,7 @@ namespace {
BasicIo &io = image_.io();
if (io.open() != 0) {
throw Error(kerDataSourceOpenFailed, io.path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io.path(), strError());
}
IoCloser closer(io);
const byte* data = io.mmap();
@ -464,7 +464,7 @@ namespace {
}
return {record + sizeHdr + 28, sizeData - 28};
}
throw Error(kerErrorMessage, "Invalid native preview filter: " + nativePreview_.filter_);
throw Error(ErrorCode::kerErrorMessage, "Invalid native preview filter: " + nativePreview_.filter_);
}
bool LoaderNative::readDimensions()
@ -544,7 +544,7 @@ namespace {
BasicIo &io = image_.io();
if (io.open() != 0) {
throw Error(kerDataSourceOpenFailed, io.path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io.path(), strError());
}
IoCloser closer(io);
@ -561,7 +561,7 @@ namespace {
BasicIo &io = image_.io();
if (io.open() != 0) {
throw Error(kerDataSourceOpenFailed, io.path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io.path(), strError());
}
IoCloser closer(io);
const Exiv2::byte* base = io.mmap();
@ -765,7 +765,7 @@ namespace {
BasicIo &io = image_.io();
if (io.open() != 0) {
throw Error(kerDataSourceOpenFailed, io.path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io.path(), strError());
}
IoCloser closer(io);
@ -783,7 +783,7 @@ namespace {
}
else {
// FIXME: the buffer is probably copied twice, it should be optimized
enforce(size_ <= static_cast<uint32_t>(io.size()), kerCorruptedMetadata);
enforce(size_ <= static_cast<uint32_t>(io.size()), ErrorCode::kerCorruptedMetadata);
DataBuf buf(size_);
uint32_t idxBuf = 0;
for (size_t i = 0; i < sizes.count(); i++) {
@ -794,7 +794,7 @@ namespace {
// see the constructor of LoaderTiff
// But e.g in malicious files some of these values could be negative
// That's why we check again for each step here to really make sure we don't overstep
enforce(Safe::add(idxBuf, size) <= size_, kerCorruptedMetadata);
enforce(Safe::add(idxBuf, size) <= size_, ErrorCode::kerCorruptedMetadata);
if (size!=0 && Safe::add(offset, size) <= static_cast<uint32_t>(io.size())){
buf.copyBytes(idxBuf, base + offset, size);
}

@ -4096,7 +4096,7 @@ namespace Exiv2 {
const XmpNsInfo::Prefix pf(prefix);
const XmpNsInfo* xn = lookupNsRegistryUnsafe(pf);
if (!xn) xn = find(xmpNsInfo, pf);
if (!xn) throw Error(kerNoNamespaceInfoForXmpPrefix, prefix);
if (!xn) throw Error(ErrorCode::kerNoNamespaceInfoForXmpPrefix, prefix);
return xn;
}
@ -4158,7 +4158,7 @@ namespace Exiv2 {
{
// Validate prefix
if (XmpProperties::ns(prefix).empty())
throw Error(kerNoNamespaceForPrefix, prefix);
throw Error(ErrorCode::kerNoNamespaceForPrefix, prefix);
property_ = property;
prefix_ = prefix;
@ -4244,29 +4244,29 @@ namespace Exiv2 {
// Get the family name, prefix and property name parts of the key
std::string::size_type pos1 = key.find('.');
if (pos1 == std::string::npos) {
throw Error(kerInvalidKey, key);
throw Error(ErrorCode::kerInvalidKey, key);
}
std::string familyName = key.substr(0, pos1);
if (0 != strcmp(familyName.c_str(), familyName_)) {
throw Error(kerInvalidKey, key);
throw Error(ErrorCode::kerInvalidKey, key);
}
std::string::size_type pos0 = pos1 + 1;
pos1 = key.find('.', pos0);
if (pos1 == std::string::npos) {
throw Error(kerInvalidKey, key);
throw Error(ErrorCode::kerInvalidKey, key);
}
std::string prefix = key.substr(pos0, pos1 - pos0);
if (prefix.empty()) {
throw Error(kerInvalidKey, key);
throw Error(ErrorCode::kerInvalidKey, key);
}
std::string property = key.substr(pos1 + 1);
if (property.empty()) {
throw Error(kerInvalidKey, key);
throw Error(ErrorCode::kerInvalidKey, key);
}
// Validate prefix
if (XmpProperties::ns(prefix).empty())
throw Error(kerNoNamespaceForPrefix, prefix);
throw Error(ErrorCode::kerNoNamespaceForPrefix, prefix);
property_ = property;
prefix_ = prefix;

@ -104,7 +104,7 @@ namespace Exiv2 {
void PsdImage::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "Photoshop"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "Photoshop"));
}
void PsdImage::readMetadata()
@ -114,15 +114,15 @@ namespace Exiv2 {
#endif
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isPsdType(*io_, false))
{
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
clearMetadata();
@ -143,7 +143,7 @@ namespace Exiv2 {
byte buf[26];
if (io_->read(buf, 26) != 26)
{
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
pixelWidth_ = getLong(buf + 18, bigEndian);
pixelHeight_ = getLong(buf + 14, bigEndian);
@ -152,31 +152,31 @@ namespace Exiv2 {
// the first four bytes of which specify the byte size of the whole section
if (io_->read(buf, 4) != 4)
{
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
// skip it
uint32_t colorDataLength = getULong(buf, bigEndian);
if (io_->seek(colorDataLength, BasicIo::cur))
{
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
// after the color data section, comes a list of resource blocks, preceded by the total byte size
if (io_->read(buf, 4) != 4)
{
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
uint32_t resourcesLength = getULong(buf, bigEndian);
enforce(resourcesLength < io_->size(), Exiv2::kerCorruptedMetadata);
enforce(resourcesLength < io_->size(), Exiv2::ErrorCode::kerCorruptedMetadata);
while (resourcesLength > 0)
{
enforce(resourcesLength >= 8, Exiv2::kerCorruptedMetadata);
enforce(resourcesLength >= 8, Exiv2::ErrorCode::kerCorruptedMetadata);
resourcesLength -= 8;
if (io_->read(buf, 8) != 8)
{
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
if (!Photoshop::isIrb(buf, 4))
@ -187,16 +187,16 @@ namespace Exiv2 {
uint32_t resourceNameLength = buf[6] & ~1;
// skip the resource name, plus any padding
enforce(resourceNameLength <= resourcesLength, Exiv2::kerCorruptedMetadata);
enforce(resourceNameLength <= resourcesLength, Exiv2::ErrorCode::kerCorruptedMetadata);
resourcesLength -= resourceNameLength;
io_->seek(resourceNameLength, BasicIo::cur);
// read resource size
enforce(resourcesLength >= 4, Exiv2::kerCorruptedMetadata);
enforce(resourcesLength >= 4, Exiv2::ErrorCode::kerCorruptedMetadata);
resourcesLength -= 4;
if (io_->read(buf, 4) != 4)
{
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
uint32_t resourceSize = getULong(buf, bigEndian);
uint32_t curOffset = io_->tell();
@ -205,10 +205,10 @@ namespace Exiv2 {
std::cerr << std::hex << "resourceId: " << resourceId << std::dec << " length: " << resourceSize << std::hex << "\n";
#endif
enforce(resourceSize <= resourcesLength, Exiv2::kerCorruptedMetadata);
enforce(resourceSize <= resourcesLength, Exiv2::ErrorCode::kerCorruptedMetadata);
readResourceBlock(resourceId, resourceSize);
resourceSize = (resourceSize + 1) & ~1; // pad to even
enforce(resourceSize <= resourcesLength, Exiv2::kerCorruptedMetadata);
enforce(resourceSize <= resourcesLength, Exiv2::ErrorCode::kerCorruptedMetadata);
resourcesLength -= resourceSize;
io_->seek(curOffset + resourceSize, BasicIo::beg);
}
@ -224,7 +224,7 @@ namespace Exiv2 {
DataBuf rawIPTC(resourceSize);
io_->read(rawIPTC.data(), rawIPTC.size());
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (IptcParser::decode(iptcData_, rawIPTC.c_data(), static_cast<uint32_t>(rawIPTC.size()))) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << "Failed to decode IPTC metadata.\n";
@ -239,7 +239,7 @@ namespace Exiv2 {
DataBuf rawExif(resourceSize);
io_->read(rawExif.data(), rawExif.size());
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
ByteOrder bo = ExifParser::decode(exifData_, rawExif.c_data(), rawExif.size());
setByteOrder(bo);
if (!rawExif.empty() && byteOrder() == invalidByteOrder) {
@ -256,7 +256,7 @@ namespace Exiv2 {
DataBuf xmpPacket(resourceSize);
io_->read(xmpPacket.data(), xmpPacket.size());
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
xmpPacket_.assign(xmpPacket.c_str(), xmpPacket.size());
if (!xmpPacket_.empty() && XmpParser::decode(xmpData_, xmpPacket_)) {
#ifndef SUPPRESS_WARNINGS
@ -290,7 +290,7 @@ namespace Exiv2 {
byte buf[28];
if (io_->read(buf, 28) != 28)
{
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
NativePreview nativePreview;
nativePreview.position_ = io_->tell();
@ -302,7 +302,7 @@ namespace Exiv2 {
if (nativePreview.size_ > 0 && nativePreview.position_ >= 0) {
io_->seek(static_cast<long>(nativePreview.size_), BasicIo::cur);
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (format == 1) {
nativePreview.filter_ = "";
@ -326,7 +326,7 @@ namespace Exiv2 {
{
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
auto tempIo = std::make_unique<MemIo>();
@ -340,9 +340,9 @@ namespace Exiv2 {
void PsdImage::doWriteMetadata(BasicIo& outIo)
{
if (!io_->isopen())
throw Error(kerInputDataReadFailed);
throw Error(ErrorCode::kerInputDataReadFailed);
if (!outIo.isopen())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PsdImage::doWriteMetadata: Writing PSD file " << io_->path() << "\n";
@ -352,8 +352,8 @@ namespace Exiv2 {
// Ensure that this is the correct image type
if (!isPsdType(*io_, true)) {
if (io_->error() || io_->eof())
throw Error(kerInputDataReadFailed);
throw Error(kerNoImageInInputData);
throw Error(ErrorCode::kerInputDataReadFailed);
throw Error(ErrorCode::kerNoImageInInputData);
}
io_->seek(0, BasicIo::beg); // rewind
@ -364,22 +364,22 @@ namespace Exiv2 {
// Get Photoshop header from original file
byte psd_head[26];
if (io_->read(psd_head, 26) != 26)
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
// Write Photoshop header data out to new PSD file
if (outIo.write(psd_head, 26) != 26)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Read colorDataLength from original PSD
if (io_->read(buf, 4) != 4)
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
uint32_t colorDataLength = getULong(buf, bigEndian);
// Write colorDataLength
ul2Data(buf, colorDataLength, bigEndian);
if (outIo.write(buf, 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::dec << "colorDataLength: " << colorDataLength << "\n";
#endif
@ -390,19 +390,19 @@ namespace Exiv2 {
? static_cast<size_t>(colorDataLength) - readTotal
: lbuf.size();
if (io_->read(lbuf.data(), toRead) != toRead)
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
readTotal += toRead;
if (outIo.write(lbuf.c_data(), toRead) != toRead)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
uint32_t resLenOffset = io_->tell(); // remember for later update
// Read length of all resource blocks from original PSD
if (io_->read(buf, 4) != 4)
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
uint32_t oldResLength = getULong(buf, bigEndian);
uint32_t newResLength = 0;
@ -410,7 +410,7 @@ namespace Exiv2 {
// Write oldResLength (will be updated later)
ul2Data(buf, oldResLength, bigEndian);
if (outIo.write(buf, 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::dec << "oldResLength: " << oldResLength << "\n";
@ -425,14 +425,14 @@ namespace Exiv2 {
bool xmpDone = false;
while (oldResLength > 0) {
if (io_->read(buf, 8) != 8)
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
// read resource type and ID
uint32_t resourceType = getULong(buf, bigEndian);
if (!Photoshop::isIrb(buf, 4))
{
throw Error(kerNotAnImage, "Photoshop"); // bad resource type
throw Error(ErrorCode::kerNotAnImage, "Photoshop"); // bad resource type
}
uint16_t resourceId = getUShort(buf + 4, bigEndian);
uint32_t resourceNameLength = buf[6];
@ -442,11 +442,11 @@ namespace Exiv2 {
// read rest of resource name, plus any padding
DataBuf resName(256);
if (io_->read(resName.data(), adjResourceNameLen) != adjResourceNameLen)
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
// read resource size (actual length w/o padding!)
if (io_->read(buf, 4) != 4)
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
uint32_t resourceSize = getULong(buf, bigEndian);
uint32_t pResourceSize = (resourceSize + 1) & ~1; // padded resource size
@ -485,22 +485,22 @@ namespace Exiv2 {
// Copy resource block to new PSD file
ul2Data(buf, resourceType, bigEndian);
if (outIo.write(buf, 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
us2Data(buf, resourceId, bigEndian);
if (outIo.write(buf, 2) != 2)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write resource name as Pascal string
buf[0] = resourceNameLength & 0x00ff;
if (outIo.write(buf, 1) != 1)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
buf[0] = resourceNameFirstChar;
if (outIo.write(buf, 1) != 1)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(resName.c_data(), adjResourceNameLen) != static_cast<size_t>(adjResourceNameLen))
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
ul2Data(buf, resourceSize, bigEndian);
if (outIo.write(buf, 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
readTotal = 0;
while (readTotal < pResourceSize) {
@ -509,14 +509,14 @@ namespace Exiv2 {
? static_cast<long>(pResourceSize - readTotal)
: static_cast<long>(lbuf.size());
if (io_->read(lbuf.data(), toRead) != toRead) {
throw Error(kerNotAnImage, "Photoshop");
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
}
readTotal += toRead;
if (outIo.write(lbuf.c_data(), toRead) != toRead)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
newResLength += pResourceSize + adjResourceNameLen + 12;
}
@ -548,10 +548,10 @@ namespace Exiv2 {
size_t readSize = 0;
while ((readSize=io_->read(lbuf.data(), lbuf.size()))) {
if (outIo.write(lbuf.c_data(), readSize) != readSize)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
if (outIo.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Update length of resources
#ifdef EXIV2_DEBUG_MESSAGES
@ -560,7 +560,7 @@ namespace Exiv2 {
outIo.seek(resLenOffset, BasicIo::beg);
ul2Data(buf, newResLength, bigEndian);
if (outIo.write(buf, 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
} // PsdImage::doWriteMetadata
@ -577,25 +577,25 @@ namespace Exiv2 {
std::cerr << std::dec << "Writing IPTC_NAA: size: " << rawIptc.size() << "\n";
#endif
if (out.write(reinterpret_cast<const byte*>(Photoshop::irbId_[0]), 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
us2Data(buf, kPhotoshopResourceID_IPTC_NAA, bigEndian);
if (out.write(buf, 2) != 2)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
us2Data(buf, 0, bigEndian); // NULL resource name
if (out.write(buf, 2) != 2)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
ul2Data(buf, static_cast<uint32_t>(rawIptc.size()), bigEndian);
if (out.write(buf, 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write encoded Iptc data
if (out.write(rawIptc.c_data(), rawIptc.size()) != rawIptc.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
resLength += static_cast<uint32_t>(rawIptc.size()) + 12;
if (rawIptc.size() & 1) // even padding
{
buf[0] = 0;
if (out.write(buf, 1) != 1)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
resLength++;
}
}
@ -623,25 +623,25 @@ namespace Exiv2 {
std::cerr << std::dec << "Writing ExifInfo: size: " << blob.size() << "\n";
#endif
if (out.write(reinterpret_cast<const byte*>(Photoshop::irbId_[0]), 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
us2Data(buf, kPhotoshopResourceID_ExifInfo, bigEndian);
if (out.write(buf, 2) != 2)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
us2Data(buf, 0, bigEndian); // NULL resource name
if (out.write(buf, 2) != 2)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
ul2Data(buf, static_cast<uint32_t>(blob.size()), bigEndian);
if (out.write(buf, 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write encoded Exif data
if (out.write(&blob[0], blob.size()) != blob.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
resLength += static_cast<long>(blob.size()) + 12;
if (blob.size() & 1) // even padding
{
buf[0] = 0;
if (out.write(buf, 1) != 1)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
resLength++;
}
}
@ -673,27 +673,27 @@ namespace Exiv2 {
std::cerr << std::dec << "Writing XMPPacket: size: " << xmpPacket.size() << "\n";
#endif
if (out.write(reinterpret_cast<const byte*>(Photoshop::irbId_[0]), 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
us2Data(buf, kPhotoshopResourceID_XMPPacket, bigEndian);
if (out.write(buf, 2) != 2)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
us2Data(buf, 0, bigEndian); // NULL resource name
if (out.write(buf, 2) != 2)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
ul2Data(buf, static_cast<uint32_t>(xmpPacket.size()), bigEndian);
if (out.write(buf, 4) != 4)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
// Write XMPPacket
if (out.write(reinterpret_cast<const byte*>(xmpPacket.data()), xmpPacket.size()) != xmpPacket.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (out.error())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
resLength += static_cast<uint32_t>(xmpPacket.size()) + 12;
if (xmpPacket.size() & 1) // even padding
{
buf[0] = 0;
if (out.write(buf, 1) != 1)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
resLength++;
}
}

@ -50,30 +50,30 @@ namespace Exiv2 {
void RafImage::setExifData(const ExifData& /*exifData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "Exif metadata", "RAF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Exif metadata", "RAF"));
}
void RafImage::setIptcData(const IptcData& /*iptcData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "IPTC metadata", "RAF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "IPTC metadata", "RAF"));
}
void RafImage::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "RAF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "RAF"));
}
void RafImage::printStructure(std::ostream& out, PrintStructureOption option, int depth) {
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
// Ensure this is the correct image type
if (!isRafType(*io_, true)) {
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "RAF");
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "RAF");
}
const bool bPrint = option==kpsBasic || option==kpsRecursive;
@ -266,49 +266,49 @@ namespace Exiv2 {
std::cerr << "Reading RAF file " << io_->path() << "\n";
#endif
if (io_->open() != 0)
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isRafType(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "RAF");
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "RAF");
}
clearMetadata();
if (io_->seek(84,BasicIo::beg) != 0)
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
byte jpg_img_offset [4];
if (io_->read(jpg_img_offset, 4) != 4)
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
byte jpg_img_length [4];
if (io_->read(jpg_img_length, 4) != 4)
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
uint32_t jpg_img_off_u32 = Exiv2::getULong(jpg_img_offset, bigEndian);
uint32_t jpg_img_len_u32 = Exiv2::getULong(jpg_img_length, bigEndian);
enforce(Safe::add(jpg_img_off_u32, jpg_img_len_u32) <= io_->size(), kerCorruptedMetadata);
enforce(Safe::add(jpg_img_off_u32, jpg_img_len_u32) <= io_->size(), ErrorCode::kerCorruptedMetadata);
#if LONG_MAX < UINT_MAX
enforce(jpg_img_off_u32 <= static_cast<uint32_t>(std::numeric_limits<long>::max()),
kerCorruptedMetadata);
ErrorCode::kerCorruptedMetadata);
enforce(jpg_img_len_u32 <= static_cast<uint32_t>(std::numeric_limits<long>::max()),
kerCorruptedMetadata);
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);
enforce(jpg_img_len >= 12, kerCorruptedMetadata);
enforce(jpg_img_len >= 12, ErrorCode::kerCorruptedMetadata);
DataBuf buf(jpg_img_len - 12);
if (io_->seek(jpg_img_off + 12,BasicIo::beg) != 0)
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
io_->read(buf.data(), buf.size());
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
io_->seek(0,BasicIo::beg); // rewind
@ -326,26 +326,26 @@ namespace Exiv2 {
// parse the tiff
byte readBuff[4];
if (io_->seek(100, BasicIo::beg) != 0)
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
if (io_->read(readBuff, 4) != 4 )
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
uint32_t tiffOffset = Exiv2::getULong(readBuff, bigEndian);
if (io_->read(readBuff, 4) != 4)
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
uint32_t tiffLength = Exiv2::getULong(readBuff, bigEndian);
// sanity check. Does tiff lie inside the file?
enforce(Safe::add(tiffOffset, tiffLength) <= io_->size(), kerCorruptedMetadata);
enforce(Safe::add(tiffOffset, tiffLength) <= io_->size(), ErrorCode::kerCorruptedMetadata);
if (io_->seek(tiffOffset, BasicIo::beg) != 0)
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
// Check if this really is a tiff and then call the tiff parser.
// Check is needed because some older models just embed a raw bitstream.
// For those files we skip the parsing step.
if (io_->read(readBuff, 4) != 4) {
throw Error(kerFailedToReadImageData); }
throw Error(ErrorCode::kerFailedToReadImageData); }
io_->seek(-4, BasicIo::cur);
if (memcmp(readBuff, "\x49\x49\x2A\x00", 4) == 0 ||
memcmp(readBuff, "\x4D\x4D\x00\x2A", 4) == 0)
@ -367,7 +367,7 @@ namespace Exiv2 {
void RafImage::writeMetadata()
{
//! Todo: implement me!
throw(Error(kerWritingImageFormatUnsupported, "RAF"));
throw(Error(ErrorCode::kerWritingImageFormatUnsupported, "RAF"));
} // RafImage::writeMetadata
// *************************************************************************

@ -56,29 +56,29 @@ namespace Exiv2 {
void Rw2Image::setExifData(const ExifData& /*exifData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "Exif metadata", "RW2"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Exif metadata", "RW2"));
}
void Rw2Image::setIptcData(const IptcData& /*iptcData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "IPTC metadata", "RW2"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "IPTC metadata", "RW2"));
}
void Rw2Image::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "RW2"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "RW2"));
}
void Rw2Image::printStructure(std::ostream& out, PrintStructureOption option, int depth) {
out << "RW2 IMAGE" << std::endl;
if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError());
if (io_->open() != 0) throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
// Ensure that this is the correct image type
if ( imageType() == ImageType::none )
if (!isRw2Type(*io_, false)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAJpeg);
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
io_->seek(0,BasicIo::beg);
@ -92,13 +92,13 @@ namespace Exiv2 {
std::cerr << "Reading RW2 file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isRw2Type(*io_, false)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "RW2");
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "RW2");
}
clearMetadata();
ByteOrder bo =
@ -194,7 +194,7 @@ namespace Exiv2 {
void Rw2Image::writeMetadata()
{
// Todo: implement me!
throw(Error(kerWritingImageFormatUnsupported, "RW2"));
throw(Error(ErrorCode::kerWritingImageFormatUnsupported, "RW2"));
} // Rw2Image::writeMetadata
ByteOrder Rw2Parser::decode(

@ -211,31 +211,31 @@ namespace Exiv2 {
{
// Get the family name, IFD name and tag name parts of the key
std::string::size_type pos1 = key.find('.');
if (pos1 == std::string::npos) throw Error(kerInvalidKey, key);
if (pos1 == std::string::npos) throw Error(ErrorCode::kerInvalidKey, key);
std::string familyName = key.substr(0, pos1);
if (0 != strcmp(familyName.c_str(), familyName_)) {
throw Error(kerInvalidKey, key);
throw Error(ErrorCode::kerInvalidKey, key);
}
std::string::size_type pos0 = pos1 + 1;
pos1 = key.find('.', pos0);
if (pos1 == std::string::npos) throw Error(kerInvalidKey, key);
if (pos1 == std::string::npos) throw Error(ErrorCode::kerInvalidKey, key);
std::string groupName = key.substr(pos0, pos1 - pos0);
if (groupName.empty()) throw Error(kerInvalidKey, key);
if (groupName.empty()) throw Error(ErrorCode::kerInvalidKey, key);
std::string tn = key.substr(pos1 + 1);
if (tn.empty()) throw Error(kerInvalidKey, key);
if (tn.empty()) throw Error(ErrorCode::kerInvalidKey, key);
// Find IfdId
IfdId ifdId = groupId(groupName);
if (ifdId == ifdIdNotSet) throw Error(kerInvalidKey, key);
if (ifdId == ifdIdNotSet) throw Error(ErrorCode::kerInvalidKey, key);
if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) {
throw Error(kerInvalidKey, key);
throw Error(ErrorCode::kerInvalidKey, key);
}
// Convert tag
uint16_t tag = tagNumber(tn, ifdId);
// Get tag info
tagInfo_ = tagInfo(tag, ifdId);
if (!tagInfo_)
throw Error(kerInvalidKey, key);
throw Error(ErrorCode::kerInvalidKey, key);
tag_ = tag;
ifdId_ = ifdId;
@ -260,11 +260,11 @@ namespace Exiv2 {
IfdId ifdId = groupId(groupName);
// Todo: Test if this condition can be removed
if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) {
throw Error(kerInvalidIfdId, ifdId);
throw Error(ErrorCode::kerInvalidIfdId, ifdId);
}
const TagInfo* ti = tagInfo(tag, ifdId);
if (!ti) {
throw Error(kerInvalidIfdId, ifdId);
throw Error(ErrorCode::kerInvalidIfdId, ifdId);
}
p_->groupName_ = groupName;
p_->makeKey(tag, ifdId, ti);
@ -275,7 +275,7 @@ namespace Exiv2 {
{
auto ifdId = static_cast<IfdId>(ti.ifdId_);
if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) {
throw Error(kerInvalidIfdId, ifdId);
throw Error(ErrorCode::kerInvalidIfdId, ifdId);
}
p_->groupName_ = Exiv2::groupName(ifdId);
p_->makeKey(ti.tag_, ifdId, &ti);

@ -71,16 +71,16 @@ namespace Exiv2::Internal {
{ canonFiId, "Makernote", "CanonFi", CanonMakerNote::tagListFi },
{ canonPaId, "Makernote", "CanonPa", CanonMakerNote::tagListPa },
{ canonPrId, "Makernote", "CanonPr", CanonMakerNote::tagListPr },
{ canonVigCor2Id, "Makernote", "CanonVigCor2", CanonMakerNote::tagListVigCor2 },
{ canonLiOpId, "Makernote", "CanonLiOp", CanonMakerNote::tagListLiOp },
{ canonVigCor2Id, "Makernote", "CanonVigCor2", CanonMakerNote::tagListVigCor2 },
{ canonLiOpId, "Makernote", "CanonLiOp", CanonMakerNote::tagListLiOp },
{ canonAfMiAdjId, "Makernote", "CanonAfMiAdj", CanonMakerNote::tagListAfMiAdj },
{ canonLeId, "Makernote", "CanonLe", CanonMakerNote::tagListLe },
{ canonAmId, "Makernote", "CanonAm", CanonMakerNote::tagListAm },
{ canonFilId, "Makernote", "CanonFil", CanonMakerNote::tagListFil },
{ canonMeId, "Makernote", "CanonMe", CanonMakerNote::tagListMe },
{ canonHdrId, "Makernote", "CanonHdr", CanonMakerNote::tagListHdr },
{ canonAfCId, "Makernote", "CanonAfC", CanonMakerNote::tagListAfC },
{ canonRawBId, "Makernote", "CanonRawB", CanonMakerNote::tagListRawB },
{ canonLeId, "Makernote", "CanonLe", CanonMakerNote::tagListLe },
{ canonAmId, "Makernote", "CanonAm", CanonMakerNote::tagListAm },
{ canonFilId, "Makernote", "CanonFil", CanonMakerNote::tagListFil },
{ canonMeId, "Makernote", "CanonMe", CanonMakerNote::tagListMe },
{ canonHdrId, "Makernote", "CanonHdr", CanonMakerNote::tagListHdr },
{ canonAfCId, "Makernote", "CanonAfC", CanonMakerNote::tagListAfC },
{ canonRawBId, "Makernote", "CanonRawB", CanonMakerNote::tagListRawB },
{ casioId, "Makernote", "Casio", CasioMakerNote::tagList },
{ casio2Id, "Makernote", "Casio2", Casio2MakerNote::tagList },
{ fujiId, "Makernote", "Fujifilm", FujiMakerNote::tagList },
@ -2642,7 +2642,8 @@ namespace Exiv2::Internal {
const TagInfo* ti = tagInfo(tagName, ifdId);
if (ti && ti->tag_ != 0xffff)
return ti->tag_;
if (!isHex(tagName, 4, "0x")) throw Error(kerInvalidTag, tagName, ifdId);
if (!isHex(tagName, 4, "0x"))
throw Error(ErrorCode::kerInvalidTag, tagName, ifdId);
std::istringstream is(tagName);
uint16_t tag = 0;
is >> std::hex >> tag;

@ -28,19 +28,19 @@ namespace Exiv2 {
void TgaImage::setExifData(const ExifData& /*exifData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "Exif metadata", "TGA"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Exif metadata", "TGA"));
}
void TgaImage::setIptcData(const IptcData& /*iptcData*/)
{
// Todo: implement me!
throw(Error(kerInvalidSettingForImage, "IPTC metadata", "TGA"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "IPTC metadata", "TGA"));
}
void TgaImage::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "TGA"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "TGA"));
}
void TgaImage::readMetadata()
@ -50,14 +50,14 @@ namespace Exiv2 {
#endif
if (io_->open() != 0)
{
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isTgaType(*io_, false))
{
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "TGA");
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "TGA");
}
clearMetadata();
@ -94,7 +94,7 @@ namespace Exiv2 {
void TgaImage::writeMetadata()
{
// Todo: implement me!
throw(Error(kerWritingImageFormatUnsupported, "TGA"));
throw(Error(ErrorCode::kerWritingImageFormatUnsupported, "TGA"));
} // TgaImage::writeMetadata
// *************************************************************************

@ -59,7 +59,7 @@ namespace Exiv2::Internal {
void IoWrapper::setTarget(int id, int64_t target)
{
if (target < 0 || target > std::numeric_limits<uint32_t>::max()) {
throw Error(kerOffsetOutOfRange);
throw Error(ErrorCode::kerOffsetOutOfRange);
}
if (pow_) pow_->setTarget(OffsetWriter::OffsetId(id), static_cast<uint32_t>(target));
}
@ -999,7 +999,8 @@ namespace Exiv2::Internal {
// Number of components to write
const uint32_t compCount = count();
if (compCount > 0xffff) throw Error(kerTooManyTiffDirectoryEntries, groupName(group()));
if (compCount > 0xffff)
throw Error(ErrorCode::kerTooManyTiffDirectoryEntries, groupName(group()));
// Size of next IFD, if any
uint32_t sizeNext = 0;
@ -1085,7 +1086,7 @@ namespace Exiv2::Internal {
uint32_t sv = component->size();
if (sv > 4) {
uint32_t d = component->write(ioWrapper, byteOrder, offset, valueIdx, dataIdx, imageIdx);
enforce(sv == d, kerImageWriteFailed);
enforce(sv == d, ErrorCode::kerImageWriteFailed);
if ((sv & 1) == 1) {
ioWrapper.putb(0x0); // Align value to word boundary
sv += 1;
@ -1178,7 +1179,8 @@ namespace Exiv2::Internal {
switch(tiffType) {
case ttUnsignedShort:
case ttSignedShort:
if (static_cast<uint32_t>(offset) > 0xffff) throw Error(kerOffsetOutOfRange);
if (static_cast<uint32_t>(offset) > 0xffff)
throw Error(ErrorCode::kerOffsetOutOfRange);
rc = s2Data(buf, static_cast<int16_t>(offset), byteOrder);
break;
case ttUnsignedLong:
@ -1186,7 +1188,7 @@ namespace Exiv2::Internal {
rc = l2Data(buf, static_cast<uint32_t>(offset), byteOrder);
break;
default:
throw Error(kerUnsupportedDataAreaOffsetType);
throw Error(ErrorCode::kerUnsupportedDataAreaOffsetType);
break;
}
return rc;
@ -1529,7 +1531,7 @@ namespace Exiv2::Internal {
ByteOrder /*byteOrder*/) const
{
if ( !pValue() )
throw Error(kerImageWriteFailed); // #1296
throw Error(ErrorCode::kerImageWriteFailed); // #1296
size_t len = pValue()->sizeDataArea();
if (len > 0) {

@ -26,7 +26,7 @@
in crwimage.* :
+ Fix CiffHeader according to TiffHeader
+ Combine Error(kerNotAJpeg) and Error(kerNotACrwImage), add format argument %1
+ Combine Error(ErrorCode::kerNotAJpeg) and Error(kerNotACrwImage), add format argument %1
+ Search crwimage for todos, fix writeMetadata comment
+ rename loadStack to getPath for consistency
@ -136,7 +136,7 @@ namespace Exiv2 {
void TiffImage::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "TIFF"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "TIFF"));
}
void TiffImage::readMetadata()
@ -145,15 +145,15 @@ namespace Exiv2 {
std::cerr << "Reading TIFF file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isTiffType(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "TIFF");
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "TIFF");
}
clearMetadata();
@ -167,7 +167,7 @@ namespace Exiv2 {
if ( pos != exifData_.end() ) {
size_t size = pos->count() * pos->typeSize();
if (size == 0) {
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
}
iccProfile_.alloc(size);
pos->copy(iccProfile_.data(),bo);
@ -302,13 +302,13 @@ namespace Exiv2 {
void TiffImage::printStructure(std::ostream& out, Exiv2::PrintStructureOption option,int depth)
{
if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError());
if (io_->open() != 0) throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
// Ensure that this is the correct image type
if (imageType() == ImageType::none) {
if (!isTiffType(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAJpeg);
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
}

@ -2140,7 +2140,7 @@ namespace Exiv2::Internal {
if (!pData || size == 0)
return nullptr;
if (!pHeader->read(pData, size) || pHeader->offset() >= size) {
throw Error(kerNotAnImage, "TIFF");
throw Error(ErrorCode::kerNotAnImage, "TIFF");
}
auto rootDir = TiffCreator::create(root, ifdIdNotSet);
if (rootDir) {

@ -1507,7 +1507,7 @@ namespace Exiv2::Internal {
p += 4;
if (count > std::numeric_limits<uint32_t>::max() / typeSize) {
throw Error(kerArithmeticOverflow);
throw Error(ErrorCode::kerArithmeticOverflow);
}
auto size = static_cast<uint32_t>(typeSize * count);
uint32_t offset = getLong(p, byteOrder());
@ -1549,10 +1549,10 @@ namespace Exiv2::Internal {
if ((static_cast<uintptr_t>(baseOffset()) > std::numeric_limits<uintptr_t>::max() - static_cast<uintptr_t>(offset))
|| (static_cast<uintptr_t>(baseOffset() + offset) > std::numeric_limits<uintptr_t>::max() - reinterpret_cast<uintptr_t>(pData_)))
{
throw Error(kerCorruptedMetadata); // #562 don't throw kerArithmeticOverflow
throw Error(ErrorCode::kerCorruptedMetadata); // #562 don't throw kerArithmeticOverflow
}
if (pData_ + static_cast<uintptr_t>(baseOffset()) + static_cast<uintptr_t>(offset) > pLast_) {
throw Error(kerCorruptedMetadata);
throw Error(ErrorCode::kerCorruptedMetadata);
}
pData = const_cast<byte*>(pData_) + baseOffset() + offset;
@ -1576,7 +1576,7 @@ namespace Exiv2::Internal {
}
}
auto v = Value::create(typeId);
enforce(v != nullptr, kerCorruptedMetadata);
enforce(v != nullptr, ErrorCode::kerCorruptedMetadata);
v->read(pData, size, byteOrder());
object->setValue(std::move(v));
@ -1676,7 +1676,7 @@ namespace Exiv2::Internal {
if (bo == invalidByteOrder) bo = byteOrder();
TypeId typeId = toTypeId(object->elDef()->tiffType_, object->tag(), object->group());
auto v = Value::create(typeId);
enforce(v != nullptr, kerCorruptedMetadata);
enforce(v != nullptr, ErrorCode::kerCorruptedMetadata);
v->read(pData, size, bo);
object->setValue(std::move(v));

@ -417,7 +417,7 @@ namespace Exiv2 {
charsetId = CharsetInfo::charsetIdByName(name);
if (charsetId == invalidCharsetId) {
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << Error(kerInvalidCharset, name) << "\n";
EXV_WARNING << Error(ErrorCode::kerInvalidCharset, name) << "\n";
#endif
return 1;
}
@ -626,7 +626,7 @@ namespace Exiv2 {
setXmpStruct();
}
else {
throw Error(kerInvalidXmpText, type);
throw Error(ErrorCode::kerInvalidXmpText, type);
}
}
value_ = b;
@ -782,26 +782,26 @@ namespace Exiv2 {
} else {
lang = buf.substr(5, pos-5);
}
if (lang.empty()) throw Error(kerInvalidLangAltValue, buf);
if (lang.empty()) throw Error(ErrorCode::kerInvalidLangAltValue, buf);
// Strip quotes (so you can also specify the language without quotes)
if (lang[0] == '"') {
lang = lang.substr(1);
if (lang.empty() || lang.find('"') != lang.length() - 1)
throw Error(kerInvalidLangAltValue, buf);
throw Error(ErrorCode::kerInvalidLangAltValue, buf);
lang = lang.substr(0, lang.length()-1);
}
if (lang.empty())
throw Error(kerInvalidLangAltValue, buf);
throw Error(ErrorCode::kerInvalidLangAltValue, buf);
// Check language is in the correct format (see https://www.ietf.org/rfc/rfc3066.txt)
std::string::size_type charPos = lang.find_first_not_of(ALPHA);
if (charPos != std::string::npos) {
static const char* ALPHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
if (lang.at(charPos) != '-' || lang.find_first_not_of(ALPHA_NUM, charPos+1) != std::string::npos)
throw Error(kerInvalidLangAltValue, buf);
throw Error(ErrorCode::kerInvalidLangAltValue, buf);
}
b.clear();
@ -920,7 +920,7 @@ namespace Exiv2 {
auto printWarning = [](){
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n";
EXV_WARNING << Error(ErrorCode::kerUnsupportedDateFormat) << "\n";
#endif
};
@ -1090,7 +1090,7 @@ namespace Exiv2 {
return 0;
}
#ifndef SUPPRESS_WARNINGS
EXV_WARNING << Error(kerUnsupportedTimeFormat) << "\n";
EXV_WARNING << Error(ErrorCode::kerUnsupportedTimeFormat) << "\n";
#endif
return 1;
}
@ -1115,7 +1115,7 @@ namespace Exiv2 {
time_.hour, time_.minute, time_.second,
plusMinus, abs(time_.tzHour), abs(time_.tzMinute));
enforce(wrote == 11, Exiv2::kerUnsupportedTimeFormat);
enforce(wrote == 11, Exiv2::ErrorCode::kerUnsupportedTimeFormat);
std::memcpy(buf, temp, wrote);
return wrote;
}

@ -110,13 +110,13 @@ namespace Exiv2 {
{
// not supported
// just quietly ignore the request
// throw(Error(kerInvalidSettingForImage, "IPTC metadata", "WebP"));
// throw(Error(ErrorCode::kerInvalidSettingForImage, "IPTC metadata", "WebP"));
}
void WebPImage::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "WebP"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "WebP"));
}
/* =========================================== */
@ -124,7 +124,7 @@ namespace Exiv2 {
void WebPImage::writeMetadata()
{
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
auto tempIo = std::make_unique<MemIo>();
@ -137,8 +137,8 @@ namespace Exiv2 {
void WebPImage::doWriteMetadata(BasicIo& outIo)
{
if (!io_->isopen()) throw Error(kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(kerImageWriteFailed);
if (!io_->isopen()) throw Error(ErrorCode::kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(ErrorCode::kerImageWriteFailed);
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Writing metadata" << std::endl;
@ -148,12 +148,12 @@ namespace Exiv2 {
DataBuf chunkId(WEBP_TAG_SIZE+1);
chunkId.write_uint8(WEBP_TAG_SIZE, '\0');
io_->readOrThrow(data, WEBP_TAG_SIZE * 3, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(data, WEBP_TAG_SIZE * 3, Exiv2::ErrorCode::kerCorruptedMetadata);
uint64_t filesize = Exiv2::getULong(data + WEBP_TAG_SIZE, littleEndian);
/* Set up header */
if (outIo.write(data, WEBP_TAG_SIZE * 3) != WEBP_TAG_SIZE * 3)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
/* Parse Chunks */
bool has_size = false;
@ -188,19 +188,19 @@ namespace Exiv2 {
case we have any exif or xmp data, also check
for any chunks with alpha frame/layer set */
while (!io_->eof() && static_cast<uint64_t>(io_->tell()) < filesize) {
io_->readOrThrow(chunkId.data(), WEBP_TAG_SIZE, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(size_buff, WEBP_TAG_SIZE, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(chunkId.data(), WEBP_TAG_SIZE, Exiv2::ErrorCode::kerCorruptedMetadata);
io_->readOrThrow(size_buff, WEBP_TAG_SIZE, Exiv2::ErrorCode::kerCorruptedMetadata);
const uint32_t size_u32 = Exiv2::getULong(size_buff, littleEndian);
// Check that `size_u32` is safe to cast to `long`.
enforce(size_u32 <= static_cast<size_t>(std::numeric_limits<unsigned int>::max()),
Exiv2::kerCorruptedMetadata);
Exiv2::ErrorCode::kerCorruptedMetadata);
const auto size = static_cast<long>(size_u32);
DataBuf payload(size);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::kerCorruptedMetadata);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
if ( payload.size() % 2 ) {
byte c = 0;
io_->readOrThrow(&c, 1, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(&c, 1, Exiv2::ErrorCode::kerCorruptedMetadata);
}
/* Chunk with information about features
@ -209,7 +209,7 @@ namespace Exiv2 {
has_vp8x = true;
}
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8X) && !has_size) {
enforce(size >= 10, Exiv2::kerCorruptedMetadata);
enforce(size >= 10, Exiv2::ErrorCode::kerCorruptedMetadata);
has_size = true;
byte size_buf[WEBP_TAG_SIZE];
@ -238,7 +238,7 @@ namespace Exiv2 {
}
#endif
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8) && !has_size) {
enforce(size >= 10, Exiv2::kerCorruptedMetadata);
enforce(size >= 10, Exiv2::ErrorCode::kerCorruptedMetadata);
has_size = true;
byte size_buf[2];
@ -256,13 +256,13 @@ namespace Exiv2 {
/* Chunk with lossless image data. */
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8L) && !has_alpha) {
enforce(size >= 5, Exiv2::kerCorruptedMetadata);
enforce(size >= 5, Exiv2::ErrorCode::kerCorruptedMetadata);
if ((payload.read_uint8(4) & WEBP_VP8X_ALPHA_BIT) == WEBP_VP8X_ALPHA_BIT) {
has_alpha = true;
}
}
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8L) && !has_size) {
enforce(size >= 5, Exiv2::kerCorruptedMetadata);
enforce(size >= 5, Exiv2::ErrorCode::kerCorruptedMetadata);
has_size = true;
byte size_buf_w[2];
byte size_buf_h[3];
@ -290,13 +290,13 @@ namespace Exiv2 {
/* Chunk with animation frame. */
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_ANMF) && !has_alpha) {
enforce(size >= 6, Exiv2::kerCorruptedMetadata);
enforce(size >= 6, Exiv2::ErrorCode::kerCorruptedMetadata);
if ((payload.read_uint8(5) & 0x2) == 0x2) {
has_alpha = true;
}
}
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_ANMF) && !has_size) {
enforce(size >= 12, Exiv2::kerCorruptedMetadata);
enforce(size >= 12, Exiv2::ErrorCode::kerCorruptedMetadata);
has_size = true;
byte size_buf[WEBP_TAG_SIZE];
@ -325,22 +325,22 @@ namespace Exiv2 {
io_->seek(12, BasicIo::beg);
while (!io_->eof() && static_cast<uint64_t>(io_->tell()) < filesize) {
io_->readOrThrow(chunkId.data(), 4, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(size_buff, 4, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(chunkId.data(), 4, Exiv2::ErrorCode::kerCorruptedMetadata);
io_->readOrThrow(size_buff, 4, Exiv2::ErrorCode::kerCorruptedMetadata);
const uint32_t size_u32 = Exiv2::getULong(size_buff, littleEndian);
// Check that `size_u32` is safe to cast to `long`.
enforce(size_u32 <= static_cast<size_t>(std::numeric_limits<unsigned int>::max()),
Exiv2::kerCorruptedMetadata);
Exiv2::ErrorCode::kerCorruptedMetadata);
const auto size = static_cast<long>(size_u32);
DataBuf payload(size);
io_->readOrThrow(payload.data(), size, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(payload.data(), size, Exiv2::ErrorCode::kerCorruptedMetadata);
if ( io_->tell() % 2 ) io_->seek(+1,BasicIo::cur); // skip pad
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8X)) {
enforce(size >= 1, Exiv2::kerCorruptedMetadata);
enforce(size >= 1, Exiv2::ErrorCode::kerCorruptedMetadata);
if (has_icc){
const uint8_t x = payload.read_uint8(0);
payload.write_uint8(0, x | WEBP_VP8X_ICC_BIT);
@ -366,24 +366,24 @@ namespace Exiv2 {
}
if (outIo.write(chunkId.c_data(), WEBP_TAG_SIZE) != WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(size_buff, WEBP_TAG_SIZE) != WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(payload.c_data(), payload.size()) != payload.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.tell() % 2) {
if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed);
if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(ErrorCode::kerImageWriteFailed);
}
if (has_icc) {
if (outIo.write(reinterpret_cast<const byte*>(WEBP_CHUNK_HEADER_ICCP), WEBP_TAG_SIZE) !=
WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
ul2Data(data, static_cast<uint32_t>(iccProfile_.size()), littleEndian);
if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(iccProfile_.c_data(), iccProfile_.size()) != iccProfile_.size()) {
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
has_icc = false;
}
@ -395,43 +395,43 @@ namespace Exiv2 {
// Skip and add new data afterwards
} else {
if (outIo.write(chunkId.c_data(), WEBP_TAG_SIZE) != WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(size_buff, WEBP_TAG_SIZE) != WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(payload.c_data(), payload.size()) != payload.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
// Encoder required to pad odd sized data with a null byte
if (outIo.tell() % 2) {
if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed);
if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(ErrorCode::kerImageWriteFailed);
}
}
if (has_exif) {
if (outIo.write(reinterpret_cast<const byte*>(WEBP_CHUNK_HEADER_EXIF), WEBP_TAG_SIZE) != WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
us2Data(data, static_cast<uint16_t>(blob.size()) + 8, bigEndian);
ul2Data(data, static_cast<uint32_t>(blob.size()), littleEndian);
if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed);
if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(&blob[0], blob.size()) != blob.size()) {
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
if (outIo.tell() % 2) {
if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed);
if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(ErrorCode::kerImageWriteFailed);
}
}
if (has_xmp) {
if (outIo.write(reinterpret_cast<const byte*>(WEBP_CHUNK_HEADER_XMP), WEBP_TAG_SIZE) != WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
ul2Data(data, static_cast<uint32_t>(xmpPacket().size()), littleEndian);
if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed);
if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.write(reinterpret_cast<const byte*>(xmp.data()), xmp.size()) != xmp.size()) {
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
}
if (outIo.tell() % 2) {
if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed);
if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(ErrorCode::kerImageWriteFailed);
}
}
@ -440,7 +440,7 @@ namespace Exiv2 {
filesize = outIo.size() - 8;
outIo.seek(4, BasicIo::beg);
ul2Data(data, static_cast<uint32_t>(filesize), littleEndian);
if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed);
if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(ErrorCode::kerImageWriteFailed);
} // WebPImage::writeMetadata
@ -449,12 +449,12 @@ namespace Exiv2 {
void WebPImage::printStructure(std::ostream& out, PrintStructureOption option,int depth)
{
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
// Ensure this is the correct image type
if (!isWebPType(*io_, true)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "WEBP");
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "WEBP");
}
bool bPrint = option==kpsBasic || option==kpsRecursive;
@ -515,12 +515,12 @@ namespace Exiv2 {
void WebPImage::readMetadata()
{
if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError());
if (io_->open() != 0) throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isWebPType(*io_, true)) {
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
throw Error(kerNotAJpeg);
if (io_->error() || io_->eof()) throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAJpeg);
}
clearMetadata();
@ -528,13 +528,13 @@ namespace Exiv2 {
DataBuf chunkId(5);
chunkId.write_uint8(4, '\0');
io_->readOrThrow(data, WEBP_TAG_SIZE * 3, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(data, WEBP_TAG_SIZE * 3, Exiv2::ErrorCode::kerCorruptedMetadata);
const uint32_t filesize_u32 = Safe::add(Exiv2::getULong(data + WEBP_TAG_SIZE, littleEndian), 8U);
enforce(filesize_u32 <= io_->size(), Exiv2::kerCorruptedMetadata);
enforce(filesize_u32 <= io_->size(), Exiv2::ErrorCode::kerCorruptedMetadata);
// Check that `filesize_u32` is safe to cast to `long`.
enforce(filesize_u32 <= static_cast<uint32_t>(std::numeric_limits<long>::max()), Exiv2::kerCorruptedMetadata);
enforce(filesize_u32 <= static_cast<uint32_t>(std::numeric_limits<long>::max()), Exiv2::ErrorCode::kerCorruptedMetadata);
WebPImage::decodeChunks(static_cast<long>(filesize_u32));
@ -552,28 +552,28 @@ namespace Exiv2 {
chunkId.write_uint8(4, '\0');
while (!io_->eof() && io_->tell() < filesize) {
io_->readOrThrow(chunkId.data(), WEBP_TAG_SIZE, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(size_buff, WEBP_TAG_SIZE, Exiv2::kerCorruptedMetadata);
io_->readOrThrow(chunkId.data(), WEBP_TAG_SIZE, Exiv2::ErrorCode::kerCorruptedMetadata);
io_->readOrThrow(size_buff, WEBP_TAG_SIZE, Exiv2::ErrorCode::kerCorruptedMetadata);
const uint32_t size_u32 = Exiv2::getULong(size_buff, littleEndian);
// Check that `size_u32` is safe to cast to `long`.
enforce(size_u32 <= static_cast<uint32_t>(std::numeric_limits<long>::max()), Exiv2::kerCorruptedMetadata);
enforce(size_u32 <= static_cast<uint32_t>(std::numeric_limits<long>::max()), Exiv2::ErrorCode::kerCorruptedMetadata);
const auto size = static_cast<long>(size_u32);
// Check that `size` is within bounds.
enforce(io_->tell() <= filesize, Exiv2::kerCorruptedMetadata);
enforce(size <= (filesize - io_->tell()), Exiv2::kerCorruptedMetadata);
enforce(io_->tell() <= filesize, Exiv2::ErrorCode::kerCorruptedMetadata);
enforce(size <= (filesize - io_->tell()), Exiv2::ErrorCode::kerCorruptedMetadata);
DataBuf payload(size);
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8X) && !has_canvas_data) {
enforce(size >= 10, Exiv2::kerCorruptedMetadata);
enforce(size >= 10, Exiv2::ErrorCode::kerCorruptedMetadata);
has_canvas_data = true;
byte size_buf[WEBP_TAG_SIZE];
io_->readOrThrow(payload.data(), payload.size(), Exiv2::kerCorruptedMetadata);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
// Fetch width
memcpy(&size_buf, payload.c_data(4), 3);
@ -585,10 +585,10 @@ namespace Exiv2 {
size_buf[3] = 0;
pixelHeight_ = Exiv2::getULong(size_buf, littleEndian) + 1;
} else if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8) && !has_canvas_data) {
enforce(size >= 10, Exiv2::kerCorruptedMetadata);
enforce(size >= 10, Exiv2::ErrorCode::kerCorruptedMetadata);
has_canvas_data = true;
io_->readOrThrow(payload.data(), payload.size(), Exiv2::kerCorruptedMetadata);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
byte size_buf[WEBP_TAG_SIZE];
// Fetch width""
@ -603,13 +603,13 @@ namespace Exiv2 {
size_buf[3] = 0;
pixelHeight_ = Exiv2::getULong(size_buf, littleEndian) & 0x3fff;
} else if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8L) && !has_canvas_data) {
enforce(size >= 5, Exiv2::kerCorruptedMetadata);
enforce(size >= 5, Exiv2::ErrorCode::kerCorruptedMetadata);
has_canvas_data = true;
byte size_buf_w[2];
byte size_buf_h[3];
io_->readOrThrow(payload.data(), payload.size(), Exiv2::kerCorruptedMetadata);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
// Fetch width
memcpy(&size_buf_w, payload.c_data(1), 2);
@ -622,12 +622,12 @@ namespace Exiv2 {
size_buf_h[1] = ((size_buf_h[1] >> 6) & 0x3) | ((size_buf_h[2] & 0xF) << 0x2);
pixelHeight_ = Exiv2::getUShort(size_buf_h, littleEndian) + 1;
} else if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_ANMF) && !has_canvas_data) {
enforce(size >= 12, Exiv2::kerCorruptedMetadata);
enforce(size >= 12, Exiv2::ErrorCode::kerCorruptedMetadata);
has_canvas_data = true;
byte size_buf[WEBP_TAG_SIZE];
io_->readOrThrow(payload.data(), payload.size(), Exiv2::kerCorruptedMetadata);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
// Fetch width
memcpy(&size_buf, payload.c_data(6), 3);
@ -639,10 +639,10 @@ namespace Exiv2 {
size_buf[3] = 0;
pixelHeight_ = Exiv2::getULong(size_buf, littleEndian) + 1;
} else if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_ICCP)) {
io_->readOrThrow(payload.data(), payload.size(), Exiv2::kerCorruptedMetadata);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
this->setIccProfile(std::move(payload));
} else if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_EXIF)) {
io_->readOrThrow(payload.data(), payload.size(), Exiv2::kerCorruptedMetadata);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
byte size_buff2[2];
// 4 meaningful bytes + 2 padding bytes
@ -720,7 +720,7 @@ namespace Exiv2 {
exifData_.clear();
}
} else if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_XMP)) {
io_->readOrThrow(payload.data(), payload.size(), Exiv2::kerCorruptedMetadata);
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
xmpPacket_.assign(payload.c_str(), payload.size());
if (!xmpPacket_.empty() && XmpParser::decode(xmpData_, xmpPacket_)) {
#ifndef SUPPRESS_WARNINGS
@ -763,9 +763,9 @@ namespace Exiv2 {
byte webp[len];
byte data[len];
byte riff[len];
iIo.readOrThrow(riff, len, Exiv2::kerCorruptedMetadata);
iIo.readOrThrow(data, len, Exiv2::kerCorruptedMetadata);
iIo.readOrThrow(webp, len, Exiv2::kerCorruptedMetadata);
iIo.readOrThrow(riff, len, Exiv2::ErrorCode::kerCorruptedMetadata);
iIo.readOrThrow(data, len, Exiv2::ErrorCode::kerCorruptedMetadata);
iIo.readOrThrow(webp, len, Exiv2::ErrorCode::kerCorruptedMetadata);
bool matched_riff = (memcmp(riff, RiffImageId, len) == 0);
bool matched_webp = (memcmp(webp, WebPImageId, len) == 0);
iIo.seek(-12, BasicIo::cur);
@ -839,13 +839,13 @@ namespace Exiv2 {
byte size_buff[WEBP_TAG_SIZE];
ul2Data(size_buff, static_cast<uint32_t>(iccProfile_.size()), littleEndian);
if (iIo.write(reinterpret_cast<const byte*>(WEBP_CHUNK_HEADER_VP8X), WEBP_TAG_SIZE) != WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (iIo.write(size_buff, WEBP_TAG_SIZE) != WEBP_TAG_SIZE)
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (iIo.write(iccProfile_.c_data(), iccProfile_.size()) != iccProfile_.size())
throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (iIo.tell() % 2) {
if (iIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed);
if (iIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(ErrorCode::kerImageWriteFailed);
}
}
}

@ -70,7 +70,7 @@ namespace {
// the (static) check method.
XMLValidator() : parser_(XML_ParserCreateNS(0, '@')) {
if (!parser_) {
throw Error(kerXMPToolkitError, "Could not create expat parser");
throw Error(ErrorCode::kerXMPToolkitError, "Could not create expat parser");
}
}
@ -97,7 +97,7 @@ namespace {
void check_internal(const char* buf, size_t buflen) {
if (buflen > static_cast<size_t>(std::numeric_limits<int>::max())) {
throw Error(kerXMPToolkitError, "Buffer length is greater than INT_MAX");
throw Error(ErrorCode::kerXMPToolkitError, "Buffer length is greater than INT_MAX");
}
XML_SetUserData(parser_, this);
@ -369,13 +369,13 @@ namespace Exiv2 {
const Value& Xmpdatum::value() const
{
if (!p_->value_)
throw Error(kerValueNotSet);
throw Error(ErrorCode::kerValueNotSet);
return *p_->value_;
}
long Xmpdatum::copy(byte* /*buf*/, ByteOrder /*byteOrder*/) const
{
throw Error(kerFunctionNotSupported, "Xmpdatum::copy");
throw Error(ErrorCode::kerFunctionNotSupported, "Xmpdatum::copy");
return 0;
}
@ -634,7 +634,7 @@ namespace Exiv2 {
SXMPMeta::DumpNamespaces(nsDumper,&dict);
if (bInit) terminate();
} catch (const XMP_Error& e) {
throw Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg());
throw Error(ErrorCode::kerXMPToolkitError, e.GetID(), e.GetErrMsg());
}
}
#else
@ -667,7 +667,7 @@ namespace Exiv2 {
#endif
}
catch (const XMP_Error& /* e */) {
// throw Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg());
// throw Error(ErrorCode::kerXMPToolkitError, e.GetID(), e.GetErrMsg());
}
} // XmpParser::registerNs
#else
@ -686,7 +686,7 @@ namespace Exiv2 {
// SXMPMeta::DeleteNamespace(ns.c_str());
}
catch (const XMP_Error& e) {
throw Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg());
throw Error(ErrorCode::kerXMPToolkitError, e.GetID(), e.GetErrMsg());
}
#endif
} // XmpParser::unregisterNs
@ -718,7 +718,7 @@ namespace Exiv2 {
while (iter.Next(&schemaNs, &propPath, &propValue, &opt)) {
printNode(schemaNs, propPath, propValue, opt);
if (XMP_PropIsAlias(opt)) {
throw Error(kerAliasesNotSupported, schemaNs, propPath, propValue);
throw Error(ErrorCode::kerAliasesNotSupported, schemaNs, propPath, propValue);
continue;
}
if (XMP_NodeIsSchema(opt)) {
@ -727,7 +727,7 @@ namespace Exiv2 {
if (XmpProperties::prefix(schemaNs).empty()) {
std::string prefix;
bool ret = SXMPMeta::GetNamespacePrefix(schemaNs.c_str(), &prefix);
if (!ret) throw Error(kerSchemaNamespaceNotRegistered, schemaNs);
if (!ret) throw Error(ErrorCode::kerSchemaNamespaceNotRegistered, schemaNs);
prefix = prefix.substr(0, prefix.size() - 1);
XmpProperties::registerNs(schemaNs, prefix);
}
@ -745,7 +745,7 @@ namespace Exiv2 {
if ( !haveNext
|| !XMP_PropIsSimple(opt)
|| !XMP_PropHasLang(opt)) {
throw Error(kerDecodeLangAltPropertyFailed, propPath, opt);
throw Error(ErrorCode::kerDecodeLangAltPropertyFailed, propPath, opt);
}
const std::string text = propValue;
// Get the language qualifier
@ -755,7 +755,7 @@ namespace Exiv2 {
|| !XMP_PropIsSimple(opt)
|| !XMP_PropIsQualifier(opt)
|| propPath.substr(propPath.size() - 8, 8) != "xml:lang") {
throw Error(kerDecodeLangAltQualifierFailed, propPath, opt);
throw Error(ErrorCode::kerDecodeLangAltQualifierFailed, propPath, opt);
}
val->value_[propValue] = text;
}
@ -809,14 +809,14 @@ namespace Exiv2 {
continue;
}
// Don't let any node go by unnoticed
throw Error(kerUnhandledXmpNode, key->key(), opt);
throw Error(ErrorCode::kerUnhandledXmpNode, key->key(), opt);
} // iterate through all XMP nodes
return 0;
}
#ifndef SUPPRESS_WARNINGS
catch (const XMP_Error& e) {
EXV_ERROR << Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg()) << "\n";
EXV_ERROR << Error(ErrorCode::kerXMPToolkitError, e.GetID(), e.GetErrMsg()) << "\n";
xmpData.clear();
return 3;
}
@ -874,7 +874,7 @@ namespace Exiv2 {
// Encode Lang Alt property
const auto la = dynamic_cast<const LangAltValue*>(&i.value());
if (!la)
throw Error(kerEncodeLangAltPropertyFailed, i.key());
throw Error(ErrorCode::kerEncodeLangAltPropertyFailed, i.key());
int idx = 1;
for (auto&& k : la->value_) {
@ -892,7 +892,7 @@ namespace Exiv2 {
// Todo: Xmpdatum should have an XmpValue, not a Value
const auto val = dynamic_cast<const XmpValue*>(&i.value());
if (!val)
throw Error(kerInvalidKeyXmpValue, i.key(), i.typeName());
throw Error(ErrorCode::kerInvalidKeyXmpValue, i.key(), i.typeName());
options = xmpArrayOptionBits(val->xmpArrayType())
| xmpArrayOptionBits(val->xmpStruct());
if (i.typeId() == xmpBag || i.typeId() == xmpSeq || i.typeId() == xmpAlt) {
@ -916,7 +916,7 @@ namespace Exiv2 {
continue;
}
// Don't let any Xmpdatum go by unnoticed
throw Error(kerUnhandledXmpdatum, i.tagName(), i.typeName());
throw Error(ErrorCode::kerUnhandledXmpdatum, i.tagName(), i.typeName());
}
std::string tmpPacket;
meta.SerializeToBuffer(&tmpPacket, xmpFormatOptionBits(static_cast<XmpFormatFlags>(formatFlags)), padding); // throws
@ -926,7 +926,7 @@ namespace Exiv2 {
}
#ifndef SUPPRESS_WARNINGS
catch (const XMP_Error& e) {
EXV_ERROR << Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg()) << "\n";
EXV_ERROR << Error(ErrorCode::kerXMPToolkitError, e.GetID(), e.GetErrMsg()) << "\n";
return 3;
}
#else
@ -1084,13 +1084,13 @@ namespace {
std::string property;
std::string::size_type idx = propPath.find(':');
if (idx == std::string::npos) {
throw Exiv2::Error(Exiv2::kerPropertyNameIdentificationFailed, propPath, schemaNs);
throw Exiv2::Error(Exiv2::ErrorCode::kerPropertyNameIdentificationFailed, propPath, schemaNs);
}
// Don't worry about out_of_range, XMP parser takes care of this
property = propPath.substr(idx + 1);
std::string prefix = Exiv2::XmpProperties::prefix(schemaNs);
if (prefix.empty()) {
throw Exiv2::Error(Exiv2::kerNoPrefixForNamespace, propPath, schemaNs);
throw Exiv2::Error(Exiv2::ErrorCode::kerNoPrefixForNamespace, propPath, schemaNs);
}
return std::make_unique<Exiv2::XmpKey>(prefix, property);
} // makeXmpKey

@ -40,7 +40,7 @@ namespace Exiv2 {
void XmpSidecar::setComment(std::string_view /*comment*/)
{
// not supported
throw(Error(kerInvalidSettingForImage, "Image comment", "XMP"));
throw(Error(ErrorCode::kerInvalidSettingForImage, "Image comment", "XMP"));
}
void XmpSidecar::readMetadata()
@ -49,14 +49,14 @@ namespace Exiv2 {
std::cerr << "Reading XMP file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
// Ensure that this is the correct image type
if (!isXmpType(*io_, false)) {
if (io_->error() || io_->eof())
throw Error(kerFailedToReadImageData);
throw Error(kerNotAnImage, "XMP");
throw Error(ErrorCode::kerFailedToReadImageData);
throw Error(ErrorCode::kerNotAnImage, "XMP");
}
// Read the XMP packet from the IO stream
std::string xmpPacket;
@ -67,7 +67,7 @@ namespace Exiv2 {
xmpPacket.append(reinterpret_cast<char*>(buf), l);
}
if (io_->error())
throw Error(kerFailedToReadImageData);
throw Error(ErrorCode::kerFailedToReadImageData);
clearMetadata();
xmpPacket_ = xmpPacket;
if (!xmpPacket_.empty() && XmpParser::decode(xmpData_, xmpPacket_)) {
@ -106,7 +106,7 @@ namespace Exiv2 {
void XmpSidecar::writeMetadata()
{
if (io_->open() != 0) {
throw Error(kerDataSourceOpenFailed, io_->path(), strError());
throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError());
}
IoCloser closer(*io_);
@ -157,8 +157,8 @@ namespace Exiv2 {
// Write XMP packet
if (tempIo->write(reinterpret_cast<const byte*>(xmpPacket_.data()), xmpPacket_.size()) != xmpPacket_.size())
throw Error(kerImageWriteFailed);
if (tempIo->error()) throw Error(kerImageWriteFailed);
throw Error(ErrorCode::kerImageWriteFailed);
if (tempIo->error()) throw Error(ErrorCode::kerImageWriteFailed);
io_->close();
io_->transfer(*tempIo); // may throw
}

@ -13,7 +13,7 @@ TEST(IptcKey, creationWithNonValidStringFormatThrows)
IptcKey key("Yeah");
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInvalidKey, e.code());
ASSERT_EQ(ErrorCode::kerInvalidKey, e.code());
ASSERT_STREQ("Invalid key 'Yeah'", e.what());
}
}
@ -24,7 +24,7 @@ TEST(IptcKey, creationWithNonValidRecordNameThrows)
IptcKey key("Iptc.WrongRecordName.ModelVersion");
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInvalidRecord, e.code());
ASSERT_EQ(ErrorCode::kerInvalidRecord, e.code());
ASSERT_STREQ("Invalid record name 'WrongRecordName'", e.what());
}
}
@ -35,7 +35,7 @@ TEST(IptcKey, creationWithNonValidDatasetNameThrows)
IptcKey key("Iptc.Envelope.WrongDataset");
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInvalidDataset, e.code());
ASSERT_EQ(ErrorCode::kerInvalidDataset, e.code());
ASSERT_STREQ("Invalid dataset name 'WrongDataset'", e.what());
}
}
@ -46,7 +46,7 @@ TEST(IptcKey, creationWithNonValidFamiltyNameThrows)
IptcKey key("JOJO.Envelope.WrongDataset");
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInvalidKey, e.code());
ASSERT_EQ(ErrorCode::kerInvalidKey, e.code());
ASSERT_STREQ("Invalid key 'JOJO.Envelope.WrongDataset'", e.what());
}
}

@ -20,7 +20,7 @@ TEST(LangAltValueReadTest, noLanguageValBeforeSpace)
xmpData["Xmp.dc.title"] = "lang= test1-1";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -37,7 +37,7 @@ TEST(LangAltValueReadTest, quoteThenNoLanguageValBeforeSpace)
xmpData["Xmp.dc.title"] = "lang=\" test1-2";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -55,7 +55,7 @@ TEST(LangAltValueReadTest, emptyDoubleQuotesLanguageValBeforeSpace)
xmpData["Xmp.dc.title"] = "lang=\"\" test2";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -73,7 +73,7 @@ TEST(LangAltValueReadTest, emptyDoubleQuotesLanguageValNoSpace)
xmpData["Xmp.dc.title"] = "lang=\"\"test3-1";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -90,7 +90,7 @@ TEST(LangAltValueReadTest, oneDoubleQuotesLanguageValNoSpace)
xmpData["Xmp.dc.title"] = "lang=\"test3-2";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -107,7 +107,7 @@ TEST(LangAltValueReadTest, oneDoubleQuotesLanguageValBeforeSpace)
xmpData["Xmp.dc.title"] = "lang=\"en-UK test3-3";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -124,7 +124,7 @@ TEST(LangAltValueReadTest, languageValOneDoubleQuotesBeforeSpace)
xmpData["Xmp.dc.title"] = "lang=en-US\" test3-4";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -141,7 +141,7 @@ TEST(LangAltValueReadTest, languageValOneDoubleQuotesNoSpace)
xmpData["Xmp.dc.title"] = "lang=test3-5\"";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -158,7 +158,7 @@ TEST(LangAltValueReadTest, languageValTwoDoubleQuotesNoSpace)
xmpData["Xmp.dc.title"] = "lang=test3-6\"\"";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -176,7 +176,7 @@ TEST(LangAltValueReadTest, languageValExtraHyphenBeforeSpace)
xmpData["Xmp.dc.title"] = "lang=en-UK- test4-1";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);
@ -193,7 +193,7 @@ TEST(LangAltValueReadTest, languageValWithInvalidCharBeforeSpace)
xmpData["Xmp.dc.title"] = "lang=en=UK test4-2";
}
catch (AnyError& e) {
ASSERT_EQ(e.code(),Exiv2::kerInvalidLangAltValue);
ASSERT_EQ(e.code(),Exiv2::ErrorCode::kerInvalidLangAltValue);
}
catch (...) {
ASSERT_TRUE(false);

@ -30,7 +30,7 @@ TEST(BmpImage, writeMetadataIsNotImplemented)
bmp.writeMetadata();
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerWritingImageFormatUnsupported, e.code());
ASSERT_EQ(ErrorCode::kerWritingImageFormatUnsupported, e.code());
ASSERT_STREQ("Writing to BMP images is not supported", e.what());
}
}
@ -45,7 +45,7 @@ TEST(BmpImage, setExitDataIsNotImplemented)
bmp.setExifData(data);
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInvalidSettingForImage, e.code());
ASSERT_EQ(ErrorCode::kerInvalidSettingForImage, e.code());
ASSERT_STREQ("Setting Exif metadata in BMP images is not supported", e.what());
}
}
@ -60,7 +60,7 @@ TEST(BmpImage, setIptcDataIsNotImplemented)
bmp.setIptcData(data);
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInvalidSettingForImage, e.code());
ASSERT_EQ(ErrorCode::kerInvalidSettingForImage, e.code());
ASSERT_STREQ("Setting IPTC metadata in BMP images is not supported", e.what());
}
}
@ -74,7 +74,7 @@ TEST(BmpImage, setCommentIsNotImplemented)
bmp.setComment("random comment");
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInvalidSettingForImage, e.code());
ASSERT_EQ(ErrorCode::kerInvalidSettingForImage, e.code());
ASSERT_STREQ("Setting Image comment in BMP images is not supported", e.what());
}
}
@ -118,7 +118,7 @@ TEST(BmpImage, readMetadataThrowsWhenImageIsNotBMP)
bmp.readMetadata();
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerNotAnImage, e.code());
ASSERT_EQ(ErrorCode::kerNotAnImage, e.code());
ASSERT_STREQ("This does not look like a BMP image", e.what());
}
}
@ -132,7 +132,7 @@ TEST(BmpImage, readMetadataThrowsWhenThereIsNotEnoughInfoToRead)
bmp.readMetadata();
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerFailedToReadImageData, e.code());
ASSERT_EQ(ErrorCode::kerFailedToReadImageData, e.code());
ASSERT_STREQ("Failed to read image data", e.what());
}
}
@ -146,7 +146,7 @@ TEST(BmpImage, readMetadataThrowsWhenIoCannotBeOpened)
bmp.readMetadata();
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerDataSourceOpenFailed, e.code());
ASSERT_EQ(ErrorCode::kerDataSourceOpenFailed, e.code());
}
}

@ -148,7 +148,7 @@ TEST(IptcDataSets, dataSet_throwWithNonExistingDatasetName)
IptcDataSets::dataSet("NonExistingName", IptcDataSets::envelope);
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInvalidDataset, e.code());
ASSERT_EQ(ErrorCode::kerInvalidDataset, e.code());
ASSERT_STREQ("Invalid dataset name 'NonExistingName'", e.what());
}
}
@ -160,7 +160,7 @@ TEST(IptcDataSets, dataSet_throwWithNonExistingRecordId)
IptcDataSets::dataSet("ModelVersion", 5);
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInvalidDataset, e.code());
ASSERT_EQ(ErrorCode::kerInvalidDataset, e.code());
ASSERT_STREQ("Invalid dataset name 'ModelVersion'", e.what());
}
}

@ -10,7 +10,7 @@
TEST(enforce, errMessage)
{
try {
enforce(false, Exiv2::kerErrorMessage, "an error occurred");
enforce(false, Exiv2::ErrorCode::kerErrorMessage, "an error occurred");
} catch (const Exiv2::Error& e) {
ASSERT_STREQ(e.what(), "an error occurred");
}
@ -18,12 +18,12 @@ TEST(enforce, errMessage)
TEST(enforce, exceptionThrown)
{
ASSERT_NO_THROW(enforce(true, Exiv2::kerErrorMessage));
ASSERT_NO_THROW(enforce(true, Exiv2::ErrorCode::kerErrorMessage));
ASSERT_THROW(enforce(false, Exiv2::kerErrorMessage), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::ErrorCode::kerErrorMessage), Exiv2::Error);
ASSERT_THROW(enforce<std::overflow_error>(false, "error message"), std::overflow_error);
ASSERT_THROW(enforce(false, Exiv2::kerMallocFailed), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::kerErrorMessage, "error message"), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::kerDataSourceOpenFailed, "path", "strerror"), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::kerCallFailed, "path", "strerror", "function"), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::ErrorCode::kerMallocFailed), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::ErrorCode::kerErrorMessage, "error message"), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::ErrorCode::kerDataSourceOpenFailed, "path", "strerror"), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::ErrorCode::kerCallFailed, "path", "strerror", "function"), Exiv2::Error);
}

@ -108,7 +108,7 @@ TEST(PngImage, cannotReadMetadataFromEmptyIo)
png.readMetadata();
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerNotAnImage, e.code());
ASSERT_EQ(ErrorCode::kerNotAnImage, e.code());
ASSERT_STREQ("This does not look like a PNG image", e.what());
}
}
@ -123,7 +123,7 @@ TEST(PngImage, cannotReadMetadataFromIoWhichCannotBeOpened)
png.readMetadata();
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerDataSourceOpenFailed, e.code());
ASSERT_EQ(ErrorCode::kerDataSourceOpenFailed, e.code());
}
}
@ -137,7 +137,7 @@ TEST(PngImage, cannotWriteMetadataToEmptyIo)
png.writeMetadata();
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerNoImageInInputData, e.code());
ASSERT_EQ(ErrorCode::kerNoImageInInputData, e.code());
}
}
@ -159,7 +159,7 @@ TEST(PngImage, cannotWriteMetadataToIoWhichCannotBeOpened)
png.readMetadata();
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerDataSourceOpenFailed, e.code());
ASSERT_EQ(ErrorCode::kerDataSourceOpenFailed, e.code());
}
}
@ -200,6 +200,6 @@ TEST(isPngType, withMemIoInErroneousStatusThrows)
isPngType(memIo, false);
FAIL();
} catch (const Exiv2::Error& e) {
ASSERT_EQ(kerInputDataReadFailed, e.code());
ASSERT_EQ(ErrorCode::kerInputDataReadFailed, e.code());
}
}

Loading…
Cancel
Save