diff options
author | Brad King <brad.king@kitware.com> | 2018-03-09 11:51:38 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-03-09 11:59:19 (GMT) |
commit | 760c6c08a5f5ba6390f40a7dddb499bd7f16c702 (patch) | |
tree | 7e8b7f2c0744029949facaaa6336e0b075f6ab01 | |
parent | c1e087a9d3af74299d7681c9f9de59e5977a1539 (diff) | |
parent | 6f2f9ce331179091c6d5c75d78cdf3f67255ded1 (diff) | |
download | CMake-760c6c08a5f5ba6390f40a7dddb499bd7f16c702.zip CMake-760c6c08a5f5ba6390f40a7dddb499bd7f16c702.tar.gz CMake-760c6c08a5f5ba6390f40a7dddb499bd7f16c702.tar.bz2 |
Merge branch 'autogen-empty-source-file-fix' into release-3.10
There is no corresponding merge request because this fix was
cherry-picked specifically for CMake 3.10.
-rw-r--r-- | Source/cmQtAutoGenerators.cxx | 20 |
1 files 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."); |