Merge pull request #2275 from kevinbackhouse/vector-access

Fix some "unsafe vector access" warnings
main
Kevin Backhouse 3 years ago committed by GitHub
commit 2c31430ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -99,8 +99,6 @@ constexpr auto registry = std::array{
#ifdef EXV_ENABLE_BMFF #ifdef EXV_ENABLE_BMFF
Registry{ImageType::bmff, newBmffInstance, isBmffType, amRead, amRead, amRead, amNone}, Registry{ImageType::bmff, newBmffInstance, isBmffType, amRead, amRead, amRead, amNone},
#endif // EXV_ENABLE_BMFF #endif // EXV_ENABLE_BMFF
// End of list marker
Registry{ImageType::none, nullptr, nullptr, amNone, amNone, amNone, amNone},
}; };
std::string pathOfFileUrl(const std::string& url) { std::string pathOfFileUrl(const std::string& url) {
@ -751,9 +749,9 @@ ImageType ImageFactory::getType(BasicIo& io) {
if (io.open() != 0) if (io.open() != 0)
return ImageType::none; return ImageType::none;
IoCloser closer(io); IoCloser closer(io);
for (unsigned int i = 0; registry[i].imageType_ != ImageType::none; ++i) { for (const auto& r : registry) {
if (registry[i].isThisType_(io, false)) { if (r.isThisType_(io, false)) {
return registry[i].imageType_; return r.imageType_;
} }
} }
return ImageType::none; return ImageType::none;
@ -798,9 +796,9 @@ Image::UniquePtr ImageFactory::open(BasicIo::UniquePtr io) {
if (io->open() != 0) { if (io->open() != 0) {
throw Error(ErrorCode::kerDataSourceOpenFailed, io->path(), strError()); throw Error(ErrorCode::kerDataSourceOpenFailed, io->path(), strError());
} }
for (unsigned int i = 0; registry[i].imageType_ != ImageType::none; ++i) { for (const auto& r : registry) {
if (registry[i].isThisType_(*io, false)) { if (r.isThisType_(*io, false)) {
return registry[i].newInstance_(std::move(io), false); return r.newInstance_(std::move(io), false);
} }
} }
return nullptr; return nullptr;

@ -237,20 +237,13 @@ std::ostream& Nikon1MakerNote::print0x0088(std::ostream& os, const Value& value,
os << "; "; os << "; ";
const uint32_t focusPoint = value.toUint32(1); const uint32_t focusPoint = value.toUint32(1);
switch (focusPoint) { if (focusPoint <= 4) {
// Could use array nikonFocuspoints
case 0:
case 1:
case 2:
case 3:
case 4:
os << nikonFocuspoints[focusPoint]; os << nikonFocuspoints[focusPoint];
break; } else {
default:
os << value; os << value;
if (focusPoint < nikonFocuspoints.size()) if (focusPoint < nikonFocuspoints.size()) {
os << " " << _("guess") << " " << nikonFocuspoints[focusPoint]; os << " " << _("guess") << " " << nikonFocuspoints[focusPoint];
break; }
} }
} }
if (value.count() >= 3) { if (value.count() >= 3) {

@ -127,10 +127,12 @@ static bool tEXtToDataBuf(const byte* bytes, size_t length, DataBuf& result) {
static bool bFirst = true; static bool bFirst = true;
if (bFirst) { if (bFirst) {
value.fill(0); value.fill(0);
const char* hexdigits = "0123456789ABCDEF"; for (int i = 0; i < 10; i++) {
for (int i = 0; i < 16; i++) { value['0' + i] = i + 1;
value[tolower(hexdigits[i])] = i + 1; }
value[toupper(hexdigits[i])] = i + 1; for (int i = 0; i < 6; i++) {
value['a' + i] = i + 10 + 1;
value['A' + i] = i + 10 + 1;
} }
bFirst = false; bFirst = false;
} }

@ -353,13 +353,4 @@ TEST(TheImageFactory, getsExpectedModesForXmpImages) {
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::xmp, mdIccProfile)); EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::xmp, mdIccProfile));
} }
TEST(TheImageFactory, getsExpectedModesForNoneValue) {
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdNone));
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdExif));
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdIptc));
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdXmp));
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdComment));
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdIccProfile));
}
/// \todo check why JpegBase is taking ImageType in the constructor /// \todo check why JpegBase is taking ImageType in the constructor

Loading…
Cancel
Save