From 2205a14a069c64c58bb33949a26bea1c5d1a3de4 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 21 Feb 2023 14:54:32 -0800 Subject: [PATCH] clang-tidy: default init various members Found with cppcoreguidelines-pro-type-member-init Signed-off-by: Rosen Penev --- app/exiv2.cpp | 6 +----- include/exiv2/image.hpp | 8 ++++---- include/exiv2/preview.hpp | 8 ++++---- src/datasets.cpp | 2 +- unitTests/test_DateValue.cpp | 13 +++---------- unitTests/test_basicio.cpp | 30 ++++++++++-------------------- 6 files changed, 23 insertions(+), 44 deletions(-) diff --git a/app/exiv2.cpp b/app/exiv2.cpp index c13d80f1..c0855038 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -195,13 +195,9 @@ int main(int argc, char* const argv[]) { Params::Params() : optstring_(":hVvqfbuktTFa:Y:O:D:r:p:P:d:e:i:c:m:M:l:S:g:K:n:Q:"), - target_(ctExif | ctIptc | ctComment | ctXmp), - + yodAdjust_(emptyYodAdjust_), format_("%Y%m%d_%H%M%S") { - yodAdjust_[yodYear] = emptyYodAdjust_[yodYear]; - yodAdjust_[yodMonth] = emptyYodAdjust_[yodMonth]; - yodAdjust_[yodDay] = emptyYodAdjust_[yodDay]; } Params& Params::instance() { diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp index 8a62aa25..66f14870 100644 --- a/include/exiv2/image.hpp +++ b/include/exiv2/image.hpp @@ -21,10 +21,10 @@ namespace Exiv2 { //! Native preview information. This is meant to be used only by the PreviewManager. struct NativePreview { - size_t position_; //!< Position - size_t size_; //!< Size - size_t width_; //!< Width - size_t height_; //!< Height + size_t position_{}; //!< Position + size_t size_{}; //!< Size + size_t width_{}; //!< Width + size_t height_{}; //!< Height std::string filter_; //!< Filter std::string mimeType_; //!< MIME type }; diff --git a/include/exiv2/preview.hpp b/include/exiv2/preview.hpp index 06456407..295c35b5 100644 --- a/include/exiv2/preview.hpp +++ b/include/exiv2/preview.hpp @@ -23,10 +23,10 @@ using PreviewId = int; struct EXIV2API PreviewProperties { std::string mimeType_; //!< Preview image mime type. std::string extension_; //!< Preview image extension. - size_t size_; //!< Preview image size in bytes. - size_t width_; //!< Preview image width in pixels or 0 for unknown width. - size_t height_; //!< Preview image height in pixels or 0 for unknown height. - PreviewId id_; //!< Identifies type of preview image. + size_t size_{}; //!< Preview image size in bytes. + size_t width_{}; //!< Preview image width in pixels or 0 for unknown width. + size_t height_{}; //!< Preview image height in pixels or 0 for unknown height. + PreviewId id_{}; //!< Identifies type of preview image. }; //! Container type to hold all preview images metadata. diff --git a/src/datasets.cpp b/src/datasets.cpp index 5965437d..39cb2ea5 100644 --- a/src/datasets.cpp +++ b/src/datasets.cpp @@ -500,7 +500,7 @@ void IptcDataSets::dataSetList(std::ostream& os) { } } -IptcKey::IptcKey(std::string key) : key_(std::move(key)) { +IptcKey::IptcKey(std::string key) : tag_(0), record_(0), key_(std::move(key)) { decomposeKey(); } diff --git a/unitTests/test_DateValue.cpp b/unitTests/test_DateValue.cpp index b56af551..d813973f 100644 --- a/unitTests/test_DateValue.cpp +++ b/unitTests/test_DateValue.cpp @@ -34,10 +34,7 @@ TEST(ADateValue, canBeConstructedWithInvalidDate) { TEST(ADateValue, setsValidDateCorrectly) { DateValue dateValue; - DateValue::Date date; - date.year = 2018; - date.month = 4; - date.day = 2; + DateValue::Date date = {2018, 4, 2}; dateValue.setDate(date); ASSERT_EQ(2018, dateValue.getDate().year); @@ -48,10 +45,7 @@ TEST(ADateValue, setsValidDateCorrectly) { /// \todo Probably we should avoid this ... TEST(ADateValue, setsInvalidDateCorrectly) { DateValue dateValue; - DateValue::Date date; - date.year = 2018; - date.month = 13; - date.day = 69; + DateValue::Date date = {2018, 13, 69}; dateValue.setDate(date); ASSERT_EQ(2018, dateValue.getDate().year); @@ -154,8 +148,7 @@ TEST(ADateValue, writesVeryOldDateToExtendedFormat) { TEST(ADateValue, copiesToByteBufferWithBasicFormat) { const DateValue dateValue(2021, 12, 1); - std::array buf; - buf.fill(0); + std::array buf = {}; const byte expectedDate[10] = {'2', '0', '2', '1', '1', '2', '0', '1'}; ASSERT_EQ(8, dateValue.copy(buf.data())); diff --git a/unitTests/test_basicio.cpp b/unitTests/test_basicio.cpp index 92672596..9b8ef10a 100644 --- a/unitTests/test_basicio.cpp +++ b/unitTests/test_basicio.cpp @@ -43,8 +43,7 @@ TEST(MemIo_Default, seekToEndPositionAndReadTriggersEof) { ASSERT_EQ(0, io.seek(0, BasicIo::end)); ASSERT_EQ(0, io.tell()); - std::array buf2; - buf2.fill(0); + std::array buf2 = {}; ASSERT_EQ(0, io.read(buf2.data(), 1)); // Note that we cannot even read 1 byte being at the end ASSERT_TRUE(io.eof()); } @@ -52,16 +51,14 @@ TEST(MemIo_Default, seekToEndPositionAndReadTriggersEof) { // ------------------------- TEST(MemIo, isNotAtEofInitially) { - std::array buf; - buf.fill(0); + std::array buf = {}; MemIo io(buf.data(), buf.size()); ASSERT_FALSE(io.eof()); } TEST(MemIo, seekBeyondBufferSizeReturns1AndSetsEofToTrue) { - std::array buf; - buf.fill(0); + std::array buf = {}; MemIo io(buf.data(), buf.size()); ASSERT_EQ(1, io.seek(65, BasicIo::beg)); @@ -69,8 +66,7 @@ TEST(MemIo, seekBeyondBufferSizeReturns1AndSetsEofToTrue) { } TEST(MemIo, seekBefore0Returns1ButItDoesNotSetEofToTrue) { - std::array buf; - buf.fill(0); + std::array buf = {}; MemIo io(buf.data(), buf.size()); ASSERT_EQ(1, io.seek(-1, BasicIo::beg)); @@ -88,8 +84,7 @@ TEST(MemIo, seekBeyondBoundsDoesNotMoveThePosition) { } TEST(MemIo, seekInsideBoundsMoveThePosition) { - std::array buf; - buf.fill(0); + std::array buf = {}; MemIo io(buf.data(), buf.size()); ASSERT_EQ(0, io.tell()); @@ -98,8 +93,7 @@ TEST(MemIo, seekInsideBoundsMoveThePosition) { } TEST(MemIo, seekInsideBoundsUsingBeg_resetsThePosition) { - std::array buf; - buf.fill(0); + std::array buf = {}; MemIo io(buf.data(), buf.size()); std::vector positions{0, 8, 16, 32, 64}; @@ -110,8 +104,7 @@ TEST(MemIo, seekInsideBoundsUsingBeg_resetsThePosition) { } TEST(MemIo, seekInsideBoundsUsingCur_shiftThePosition) { - std::array buf; - buf.fill(0); + std::array buf = {}; MemIo io(buf.data(), buf.size()); std::vector shifts{4, 4, 8, 16, 32}; @@ -123,8 +116,7 @@ TEST(MemIo, seekInsideBoundsUsingCur_shiftThePosition) { } TEST(MemIo, seekToEndPosition_doesNotTriggerEof) { - std::array buf; - buf.fill(0); + std::array buf = {}; MemIo io(buf.data(), buf.size()); ASSERT_EQ(0, io.tell()); @@ -134,15 +126,13 @@ TEST(MemIo, seekToEndPosition_doesNotTriggerEof) { } TEST(MemIo, seekToEndPositionAndReadTriggersEof) { - std::array buf; - buf.fill(0); + std::array buf = {}; MemIo io(buf.data(), buf.size()); ASSERT_EQ(0, io.seek(0, BasicIo::end)); ASSERT_EQ(64, io.tell()); - std::array buf2; - buf2.fill(0); + std::array buf2 = {}; ASSERT_EQ(0, io.read(buf2.data(), 1)); // Note that we cannot even read 1 byte being at the end ASSERT_TRUE(io.eof()); }