From 2dd8958d9f56aa3d447fb85f11f55a4762274ac5 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 7 Sep 2016 20:13:46 -0500 Subject: [PATCH] Suppress some compiler false positive warnings that come up in Visual C++ --- src/ox/fs/filestore.hpp | 4 ++-- src/ox/fs/filesystem.hpp | 20 +++++++++++++------- src/ox/fs/oxfstool.cpp | 14 ++++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/ox/fs/filestore.hpp b/src/ox/fs/filestore.hpp index c10ee45fb..904e82240 100644 --- a/src/ox/fs/filestore.hpp +++ b/src/ox/fs/filestore.hpp @@ -37,7 +37,7 @@ class FileStore { FsSize_t size(); void setId(InodeId_t); - void setData(void *data, int size); + void setData(void *data, FsSize_t size); void *data(); private: @@ -203,7 +203,7 @@ void FileStore::Inode::setId(InodeId_t id) { } template -void FileStore::Inode::setData(void *data, int size) { +void FileStore::Inode::setData(void *data, FsSize_t size) { ox::std::memcpy(this->data(), data, size); dataLen = size; } diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index 7b72489cf..285f88a75 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -127,50 +127,56 @@ FileStat FileSystemTemplate::stat(const char *path) { return stat; } +#pragma warning(disable:4244) template FileStat FileSystemTemplate::stat(ox::std::uint64_t inode) { FileStat stat; - auto s = store->stat(inode); + auto s = store->stat((FileStore::FsSize_t) inode); stat.size = s.size; stat.inode = s.inodeId; stat.fileType = s.fileType; return stat; } +#pragma warning(disable:4244) template int FileSystemTemplate::read(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size) { auto err = 1; - auto s = store->stat(inode); + auto s = store->stat((FileStore::FsSize_t) inode); if (size == s.size) { - err = store->read(inode, buffer, nullptr); + err = store->read((FileStore::FsSize_t) inode, buffer, nullptr); } return err; } +#pragma warning(disable:4244) template ox::std::uint8_t *FileSystemTemplate::read(ox::std::uint64_t inode, ox::std::uint64_t *size) { - auto s = store->stat(inode); + auto s = store->stat((FileStore::FsSize_t) inode); auto buff = new ox::std::uint8_t[s.size]; if (size) { *size = s.size; } - if (store->read(inode, buff, nullptr)) { + if (store->read((FileStore::FsSize_t) inode, buff, nullptr)) { delete []buff; buff = nullptr; } return buff; } +#pragma warning(disable:4244) template int FileSystemTemplate::remove(ox::std::uint64_t inode) { - return store->remove(inode); + return store->remove((FileStore::FsSize_t) inode); } +#pragma warning(disable:4244) template int FileSystemTemplate::write(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size, ox::std::uint8_t fileType) { - return store->write(inode, buffer, size, fileType); + return store->write((FileStore::FsSize_t) inode, buffer, (FileStore::FsSize_t) size, fileType); } +#pragma warning(disable:4244) template ox::std::uint8_t *FileSystemTemplate::format(void *buffer, typename FileStore::FsSize_t size, bool useDirectories) { buffer = FileStore::format((ox::std::uint8_t*) buffer, size, FS_TYPE); diff --git a/src/ox/fs/oxfstool.cpp b/src/ox/fs/oxfstool.cpp index 20e99aaf3..5b7c45fd8 100644 --- a/src/ox/fs/oxfstool.cpp +++ b/src/ox/fs/oxfstool.cpp @@ -40,10 +40,10 @@ char *loadFileBuff(const char *path, ::size_t *sizeOut = nullptr) { } ox::std::uint64_t bytes(const char *str) { - const auto size = ::strlen(str); + auto size = ::strlen(str); const auto lastChar = str[size-1]; auto multiplier = 1; - char copy[size]; + auto copy = new char[size]; memcpy(copy, str, size); if (lastChar < '0' || lastChar > '9') { copy[size-1] = 0; @@ -64,7 +64,9 @@ ox::std::uint64_t bytes(const char *str) { multiplier = -1; } } - return ((ox::std::uint64_t) ::atoi(copy)) * multiplier; + const auto retval = ((ox::std::uint64_t) ::atoi(copy)) * multiplier; + delete copy; + return retval; } int format(int argc, char **args) { @@ -81,17 +83,17 @@ int format(int argc, char **args) { if (size < sizeof(FileStore64)) { err = 1; - fprintf(stderr, "File system size %llu too small, must be at least %lu\n", size, sizeof(FileStore64)); + fprintf(stderr, "File system size %llu too small, must be at least %llu\n", (ox::std::uint64_t) size, (ox::std::uint64_t) sizeof(FileStore64)); } if (!err) { // format switch (type) { case 16: - FileStore16::format(buff, size, ox::fs::OxFS_16); + FileStore16::format(buff, (FileStore16::FsSize_t) size, ox::fs::OxFS_16); break; case 32: - FileStore32::format(buff, size, ox::fs::OxFS_32); + FileStore32::format(buff, (FileStore32::FsSize_t) size, ox::fs::OxFS_32); break; case 64: FileStore64::format(buff, size, ox::fs::OxFS_64);