From e692908f28f954c71224d70822cf17482387f76d Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Thu, 28 Jan 2021 17:14:21 +1100 Subject: [PATCH] Fix gcc warning. --- CesiumGltfReader/test/TestReader.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/CesiumGltfReader/test/TestReader.cpp b/CesiumGltfReader/test/TestReader.cpp index d99ca4bfa..1aefc6494 100644 --- a/CesiumGltfReader/test/TestReader.cpp +++ b/CesiumGltfReader/test/TestReader.cpp @@ -12,20 +12,26 @@ using namespace CesiumGltf; namespace { std::vector readFile(const std::string& path) { FILE* fp = std::fopen(path.c_str(), "rb"); - if (!fp) { - return {}; - } + REQUIRE(fp); - std::fseek(fp, 0, SEEK_END); - long pos = std::ftell(fp); - std::fseek(fp, 0, SEEK_SET); + try { + std::fseek(fp, 0, SEEK_END); + long pos = std::ftell(fp); + std::fseek(fp, 0, SEEK_SET); - std::vector result(static_cast(pos)); - std::fread(result.data(), 1, result.size(), fp); + std::vector result(static_cast(pos)); + size_t itemsRead = std::fread(result.data(), 1, result.size(), fp); + REQUIRE(itemsRead == result.size()); - std::fclose(fp); + std::fclose(fp); - return result; + return result; + } catch(...) { + if (fp) { + std::fclose(fp); + } + throw; + } } }