Skip to content

Commit

Permalink
Merge pull request #305 from Infomaniak/fix-all-uninitialized-member-…
Browse files Browse the repository at this point in the history
…warnings-detected-by-cppcheck

Fixes all warnings about uninitialized member variables in constructors (cppcheck)
  • Loading branch information
ClementKunz authored Oct 15, 2024
2 parents 41d8e9f + 078b1fa commit 720ebb6
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 76 deletions.
6 changes: 2 additions & 4 deletions src/libcommon/info/driveinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
namespace KDC {

DriveInfo::DriveInfo(int dbId, int accountDbId, const QString &name, const QColor &color) :
_dbId(dbId), _accountDbId(accountDbId), _name(name), _color(color), _maintenance(false), _locked(false),
_accessDenied(false) {}
_dbId(dbId), _accountDbId(accountDbId), _name(name), _color(color) {}

DriveInfo::DriveInfo() :
_dbId(0), _accountDbId(0), _name(QString()), _color(QString()), _maintenance(false), _locked(false), _accessDenied(false) {}
DriveInfo::DriveInfo() : _dbId(0), _accountDbId(0) {}

QDataStream &operator>>(QDataStream &in, DriveInfo &info) {
in >> info._dbId >> info._accountDbId >> info._name >> info._color >> info._notifications >> info._maintenance >>
Expand Down
10 changes: 5 additions & 5 deletions src/libcommon/info/driveinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ class DriveInfo {
int _accountDbId;
QString _name;
QColor _color;
bool _notifications;
bool _admin;
bool _notifications{false};
bool _admin{false};

// Non DB attributes
bool _maintenance;
bool _locked;
bool _accessDenied;
bool _maintenance{false};
bool _locked{false};
bool _accessDenied{false};
};

} // namespace KDC
6 changes: 1 addition & 5 deletions src/libcommon/info/errorinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@

namespace KDC {

ErrorInfo::ErrorInfo() :
_dbId(0), _time(0), _level(ErrorLevel::Unknown), _functionName(QString()), _syncDbId(0), _workerName(QString()),
_exitCode(ExitCode::Unknown), _exitCause(ExitCause::Unknown), _localNodeId(QString()), _remoteNodeId(QString()),
_nodeType(NodeType::Unknown), _path(QString()), _conflictType(ConflictType::None),
_inconsistencyType(InconsistencyType::None), _cancelType(CancelType::None) {}
ErrorInfo::ErrorInfo() {}

ErrorInfo::ErrorInfo(qint64 time, ErrorLevel level, const QString &functionName, int syncDbId, const QString &workerName,
ExitCode exitCode, ExitCause exitCause, const QString &localNodeId, const QString &remoteNodeId,
Expand Down
22 changes: 11 additions & 11 deletions src/libcommon/info/errorinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,23 @@ class ErrorInfo {
friend QDataStream &operator<<(QDataStream &out, const QList<ErrorInfo> &list);

private:
int _dbId;
qint64 _time;
ErrorLevel _level;
int _dbId{0};
qint64 _time{0};
ErrorLevel _level{ErrorLevel::Unknown};
QString _functionName;
int _syncDbId;
int _syncDbId{0};
QString _workerName;
ExitCode _exitCode;
ExitCause _exitCause;
ExitCode _exitCode{ExitCode::Unknown};
ExitCause _exitCause{ExitCause::Unknown};
QString _localNodeId;
QString _remoteNodeId;
NodeType _nodeType;
NodeType _nodeType{NodeType::Unknown};
QString _path;
QString _destinationPath;
ConflictType _conflictType;
InconsistencyType _inconsistencyType;
CancelType _cancelType;
bool _autoResolved;
ConflictType _conflictType{ConflictType::None};
InconsistencyType _inconsistencyType{InconsistencyType::None};
CancelType _cancelType{CancelType::None};
bool _autoResolved{false};
};

} // namespace KDC
2 changes: 1 addition & 1 deletion src/libcommonserver/db/sqlitequery.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SqliteQuery {
log4cplus::Logger _logger;
std::shared_ptr<sqlite3> _sqlite3Db;
std::shared_ptr<sqlite3_stmt> _stmt;
int _errId;
int _errId{-1};
std::string _error;
std::string _sql;

Expand Down
8 changes: 4 additions & 4 deletions src/libcommonserver/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ class Vfs : public QObject {
VfsSetupParams _vfsSetupParams;

// Callbacks
void (*_syncFileStatus)(int syncDbId, const KDC::SyncPath &itemPath, KDC::SyncFileStatus &status);
void (*_syncFileSyncing)(int syncDbId, const KDC::SyncPath &itemPath, bool &syncing);
void (*_setSyncFileSyncing)(int syncDbId, const KDC::SyncPath &itemPath, bool syncing);
void (*_exclusionAppList)(QString &appList);
void (*_syncFileStatus)(int syncDbId, const KDC::SyncPath &itemPath, KDC::SyncFileStatus &status) = nullptr;
void (*_syncFileSyncing)(int syncDbId, const KDC::SyncPath &itemPath, bool &syncing) = nullptr;
void (*_setSyncFileSyncing)(int syncDbId, const KDC::SyncPath &itemPath, bool syncing) = nullptr;
void (*_exclusionAppList)(QString &appList) = nullptr;

inline bool extendedLog() { return _extendedLog; }

Expand Down
2 changes: 1 addition & 1 deletion src/libsyncengine/jobs/network/API_v2/getsizejob.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ class GetSizeJob : public AbstractTokenNetworkJob {
virtual void setData(bool &canceled) override { canceled = false; }

NodeId _nodeId;
int64_t _size;
int64_t _size{0};
};
} // namespace KDC
15 changes: 4 additions & 11 deletions src/libsyncengine/progress/syncfileitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@

#include "syncfileitem.h"

#include <ctime>

namespace KDC {

SyncFileItem::SyncFileItem() :
_type(NodeType::Unknown), _path(SyncPath()), _newPath(std::nullopt), _localNodeId(std::nullopt), _remoteNodeId(std::nullopt),
_direction(SyncDirection::Unknown), _instruction(SyncFileInstruction::None), _status(SyncFileStatus::Unknown),
_conflict(ConflictType::None), _inconsistency(InconsistencyType::None), _size(0), _dehydrated(false), _confirmed(false),
_timestamp(std::time(0)) {}
SyncFileItem::SyncFileItem() {}

SyncFileItem::SyncFileItem(NodeType type, const SyncPath &path, const std::optional<SyncPath> &newPath,
const std::optional<NodeId> &localNodeId, const std::optional<NodeId> &remoteNodeId,
Expand All @@ -35,14 +29,13 @@ SyncFileItem::SyncFileItem(NodeType type, const SyncPath &path, const std::optio
_type(type),
_path(path), _newPath(newPath), _localNodeId(localNodeId), _remoteNodeId(remoteNodeId), _direction(direction),
_instruction(instruction), _status(status), _conflict(conflict), _inconsistency(inconsistency), _cancelType(cancelType),
_size(size), _dehydrated(dehydrated), _confirmed(false), _timestamp(std::time(0)) {}
_size(size), _dehydrated(dehydrated) {}

SyncFileItem::SyncFileItem(NodeType type, const SyncPath &path, const std::optional<NodeId> &localNodeId,
const std::optional<NodeId> &remoteNodeId, SyncDirection direction, SyncFileInstruction instruction,
ConflictType conflict, int64_t size) :
_type(type),
_path(path), _newPath(std::nullopt), _localNodeId(localNodeId), _remoteNodeId(remoteNodeId), _direction(direction),
_instruction(instruction), _status(SyncFileStatus::Unknown), _conflict(conflict), _inconsistency(InconsistencyType::None),
_cancelType(CancelType::None), _size(size), _dehydrated(false), _confirmed(false), _timestamp(std::time(0)) {}
_path(path), _localNodeId(localNodeId), _remoteNodeId(remoteNodeId), _direction(direction), _instruction(instruction),
_conflict(conflict), _size(size) {}

} // namespace KDC
32 changes: 16 additions & 16 deletions src/libsyncengine/progress/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,24 @@ class SyncFileItem {
inline bool isDirectory() const { return _type == NodeType::Directory; }

private:
NodeType _type;
NodeType _type{NodeType::Unknown};
SyncPath _path; // Sync folder relative filesystem path
std::optional<SyncPath> _newPath;
std::optional<NodeId> _localNodeId;
std::optional<NodeId> _remoteNodeId;
SyncDirection _direction;
SyncFileInstruction _instruction;
SyncFileStatus _status;
ConflictType _conflict;
InconsistencyType _inconsistency;
CancelType _cancelType;
std::optional<SyncPath> _newPath{std::nullopt};
std::optional<NodeId> _localNodeId{std::nullopt};
std::optional<NodeId> _remoteNodeId{std::nullopt};
SyncDirection _direction{SyncDirection::Unknown};
SyncFileInstruction _instruction{SyncFileInstruction::None};
SyncFileStatus _status{SyncFileStatus::Unknown};
ConflictType _conflict{ConflictType::None};
InconsistencyType _inconsistency{InconsistencyType::None};
CancelType _cancelType{CancelType::None};
std::string _error;
int64_t _size;
time_t _modTime;
time_t _creationTime;
bool _dehydrated;
bool _confirmed;
SyncTime _timestamp;
int64_t _size{0};
time_t _modTime{0};
time_t _creationTime{0};
bool _dehydrated{false};
bool _confirmed{false};
SyncTime _timestamp{std::time(0)};
};

} // namespace KDC
2 changes: 1 addition & 1 deletion src/libsyncengine/syncpal/syncpal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ bool SyncPal::wipeVirtualFiles() {

bool SyncPal::wipeOldPlaceholders() {
LOG_SYNCPAL_INFO(_logger, "Wiping old placeholders files");
VirtualFilesCleaner virtualFileCleaner(localPath());
VirtualFilesCleaner virtualFileCleaner(localPath(), syncDbId());
std::vector<SyncPath> failedToRemovePlaceholders;
if (!virtualFileCleaner.removeDehydratedPlaceholders(failedToRemovePlaceholders)) {
LOG_SYNCPAL_WARN(_logger, "Error in VirtualFilesCleaner::removeDehydratedPlaceholders");
Expand Down
2 changes: 1 addition & 1 deletion src/libsyncengine/syncpal/syncpal.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct SyncPalInfo {
VirtualFileMode vfsMode{VirtualFileMode::Off};
bool restart{false};
bool isPaused{false};
bool syncHasFullyCompleted;
bool syncHasFullyCompleted{false};

// An advanced synchronisation targets a subdirectory of a remote drive
bool isAdvancedSync() const { return !targetPath.empty(); };
Expand Down
15 changes: 10 additions & 5 deletions src/libsyncengine/syncpal/virtualfilescleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ VirtualFilesCleaner::VirtualFilesCleaner(const SyncPath &path, int syncDbId, std
_rootPath(path), _syncDbId(syncDbId), _syncDb(syncDb), _vfsStatus(vfsStatus),
_vfsClearFileAttributes(vfsClearFileAttributes) {}

VirtualFilesCleaner::VirtualFilesCleaner(const SyncPath &path) : _logger(Log::instance()->getLogger()), _rootPath(path) {}
VirtualFilesCleaner::VirtualFilesCleaner(const SyncPath &path, int syncDbId) :
_logger(Log::instance()->getLogger()), _rootPath(path), _syncDbId(syncDbId) {}

bool VirtualFilesCleaner::run() {
// Clear xattr on root path
assert(_vfsClearFileAttributes);
_vfsClearFileAttributes(_syncDbId, _rootPath);
return removePlaceholdersRecursivly(_rootPath);
return removePlaceholdersRecursively(_rootPath);
}

bool VirtualFilesCleaner::removePlaceholdersRecursivly(const SyncPath &parentPath) {
bool VirtualFilesCleaner::removePlaceholdersRecursively(const SyncPath &parentPath) {
const SyncName rootPathStr = _rootPath.native();
try {
std::filesystem::recursive_directory_iterator dirIt;
Expand Down Expand Up @@ -90,6 +92,7 @@ bool VirtualFilesCleaner::removePlaceholdersRecursivly(const SyncPath &parentPat
bool isHydrated = false;
bool isSyncing = false;
int progress = 0;
assert(_vfsStatus);
if (!_vfsStatus(_syncDbId, dirIt->path(), isPlaceholder, isHydrated, isSyncing, progress)) {
LOGW_WARN(_logger, L"Error in vfsStatus for path=" << Path2WStr(dirIt->path()).c_str());
_exitCode = ExitCode::SystemError;
Expand Down Expand Up @@ -162,13 +165,15 @@ bool VirtualFilesCleaner::removePlaceholdersRecursivly(const SyncPath &parentPat
}

// Clear xattr
assert(_vfsClearFileAttributes);
_vfsClearFileAttributes(_syncDbId, dirIt->path());
}
} catch (std::filesystem::filesystem_error &e) {
LOG_WARN(_logger, "Error caught in VirtualFilesCleaner::removePlaceholdersRecursivly: " << e.code() << " - " << e.what());
LOG_WARN(_logger,
"Error caught in VirtualFilesCleaner::removePlaceholdersRecursively: " << e.code() << " - " << e.what());
return false;
} catch (...) {
LOG_WARN(_logger, "Error caught in VirtualFilesCleaner::removePlaceholdersRecursivly");
LOG_WARN(_logger, "Error caught in VirtualFilesCleaner::removePlaceholdersRecursively");
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions src/libsyncengine/syncpal/virtualfilescleaner.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class VirtualFilesCleaner {
bool (*vfsStatus)(int, const SyncPath &, bool &, bool &, bool &, int &),
bool (*vfsClearFileAttributes)(int, const SyncPath &));

VirtualFilesCleaner(const SyncPath &path);
VirtualFilesCleaner(const SyncPath &path, int syncDbId);

bool run();
bool removeDehydratedPlaceholders(std::vector<SyncPath> &failedToRemovePlaceholders);
Expand All @@ -41,18 +41,18 @@ class VirtualFilesCleaner {
inline ExitCause exitCause() const { return _exitCause; }

private:
bool removePlaceholdersRecursivly(const SyncPath &parentPath);
bool removePlaceholdersRecursively(const SyncPath &parentPath);
bool recursiveDirectoryIterator(const SyncPath &path, std::filesystem::recursive_directory_iterator &dirIt);
bool folderCanBeProcessed(std::filesystem::recursive_directory_iterator &dirIt);

log4cplus::Logger _logger;

SyncPath _rootPath;
int _syncDbId;
int _syncDbId{-1};
std::shared_ptr<SyncDb> _syncDb = nullptr;
bool (*_vfsStatus)(int syncDbId, const SyncPath &itemPath, bool &isPlaceholder, bool &isHydrated, bool &isSyncing,
int &progress);
bool (*_vfsClearFileAttributes)(int syncDbId, const SyncPath &itemPath);
int &progress) = nullptr;
bool (*_vfsClearFileAttributes)(int syncDbId, const SyncPath &itemPath) = nullptr;

ExitCode _exitCode = ExitCode::Unknown;
ExitCause _exitCause = ExitCause::Unknown;
Expand Down
15 changes: 9 additions & 6 deletions src/server/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,13 @@ void SocketApi::fetchPrivateLinkUrlHelper(const QString &localFile, const std::f
}

// Find the syncpal associated to sync
std::unordered_map<int, std::shared_ptr<KDC::SyncPal>>::const_iterator syncPalMapIt;
std::unordered_map<int, std::shared_ptr<KDC::SyncPal>>::const_iterator syncPalMapIt = _syncPalMap.end();
if (sync.dbId()) {
syncPalMapIt = retrieveSyncPalMapIt(sync.dbId());
if (syncPalMapIt == _syncPalMap.end()) return;
}

if (syncPalMapIt == _syncPalMap.end()) return;

FileData fileData = FileData::get(localFile);
KDC::NodeId itemId;
if (syncPalMapIt->second->fileRemoteIdFromLocalPath(QStr2Path(fileData.relativePath), itemId) != KDC::ExitCode::Ok) {
Expand Down Expand Up @@ -928,9 +929,10 @@ void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, const So
auto syncPalMapIt = _syncPalMap.end();
if (fileData.syncDbId) {
syncPalMapIt = retrieveSyncPalMapIt(fileData.syncDbId);
if (syncPalMapIt == _syncPalMap.end()) return;
}

if (syncPalMapIt == _syncPalMap.end()) return;

const bool isOnTheServer = syncPalMapIt->second->existOnServer(QStr2Path(fileData.relativePath));
const bool canShare = syncPalMapIt->second->canShareItem(QStr2Path(fileData.relativePath));

Expand Down Expand Up @@ -973,9 +975,10 @@ void SocketApi::addSharingContextMenuOptions(const FileData &fileData, QTextStre
auto syncPalMapIt = _syncPalMap.end();
if (fileData.syncDbId) {
syncPalMapIt = retrieveSyncPalMapIt(fileData.syncDbId);
if (syncPalMapIt == _syncPalMap.end()) return;
}

if (syncPalMapIt == _syncPalMap.end()) return;

const bool isOnTheServer = syncPalMapIt->second->existOnServer(QStr2Path(fileData.relativePath));
const bool canShare = syncPalMapIt->second->canShareItem(QStr2Path(fileData.relativePath));

Expand Down Expand Up @@ -1027,8 +1030,8 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, SocketListener *
}

// Find SyncPal and Vfs associated to sync
std::unordered_map<int, std::shared_ptr<KDC::SyncPal>>::const_iterator syncPalMapIt;
std::unordered_map<int, std::shared_ptr<KDC::Vfs>>::const_iterator vfsMapIt;
std::unordered_map<int, std::shared_ptr<KDC::SyncPal>>::const_iterator syncPalMapIt = _syncPalMap.end();
std::unordered_map<int, std::shared_ptr<KDC::Vfs>>::const_iterator vfsMapIt = _vfsMap.end();
if (sync.dbId()) {
syncPalMapIt = retrieveSyncPalMapIt(sync.dbId());
if (syncPalMapIt == _syncPalMap.end()) return;
Expand Down

0 comments on commit 720ebb6

Please sign in to comment.