From 4fdf5f48eb96c15e1b2bf1c66509ec1246210bae Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 9 Apr 2017 15:55:39 -0500 Subject: [PATCH] Fix big endian reading of Inode size --- src/ox/fs/filestore.hpp | 2 +- src/ox/std/byteswap.hpp | 1 + src/ox/std/test/CMakeLists.txt | 13 ++++++++++++ src/ox/std/test/byteswap_test.cpp | 34 +++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/ox/std/test/byteswap_test.cpp diff --git a/src/ox/fs/filestore.hpp b/src/ox/fs/filestore.hpp index b971c0a4c..aedfbac80 100644 --- a/src/ox/fs/filestore.hpp +++ b/src/ox/fs/filestore.hpp @@ -316,7 +316,7 @@ class FileStore { template typename Header::FsSize_t FileStore
::Inode::size() { - return std::nativizeLittleEndian(sizeof(Inode) + getDataLen()); + return sizeof(Inode) + getDataLen(); } template diff --git a/src/ox/std/byteswap.hpp b/src/ox/std/byteswap.hpp index 7d247e7a4..0628b29c0 100644 --- a/src/ox/std/byteswap.hpp +++ b/src/ox/std/byteswap.hpp @@ -13,6 +13,7 @@ namespace ox { namespace std { + inline uint16_t byteSwap(uint16_t i) { return (i << 8) | (i >> 8); } diff --git a/src/ox/std/test/CMakeLists.txt b/src/ox/std/test/CMakeLists.txt index 3fd5793c5..66d76eea2 100644 --- a/src/ox/std/test/CMakeLists.txt +++ b/src/ox/std/test/CMakeLists.txt @@ -28,3 +28,16 @@ add_test("Test\\ ox_strcmp\\ hijk\\ !=\\ asdf" StrOpsTest "hijk > asdf") add_test("Test\\ ox_strcmp\\ read\\ !=\\ resize" StrOpsTest "read < resize") add_test("Test\\ ox_strcmp\\ resize\\ !=\\ read" StrOpsTest "resize > read") add_test("Test\\ ox_strcmp\\ resize\\ ==\\ resize" StrOpsTest "resize == resize") + + +################################################################################ +# Byte Swap Tests + +add_executable( + ByteSwapTest + byteswap_test.cpp +) + +target_link_libraries(ByteSwapTest OxStd) + +add_test("Test\\ nativizeLittleEndian\\ 40\\ ==\\ 671088640" ByteSwapTest "40") diff --git a/src/ox/std/test/byteswap_test.cpp b/src/ox/std/test/byteswap_test.cpp new file mode 100644 index 000000000..46862e8b7 --- /dev/null +++ b/src/ox/std/test/byteswap_test.cpp @@ -0,0 +1,34 @@ +/* + * Copyright 2015 - 2017 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include +#include +#include +#include + +using namespace std; +using namespace ox::std; + +map> tests = { + { + "40", + []() { + cout << (nativizeLittleEndian((uint32_t) 40)) << endl; + return !(nativizeLittleEndian((uint32_t) 40) == 671088640); + } + }, +}; + +int main(int argc, const char **args) { + if (argc > 1) { + auto testName = args[1]; + if (tests.find(testName) != tests.end()) { + return tests[testName](); + } + } + return -1; +}