summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2018-03-09 09:40:59 +0100
committerBrad King <brad.king@kitware.com>2018-03-09 06:51:14 -0500
commit6f2f9ce331179091c6d5c75d78cdf3f67255ded1 (patch)
tree7e8b7f2c0744029949facaaa6336e0b075f6ab01
parentc1e087a9d3af74299d7681c9f9de59e5977a1539 (diff)
downloadcmake-6f2f9ce331179091c6d5c75d78cdf3f67255ded1.tar.gz
Autogen: Fix for the empty source file crash in 3.10.2
Issue: #17793
-rw-r--r--Source/cmQtAutoGenerators.cxx20
1 files changed, 13 insertions, 7 deletions
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index a9c9b9d361..f91ebb23e1 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.");