diff options
author | Brad King <brad.king@kitware.com> | 2013-05-31 13:37:10 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-05-31 13:37:10 (GMT) |
commit | aad04efe5eb483462d118cae8b76e64795a53810 (patch) | |
tree | b26d91807b5de7c0540aee0f1ee4297f30a61a6d | |
parent | 0ad0c37206fce114c4e4c31f5270b53e181ab3c2 (diff) | |
parent | 045d6ae0b042d4e6e3c4540c32559c58cb4153b0 (diff) | |
download | CMake-aad04efe5eb483462d118cae8b76e64795a53810.zip CMake-aad04efe5eb483462d118cae8b76e64795a53810.tar.gz CMake-aad04efe5eb483462d118cae8b76e64795a53810.tar.bz2 |
Merge branch 'fix-FileIsDirectory-SEGV' into release
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 22bf193..8b25d60 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -2742,14 +2742,23 @@ bool SystemTools::FileIsDirectory(const char* name) } // Remove any trailing slash from the name. - char buffer[KWSYS_SYSTEMTOOLS_MAXPATH]; + char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH]; + std::string string_buffer; size_t last = length-1; if(last > 0 && (name[last] == '/' || name[last] == '\\') && strcmp(name, "/") !=0) { - memcpy(buffer, name, last); - buffer[last] = 0; - name = buffer; + if(last < sizeof(local_buffer)) + { + memcpy(local_buffer, name, last); + local_buffer[last] = 0; + name = local_buffer; + } + else + { + string_buffer.append(name, last); + name = string_buffer.c_str(); + } } // Now check the file node type. |