remove various usages of memset

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 3 years ago
parent 5a47d251f5
commit 043547cbd0

@ -1803,8 +1803,7 @@ int renameFile(std::string& newPath, const struct tm* tm) {
replace(format, ":parentname:", p.parent_path().parent_path().filename().string()); replace(format, ":parentname:", p.parent_path().parent_path().filename().string());
const size_t max = 1024; const size_t max = 1024;
char basename[max]; char basename[max] = {};
std::memset(basename, 0x0, max);
if (strftime(basename, max, format.c_str(), tm) == 0) { if (strftime(basename, max, format.c_str(), tm) == 0) {
std::cerr << _("Filename format yields empty filename for the file") << " " << path << "\n"; std::cerr << _("Filename format yields empty filename for the file") << " " << path << "\n";
return 1; return 1;

@ -214,8 +214,7 @@ void fileSystemPush(const char* path, Jzon::Node& nfs) {
fs.Add("path", path); fs.Add("path", path);
fs.Add("realpath", std::filesystem::absolute(std::filesystem::path(path)).string()); fs.Add("realpath", std::filesystem::absolute(std::filesystem::path(path)).string());
struct stat buf; struct stat buf = {};
memset(&buf, 0, sizeof(buf));
stat(path, &buf); stat(path, &buf);
fs.Add("st_dev", static_cast<int>(buf.st_dev)); /* ID of device containing file */ fs.Add("st_dev", static_cast<int>(buf.st_dev)); /* ID of device containing file */

@ -366,8 +366,7 @@ time_t parseTime(const char* arg, bool bAdjust) {
char a = 0, b = 0, c = 0, d = 0, e = 0; 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); 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; struct tm T = {};
memset(&T, 0, sizeof(T));
T.tm_min = mm; T.tm_min = mm;
T.tm_hour = HH; T.tm_hour = HH;
T.tm_sec = SS1; T.tm_sec = SS1;
@ -720,8 +719,7 @@ int main(int argc, const char* argv[]) {
types[typeCode] = "code"; types[typeCode] = "code";
types[typeFile] = "file"; types[typeFile] = "file";
char const* keywords[kwMAX]; char const* keywords[kwMAX] = {};
memset(keywords, 0, sizeof(keywords));
keywords[kwHELP] = "help"; keywords[kwHELP] = "help";
keywords[kwVERSION] = "version"; keywords[kwVERSION] = "version";
keywords[kwVERBOSE] = "verbose"; keywords[kwVERBOSE] = "verbose";

@ -949,8 +949,7 @@ void CrwMap::encode0x180e(const Image& image, const CrwMapping* pCrwMapping, Cif
const ExifKey key(pCrwMapping->tag_, Internal::groupName(pCrwMapping->ifdId_)); const ExifKey key(pCrwMapping->tag_, Internal::groupName(pCrwMapping->ifdId_));
const auto ed = image.exifData().findKey(key); const auto ed = image.exifData().findKey(key);
if (ed != image.exifData().end()) { if (ed != image.exifData().end()) {
struct tm tm; struct tm tm = {};
std::memset(&tm, 0x0, sizeof(tm));
if (exifTime(ed->toString().c_str(), &tm) == 0) { if (exifTime(ed->toString().c_str(), &tm) == 0) {
t = ::mktime(&tm); t = ::mktime(&tm);
} }

@ -228,12 +228,10 @@ std::string strError() {
const size_t n = 1024; const size_t n = 1024;
#ifdef EXV_STRERROR_R_CHAR_P #ifdef EXV_STRERROR_R_CHAR_P
char* buf = nullptr; char* buf = nullptr;
char buf2[n]; char buf2[n] = {};
std::memset(buf2, 0x0, n);
buf = strerror_r(error, buf2, n); buf = strerror_r(error, buf2, n);
#else #else
char buf[n]; char buf[n] = {};
std::memset(buf, 0x0, n);
const int ret = strerror_r(error, buf, n); const int ret = strerror_r(error, buf, n);
enforce(ret != ERANGE, Exiv2::ErrorCode::kerCallFailed); enforce(ret != ERANGE, Exiv2::ErrorCode::kerCallFailed);
#endif #endif

@ -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 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; static const size_t buffer_size = 512;
char buffer[buffer_size]; char buffer[buffer_size] = {};
memset(buffer, 0, buffer_size);
snprintf(buffer, buffer_size, msg, x, y, z); snprintf(buffer, buffer_size, msg, x, y, z);
if (errno) { if (errno) {
perror(buffer); perror(buffer);
@ -210,9 +209,8 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
int server = -1; int server = -1;
// fill in the address // fill in the address
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr = {};
int serv_len = sizeof(serv_addr); int serv_len = sizeof(serv_addr);
memset(reinterpret_cast<char*>(&serv_addr), 0, serv_len);
serv_addr.sin_addr.s_addr = inet_addr(servername_p); serv_addr.sin_addr.s_addr = inet_addr(servername_p);
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;

@ -876,8 +876,7 @@ std::ostream& DateValue::write(std::ostream& os) const {
int64_t DateValue::toInt64(size_t /*n*/) const { int64_t DateValue::toInt64(size_t /*n*/) const {
// Range of tm struct is limited to about 1970 to 2038 // Range of tm struct is limited to about 1970 to 2038
// This will return -1 if outside that range // This will return -1 if outside that range
std::tm tms; std::tm tms = {};
std::memset(&tms, 0, sizeof(tms));
tms.tm_mday = date_.day; tms.tm_mday = date_.day;
tms.tm_mon = date_.month - 1; tms.tm_mon = date_.month - 1;
tms.tm_year = date_.year - 1900; tms.tm_year = date_.year - 1900;

Loading…
Cancel
Save