From 043547cbd02c8ca59053ee1ea64b307bd9391935 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 27 Mar 2022 01:47:02 -0700 Subject: [PATCH] remove various usages of memset Signed-off-by: Rosen Penev --- app/actions.cpp | 3 +-- samples/exiv2json.cpp | 3 +-- samples/geotag.cpp | 6 ++---- src/crwimage_int.cpp | 3 +-- src/futils.cpp | 6 ++---- src/http.cpp | 6 ++---- src/value.cpp | 3 +-- 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/app/actions.cpp b/app/actions.cpp index 98f6bb9a..599a9534 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -1803,8 +1803,7 @@ int renameFile(std::string& newPath, const struct tm* tm) { replace(format, ":parentname:", p.parent_path().parent_path().filename().string()); const size_t max = 1024; - char basename[max]; - std::memset(basename, 0x0, max); + char basename[max] = {}; if (strftime(basename, max, format.c_str(), tm) == 0) { std::cerr << _("Filename format yields empty filename for the file") << " " << path << "\n"; return 1; diff --git a/samples/exiv2json.cpp b/samples/exiv2json.cpp index 9fa0bb35..cdd5b331 100644 --- a/samples/exiv2json.cpp +++ b/samples/exiv2json.cpp @@ -214,8 +214,7 @@ void fileSystemPush(const char* path, Jzon::Node& nfs) { fs.Add("path", path); fs.Add("realpath", std::filesystem::absolute(std::filesystem::path(path)).string()); - struct stat buf; - memset(&buf, 0, sizeof(buf)); + struct stat buf = {}; stat(path, &buf); fs.Add("st_dev", static_cast(buf.st_dev)); /* ID of device containing file */ diff --git a/samples/geotag.cpp b/samples/geotag.cpp index ea656913..8c8bdae2 100644 --- a/samples/geotag.cpp +++ b/samples/geotag.cpp @@ -366,8 +366,7 @@ time_t parseTime(const char* arg, bool bAdjust) { char a = 0, b = 0, c = 0, d = 0, e = 0; sscanf(arg, "%d%c%d%c%d%c%d%c%d%c%d", &YY, &a, &MM, &b, &DD, &c, &HH, &d, &mm, &e, &SS1); - struct tm T; - memset(&T, 0, sizeof(T)); + struct tm T = {}; T.tm_min = mm; T.tm_hour = HH; T.tm_sec = SS1; @@ -720,8 +719,7 @@ int main(int argc, const char* argv[]) { types[typeCode] = "code"; types[typeFile] = "file"; - char const* keywords[kwMAX]; - memset(keywords, 0, sizeof(keywords)); + char const* keywords[kwMAX] = {}; keywords[kwHELP] = "help"; keywords[kwVERSION] = "version"; keywords[kwVERBOSE] = "verbose"; diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 3ad2e8ac..1774941a 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -949,8 +949,7 @@ void CrwMap::encode0x180e(const Image& image, const CrwMapping* pCrwMapping, Cif const ExifKey key(pCrwMapping->tag_, Internal::groupName(pCrwMapping->ifdId_)); const auto ed = image.exifData().findKey(key); if (ed != image.exifData().end()) { - struct tm tm; - std::memset(&tm, 0x0, sizeof(tm)); + struct tm tm = {}; if (exifTime(ed->toString().c_str(), &tm) == 0) { t = ::mktime(&tm); } diff --git a/src/futils.cpp b/src/futils.cpp index f2114f1e..fd867fcd 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -228,12 +228,10 @@ std::string strError() { const size_t n = 1024; #ifdef EXV_STRERROR_R_CHAR_P char* buf = nullptr; - char buf2[n]; - std::memset(buf2, 0x0, n); + char buf2[n] = {}; buf = strerror_r(error, buf2, n); #else - char buf[n]; - std::memset(buf, 0x0, n); + char buf[n] = {}; const int ret = strerror_r(error, buf, n); enforce(ret != ERANGE, Exiv2::ErrorCode::kerCallFailed); #endif diff --git a/src/http.cpp b/src/http.cpp index 01d307d5..0e32ab3c 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -90,8 +90,7 @@ static int forgive(int n, int& err) { static int error(std::string& errors, const char* msg, const char* x = nullptr, const char* y = nullptr, int z = 0) { static const size_t buffer_size = 512; - char buffer[buffer_size]; - memset(buffer, 0, buffer_size); + char buffer[buffer_size] = {}; snprintf(buffer, buffer_size, msg, x, y, z); if (errno) { perror(buffer); @@ -210,9 +209,8 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st int server = -1; // fill in the address - struct sockaddr_in serv_addr; + struct sockaddr_in serv_addr = {}; int serv_len = sizeof(serv_addr); - memset(reinterpret_cast(&serv_addr), 0, serv_len); serv_addr.sin_addr.s_addr = inet_addr(servername_p); serv_addr.sin_family = AF_INET; diff --git a/src/value.cpp b/src/value.cpp index 7a722ed0..ab1ce47f 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -876,8 +876,7 @@ std::ostream& DateValue::write(std::ostream& os) const { int64_t DateValue::toInt64(size_t /*n*/) const { // Range of tm struct is limited to about 1970 to 2038 // This will return -1 if outside that range - std::tm tms; - std::memset(&tms, 0, sizeof(tms)); + std::tm tms = {}; tms.tm_mday = date_.day; tms.tm_mon = date_.month - 1; tms.tm_year = date_.year - 1900;