From bfa07cba692ae9de6b392241674d8af5d21a1eaa Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Wed, 22 Jul 2015 13:47:19 +0200 Subject: [PATCH] Use the new assert that doesn't crash the program in a release build --- src/CryDevice.cpp | 2 +- src/CryFile.cpp | 2 +- src/impl/DirBlob.cpp | 6 +++--- src/impl/DirBlob.h | 2 +- src/impl/FileBlob.cpp | 1 - src/impl/SymlinkBlob.cpp | 3 +-- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/CryDevice.cpp b/src/CryDevice.cpp index c701958e..24842940 100644 --- a/src/CryDevice.cpp +++ b/src/CryDevice.cpp @@ -67,7 +67,7 @@ CryDevice::~CryDevice() { } optional> CryDevice::Load(const bf::path &path) { - assert(path.is_absolute()); + ASSERT(path.is_absolute(), "Non absolute path given"); if (path.parent_path().empty()) { //We are asked to load the root directory '/'. diff --git a/src/CryFile.cpp b/src/CryFile.cpp index 48516065..4f45864f 100644 --- a/src/CryFile.cpp +++ b/src/CryFile.cpp @@ -27,7 +27,7 @@ CryFile::~CryFile() { unique_ref CryFile::open(int flags) const { auto blob = LoadBlob(); - assert(blob != none); + ASSERT(blob != none, "Couldn't load blob"); return make_unique_ref(make_unique_ref(std::move(*blob))); } diff --git a/src/impl/DirBlob.cpp b/src/impl/DirBlob.cpp index 3ec5590d..744e460d 100644 --- a/src/impl/DirBlob.cpp +++ b/src/impl/DirBlob.cpp @@ -28,7 +28,7 @@ namespace cryfs { DirBlob::DirBlob(unique_ref blob, CryDevice *device) : _device(device), _blob(std::move(blob)), _entries(), _changed(false) { //TODO generally everywhere: asserts are bad, because they crash the filesystem. Rather return a fuse error! - assert(magicNumber() == MagicNumbers::DIR); + ASSERT(magicNumber() == MagicNumbers::DIR, "Loaded blob is not a directory"); _readEntriesFromBlob(); } @@ -224,7 +224,7 @@ void DirBlob::statChild(const Key &key, struct ::stat *result) const { result->st_size = SymlinkBlob(std::move(*blob)).target().native().size(); } } else { - assert(false); + ASSERT(false, "Unknown child type"); } //TODO Move ceilDivision to general utils which can be used by cryfs as well result->st_blocks = blobstore::onblocks::utils::ceilDivision(result->st_size, 512); @@ -233,7 +233,7 @@ void DirBlob::statChild(const Key &key, struct ::stat *result) const { void DirBlob::chmodChild(const Key &key, mode_t mode) { auto found = _findChild(key); - assert ((S_ISREG(mode) && S_ISREG(found->mode)) || (S_ISDIR(mode) && S_ISDIR(found->mode)) || (S_ISLNK(mode))); + ASSERT ((S_ISREG(mode) && S_ISREG(found->mode)) || (S_ISDIR(mode) && S_ISDIR(found->mode)) || (S_ISLNK(mode)), "Unknown mode in entry"); found->mode = mode; _changed = true; } diff --git a/src/impl/DirBlob.h b/src/impl/DirBlob.h index 474d4d0a..5d2a0f08 100644 --- a/src/impl/DirBlob.h +++ b/src/impl/DirBlob.h @@ -28,7 +28,7 @@ public: mode |= S_IFLNK; break; } - assert((S_ISREG(mode) && type == fspp::Dir::EntryType::FILE) || (S_ISDIR(mode) && type == fspp::Dir::EntryType::DIR) || (S_ISLNK(mode) && type == fspp::Dir::EntryType::SYMLINK)); + ASSERT((S_ISREG(mode) && type == fspp::Dir::EntryType::FILE) || (S_ISDIR(mode) && type == fspp::Dir::EntryType::DIR) || (S_ISLNK(mode) && type == fspp::Dir::EntryType::SYMLINK), "Unknown mode in entry"); } fspp::Dir::EntryType type; diff --git a/src/impl/FileBlob.cpp b/src/impl/FileBlob.cpp index f173ad4c..b9d1e1d0 100644 --- a/src/impl/FileBlob.cpp +++ b/src/impl/FileBlob.cpp @@ -18,7 +18,6 @@ FileBlob::~FileBlob() { } unique_ref FileBlob::InitializeEmptyFile(unique_ref blob) { - assert(blob.get() != nullptr); blob->resize(1); unsigned char magicNumber = MagicNumbers::FILE; blob->write(&magicNumber, 0, 1); diff --git a/src/impl/SymlinkBlob.cpp b/src/impl/SymlinkBlob.cpp index 131c2e3a..b1853d27 100644 --- a/src/impl/SymlinkBlob.cpp +++ b/src/impl/SymlinkBlob.cpp @@ -24,7 +24,6 @@ SymlinkBlob::~SymlinkBlob() { } unique_ref SymlinkBlob::InitializeSymlink(unique_ref blob, const bf::path &target) { - assert(blob.get() != nullptr); string targetStr = target.native(); blob->resize(1 + targetStr.size()); unsigned char magicNumber = MagicNumbers::SYMLINK; @@ -36,7 +35,7 @@ unique_ref SymlinkBlob::InitializeSymlink(unique_ref blob, co void SymlinkBlob::_checkMagicNumber(const Blob &blob) { unsigned char value; blob.read(&value, 0, 1); - assert(value == MagicNumbers::SYMLINK); + ASSERT(value == MagicNumbers::SYMLINK, "Blob is not a symlink blob"); } bf::path SymlinkBlob::_readTargetFromBlob(const blobstore::Blob &blob) {