file: remove dead code

The file command requires at least two arguments, so guarding the GLOB and
MAKE_DIRECTORY command is not necessary. Changed it for an assert to keep the
protection.
This commit is contained in:
Amine Chadly 2012-09-29 19:33:39 +02:00 committed by Rolf Eike Beer
parent 07251a8ea5
commit c2a6cb64af
4 changed files with 14 additions and 10 deletions

View File

@ -22,6 +22,7 @@
#endif #endif
#undef GetCurrentDirectory #undef GetCurrentDirectory
#include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -705,11 +706,8 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args, bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
bool recurse) bool recurse)
{ {
if ( args.size() < 2 ) // File commands has at least one argument
{ assert(args.size() > 1);
this->SetError("GLOB requires at least a variable name");
return false;
}
std::vector<std::string>::const_iterator i = args.begin(); std::vector<std::string>::const_iterator i = args.begin();
@ -843,11 +841,8 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
bool cmFileCommand::HandleMakeDirectoryCommand( bool cmFileCommand::HandleMakeDirectoryCommand(
std::vector<std::string> const& args) std::vector<std::string> const& args)
{ {
if(args.size() < 2 ) // File command has at least one argument
{ assert(args.size() > 1);
this->SetError("called with incorrect number of arguments");
return false;
}
std::vector<std::string>::const_iterator i = args.begin(); std::vector<std::string>::const_iterator i = args.begin();

View File

@ -0,0 +1,2 @@
# Checking that the call without arguments get caught by the file global protection.
file(GLOB)

View File

@ -12,6 +12,10 @@ set(Copy-NoDest-RESULT 1)
set(Copy-NoDest-STDERR "given no DESTINATION") set(Copy-NoDest-STDERR "given no DESTINATION")
set(Copy-NoFile-RESULT 1) set(Copy-NoFile-RESULT 1)
set(Copy-NoFile-STDERR "COPY cannot find.*/does_not_exist\\.txt") set(Copy-NoFile-STDERR "COPY cannot find.*/does_not_exist\\.txt")
set(Glob-NoArg-RESULT 1)
set(Glob-NoArg-STDERR "file must be called with at least two arguments")
set(Make_Directory-NoArg-RESULT 1)
set(Make-Directory-NoArg-STDERR "file must be called with at least two arguments")
set(MD5-NoFile-RESULT 1) set(MD5-NoFile-RESULT 1)
set(MD5-NoFile-STDERR "file MD5 failed to read file") set(MD5-NoFile-STDERR "file MD5 failed to read file")
set(MD5-BadArg1-RESULT 1) set(MD5-BadArg1-RESULT 1)
@ -42,6 +46,8 @@ check_cmake_test(File
Copy-LateArg Copy-LateArg
Copy-NoDest Copy-NoDest
Copy-NoFile Copy-NoFile
Glob-NoArg
Make_Directory-NoArg
MD5-NoFile MD5-NoFile
MD5-BadArg1 MD5-BadArg1
MD5-BadArg2 MD5-BadArg2

View File

@ -0,0 +1 @@
file(MAKE_DIRECTORY)