Skip to content

Commit b9b2d77

Browse files
Fix some "unsafe vector access" warnings.
1 parent 118731d commit b9b2d77

File tree

4 files changed

+19
-35
lines changed

4 files changed

+19
-35
lines changed

src/image.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ constexpr auto registry = std::array{
9999
#ifdef EXV_ENABLE_BMFF
100100
Registry{ImageType::bmff, newBmffInstance, isBmffType, amRead, amRead, amRead, amNone},
101101
#endif // EXV_ENABLE_BMFF
102-
// End of list marker
103-
Registry{ImageType::none, nullptr, nullptr, amNone, amNone, amNone, amNone},
104102
};
105103

106104
std::string pathOfFileUrl(const std::string& url) {
@@ -751,9 +749,9 @@ ImageType ImageFactory::getType(BasicIo& io) {
751749
if (io.open() != 0)
752750
return ImageType::none;
753751
IoCloser closer(io);
754-
for (unsigned int i = 0; registry[i].imageType_ != ImageType::none; ++i) {
755-
if (registry[i].isThisType_(io, false)) {
756-
return registry[i].imageType_;
752+
for (const auto& r : registry) {
753+
if (r.isThisType_(io, false)) {
754+
return r.imageType_;
757755
}
758756
}
759757
return ImageType::none;
@@ -798,9 +796,9 @@ Image::UniquePtr ImageFactory::open(BasicIo::UniquePtr io) {
798796
if (io->open() != 0) {
799797
throw Error(ErrorCode::kerDataSourceOpenFailed, io->path(), strError());
800798
}
801-
for (unsigned int i = 0; registry[i].imageType_ != ImageType::none; ++i) {
802-
if (registry[i].isThisType_(*io, false)) {
803-
return registry[i].newInstance_(std::move(io), false);
799+
for (const auto& r : registry) {
800+
if (r.isThisType_(*io, false)) {
801+
return r.newInstance_(std::move(io), false);
804802
}
805803
}
806804
return nullptr;

src/nikonmn_int.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,13 @@ std::ostream& Nikon1MakerNote::print0x0088(std::ostream& os, const Value& value,
237237
os << "; ";
238238
const uint32_t focusPoint = value.toUint32(1);
239239

240-
switch (focusPoint) {
241-
// Could use array nikonFocuspoints
242-
case 0:
243-
case 1:
244-
case 2:
245-
case 3:
246-
case 4:
247-
os << nikonFocuspoints[focusPoint];
248-
break;
249-
default:
250-
os << value;
251-
if (focusPoint < nikonFocuspoints.size())
252-
os << " " << _("guess") << " " << nikonFocuspoints[focusPoint];
253-
break;
240+
if (focusPoint <= 4) {
241+
os << nikonFocuspoints[focusPoint];
242+
} else {
243+
os << value;
244+
if (focusPoint < nikonFocuspoints.size()) {
245+
os << " " << _("guess") << " " << nikonFocuspoints[focusPoint];
246+
}
254247
}
255248
}
256249
if (value.count() >= 3) {

src/pngimage.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ static bool tEXtToDataBuf(const byte* bytes, size_t length, DataBuf& result) {
127127
static bool bFirst = true;
128128
if (bFirst) {
129129
value.fill(0);
130-
const char* hexdigits = "0123456789ABCDEF";
131-
for (int i = 0; i < 16; i++) {
132-
value[tolower(hexdigits[i])] = i + 1;
133-
value[toupper(hexdigits[i])] = i + 1;
130+
for (int i = 0; i < 10; i++) {
131+
value['0' + i] = i + 1;
132+
}
133+
for (int i = 0; i < 6; i++) {
134+
value['a' + i] = i + 10 + 1;
135+
value['A' + i] = i + 10 + 1;
134136
}
135137
bFirst = false;
136138
}

unitTests/test_ImageFactory.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,4 @@ TEST(TheImageFactory, getsExpectedModesForXmpImages) {
353353
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::xmp, mdIccProfile));
354354
}
355355

356-
TEST(TheImageFactory, getsExpectedModesForNoneValue) {
357-
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdNone));
358-
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdExif));
359-
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdIptc));
360-
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdXmp));
361-
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdComment));
362-
EXPECT_EQ(amNone, ImageFactory::checkMode(ImageType::none, mdIccProfile));
363-
}
364-
365356
/// \todo check why JpegBase is taking ImageType in the constructor

0 commit comments

Comments
 (0)