MantisBT - CMake | |||||
View Issue Details | |||||
ID | Project | Category | View Status | Date Submitted | Last Update |
0015735 | CMake | CMake | public | 2015-09-10 06:50 | 2016-02-01 09:10 |
Reporter | Pavel Solodovnikov | ||||
Assigned To | Brad King | ||||
Priority | high | Severity | major | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Platform | OS | OS Version | |||
Product Version | CMake 2.8.11 | ||||
Target Version | CMake 3.4 | Fixed in Version | CMake 3.4 | ||
Summary | 0015735: Non-ascii characters in POST_BUILD commands truncated by CMake (if Ninja generator used) on Linux | ||||
Description | CMake doesn't handle backslash escaped strings properly in POST_BUILD commands added via "add_custom_command" if provided commands end with non-ascii characters. Here is a simple example that represents the issue: I have a trivial CMakeLists.txt with one library target: cmake_minimum_required(VERSION 2.8.11) project(example) add_library(ex abc.cpp) add_custom_command(TARGET ex POST_BUILD COMMAND cmd1 "Пример с пробелами") For example, I want to execute post build command "cmd1" and pass a parameter "Пример с пробелами" that contains russian characters. If Ninja generator is specified, CMake generates ill-formed "build.ninja" file. The point of interest in produced build.ninja file looks like that: build libex.a: CXX_STATIC_LIBRARY_LINKER CMakeFiles/ex.dir/abc.cpp.o POST_BUILD = cd /mnt/sources/work/example && cmd1 Пример\ с\ PRE_LINK = : TARGET_PDB = ex.a.dbg The last word in passed parameter "Пример с пробелами" had been truncated by CMake up to the first encountered space so I can't execute my post build commands properly, since the argument string is corrupted now. After debugging CMake a little, I've discovered that the source of this error is in function "cmSystemTools::TrimWhitespace" (cmSystemTools.cxx), which doesn't take into account the fact that std::string individual characters are of 'char' type which is (in most circumstances) signed by default. Hence there are errors in conditions: while(start != s.end() && *start <= ' ') ++start; and while(*stop <= ' ') --stop; If *stop doesn't fit into 0-127 range(ascii table) as in my example with russian letters, *stop appears to be less than 0, so condition to trim characters is true and it silently chops the last word out of my string until it encounters a space char. In our projects we use such post-build commands very widely (for example to copy produced binaries to a specific directory which have a cyrillic name) so this issue is somewhat crucial for us. I've attached a patch (patch.diff inside uploaded archive) that resolves this issue. It simply adds conversion of *start and *stop explicitly to unsigned char. | ||||
Steps To Reproduce | 1) Extract attached example.tar 2) Run "cmake -G "Ninja" ." inside extracted dir. 3) Examine produced build.ninja file. | ||||
Additional Information | Affected platform is Linux, Windows uses double quote escaping and the issue does not arise. This bug persists in CMake releases from 2.8.11 up to the latest 3.3.1 (at least this is what I've observed while looking into sources). | ||||
Tags | No tags attached. | ||||
Relationships | |||||
Attached Files | ![]() https://public.kitware.com/Bug/file/5520/example.zip | ||||
Issue History | |||||
Date Modified | Username | Field | Change | ||
2015-09-10 06:50 | Pavel Solodovnikov | New Issue | |||
2015-09-10 06:50 | Pavel Solodovnikov | File Added: example.zip | |||
2015-09-10 09:20 | Brad King | Note Added: 0039392 | |||
2015-09-10 09:20 | Brad King | Assigned To | => Brad King | ||
2015-09-10 09:20 | Brad King | Status | new => resolved | ||
2015-09-10 09:20 | Brad King | Resolution | open => fixed | ||
2015-09-10 09:20 | Brad King | Fixed in Version | => CMake 3.4 | ||
2015-09-10 09:20 | Brad King | Target Version | => CMake 3.4 | ||
2015-09-10 09:46 | Clinton Stimpson | Note Added: 0039393 | |||
2015-09-10 09:54 | Brad King | Note Added: 0039394 | |||
2015-09-10 10:07 | Brad King | Note Added: 0039397 | |||
2015-09-10 11:15 | Clinton Stimpson | Note Added: 0039398 | |||
2015-09-11 04:53 | Pavel Solodovnikov | Note Added: 0039404 | |||
2015-09-11 04:59 | Pavel Solodovnikov | Note Edited: 0039404 | bug_revision_view_page.php?bugnote_id=39404#r1891 | ||
2016-02-01 09:10 | Robert Maynard | Note Added: 0040394 | |||
2016-02-01 09:10 | Robert Maynard | Status | resolved => closed |
Notes | |||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|