MantisBT - CMake
View Issue Details
0015424CMakeCMakepublic2015-02-27 10:382015-11-02 09:13
Paul Martin 
Brad King 
normalcrashalways
closedfixed 
Linux3.19
CMake 3.1.3 
CMake 3.2CMake 3.2 
0015424: Infinite loop in cmsys::SystemTools::CopyFileAlways
With some (recent) C++ libraries, "failbit" is not set on EOF, hence the while loop in cmsys::SystemTools::CopyFileAlways() never exits.
No tags attached.
patch cmake_copyfilealways.patch (887) 2015-02-27 10:38
https://public.kitware.com/Bug/file/5394/cmake_copyfilealways.patch
Issue History
2015-02-27 10:38Paul MartinNew Issue
2015-02-27 10:38Paul MartinFile Added: cmake_copyfilealways.patch
2015-02-27 10:53Brad KingNote Added: 0038094
2015-02-27 10:53Brad KingAssigned To => Brad King
2015-02-27 10:53Brad KingStatusnew => assigned
2015-02-27 10:53Brad KingTarget Version => CMake 3.2
2015-02-27 11:06Paul MartinNote Added: 0038095
2015-02-27 11:14Brad KingNote Added: 0038096
2015-03-02 09:05Brad KingNote Added: 0038134
2015-03-03 08:51Brad KingNote Added: 0038139
2015-03-03 08:52Brad KingStatusassigned => resolved
2015-03-03 08:52Brad KingResolutionopen => fixed
2015-03-03 08:52Brad KingFixed in Version => CMake 3.2
2015-11-02 09:13Robert MaynardNote Added: 0039720
2015-11-02 09:13Robert MaynardStatusresolved => closed

Notes
(0038094)
Brad King   
2015-02-27 10:53   
Thanks. IIUC the failbit should only be set when trying to read past EOF, as in the first attempt to read bytes after the last byte in the file was previously read.

Can you tell me which stream library is at fault here? The existing workaround is for a stream library from the 1990s. One might have thought modern C++ implementors would know how to read to end of file correctly. It seems like a common operation ;)

Anyway, based on your approach I've made a similar change to upstream KWSys here:

 http://review.source.kitware.com/19352 [^]

Please try that out.
(0038095)
Paul Martin   
2015-02-27 11:06   
I really don't think code obfuscation is a move in the right direction here.

Lazy boolean evaluation combined with the comma operator is not a recipe for long term code maintainability.

For reference, the C++ library is from gcc 4.9.2.
(0038096)
Brad King   
2015-02-27 11:14   
Re 0015424:0038095: Okay, I changed it to your exact patch.

Is this a known bug in gcc 4.9.2's stream library that has been addressed, or were we actually doing something non-standard here?
(0038134)
Brad King   
2015-03-02 09:05   
The change has been merged to upstream KWSys. I've now updated KWSys within CMake to get the change:

 KWSys 2015-02-27 (d2aa1afd)
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7c9afb57 [^]
(0038139)
Brad King   
2015-03-03 08:51   
The change has been backported in CMake to the 'release' branch:

 KWSys SystemTools: Update CopyFileAlways stream library workarounds
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b8ea771b [^]
(0039720)
Robert Maynard   
2015-11-02 09:13   
Closing resolved issues that have not been updated in more than 4 months.