From 6f2f9ce331179091c6d5c75d78cdf3f67255ded1 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 9 Mar 2018 09:40:59 +0100 Subject: Autogen: Fix for the empty source file crash in 3.10.2 Issue: #17793 --- Source/cmQtAutoGenerators.cxx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index a9c9b9d..f91ebb2 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -80,15 +80,21 @@ static bool ReadFile(std::string& content, std::string const& filename, std::size_t const length = cmSystemTools::FileLength(filename); cmsys::ifstream ifs(filename.c_str(), (std::ios::in | std::ios::binary)); if (ifs) { - content.resize(length); - ifs.read(&content.front(), content.size()); - if (ifs) { - success = true; + if (length > 0) { + content.resize(length); + ifs.read(&content.front(), content.size()); + if (ifs) { + success = true; + } else { + content.clear(); + if (error != nullptr) { + error->append("Reading from the file failed."); + } + } } else { + // Readable but empty file content.clear(); - if (error != nullptr) { - error->append("Reading from the file failed."); - } + success = true; } } else if (error != nullptr) { error->append("Opening the file for reading failed."); -- cgit v0.12