MantisBT - CMake
View Issue Details
0015890CMakeCMakepublic2015-12-21 10:432016-05-02 08:30
Fredrik Björkenfors 
Clinton Stimpson 
normalminoralways
closedfixed 
WindowsWindows 7Win7 SP1
CMake 3.4 
CMake 3.5CMake 3.5 
0015890: file(STRINGS ..) doesn't work on single character files.
If the file passed to file(STRINGS <file> VAR) contains a single character file VAR will be empty.
Run CMake on the attached project.

Workaround: Adding any character to the input file, including an EOL character.
If the file has less than 2 characters ReadBOM(std::istream& in) will set the failbit and the attempt to rewind the file will fail.
No tags attached.
zip CMake_bug.zip (413) 2015-12-21 10:43
https://public.kitware.com/Bug/file/5594/CMake_bug.zip
Issue History
2015-12-21 10:43Fredrik BjörkenforsNew Issue
2015-12-21 10:43Fredrik BjörkenforsFile Added: CMake_bug.zip
2015-12-21 10:47Brad KingNote Added: 0040014
2015-12-21 10:52Brad KingNote Added: 0040015
2015-12-21 10:52Brad KingAssigned To => Clinton Stimpson
2015-12-21 10:52Brad KingStatusnew => assigned
2015-12-21 10:52Brad KingTarget Version => CMake 3.5
2015-12-21 11:00Fredrik BjörkenforsNote Added: 0040017
2016-01-01 00:43Clinton StimpsonNote Added: 0040032
2016-01-07 16:07Brad KingNote Added: 0040152
2016-01-07 16:07Brad KingStatusassigned => resolved
2016-01-07 16:07Brad KingResolutionopen => fixed
2016-01-07 16:07Brad KingFixed in Version => CMake 3.5
2016-05-02 08:30Robert MaynardNote Added: 0040995
2016-05-02 08:30Robert MaynardStatusresolved => closed

Notes
(0040014)
Brad King   
2015-12-21 10:47   
Thanks. This was likely introduced as of CMake 3.2 with this change:

 file: Teach STRINGS to support UTF-16 and UTF-32 encodings
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1f77a700 [^]
(0040015)
Brad King   
2015-12-21 10:52   
The bug itself may be in the KWSys FStream::ReadBOM implementation introduced here:

 FStream: Add ability to detect BOM.
 http://public.kitware.com/gitweb?p=KWSys.git;a=commitdiff;h=b3b20cc0 [^]
(0040017)
Fredrik Björkenfors   
2015-12-21 11:00   
Yes, this is were the rewind fails due to in.read setting the failbit. I think seekg clears the eofbit, but not the failbit.
in.read(reinterpret_cast<char*>(bom), 2);
+ if(!in.good())
+ {
+ in.seekg(orig);
+ return BOM_None;
+ }
(0040032)
Clinton Stimpson   
2016-01-01 00:43   
Here is a candidate fix.
http://review.source.kitware.com/#/c/20612/ [^]
(0040152)
Brad King   
2016-01-07 16:07   
The KWSys change referenced in 0015890:0040032 has been merged to upstream KWSys. Here is a commit to CMake to update it:

 KWSys 2016-01-07 (2418443e)
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f2b0bf6e [^]
(0040995)
Robert Maynard   
2016-05-02 08:30   
Closing resolved issues that have not been updated in more than 4 months.