summaryrefslogtreecommitdiffstats
path: root/Source/cmFileCommand.cxx
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2024-05-31 11:20:30 (GMT)
committerCraig Scott <craig.scott@crascit.com>2024-05-31 12:55:20 (GMT)
commit7c516f7e28813a1ed66a4fd0a94d8a56b611eeef (patch)
tree04ae221bdaf7a1bd6d57da1aa7e96554efa11f3c /Source/cmFileCommand.cxx
parent140766867b2c8f8dff0e4d0d73e481b6944b5284 (diff)
downloadCMake-7c516f7e28813a1ed66a4fd0a94d8a56b611eeef.zip
CMake-7c516f7e28813a1ed66a4fd0a94d8a56b611eeef.tar.gz
CMake-7c516f7e28813a1ed66a4fd0a94d8a56b611eeef.tar.bz2
file(): TOUCH, TOUCH_NOCREATE and MAKE_DIRECTORY accept empty lists
Projects may be generating a list of files or directories to pass as arguments to file(TOUCH), file(TOUCH_NOCREATE), or file(MAKE_DIRECTORY). Those lists might end up being empty, so rather than requiring at least one item, allow an empty list. Fixes: #24897
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r--Source/cmFileCommand.cxx25
1 files changed, 17 insertions, 8 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 0369051..77f740b 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -73,6 +73,11 @@ namespace {
bool HandleWriteImpl(std::vector<std::string> const& args, bool append,
cmExecutionStatus& status)
{
+ if (args.size() < 2) {
+ status.SetError(cmStrCat(
+ args[0], " must be called with at least one additional argument."));
+ return false;
+ }
auto i = args.begin();
i++; // Get rid of subcommand
@@ -658,8 +663,11 @@ bool HandleStringsCommand(std::vector<std::string> const& args,
bool HandleGlobImpl(std::vector<std::string> const& args, bool recurse,
cmExecutionStatus& status)
{
- // File commands has at least one argument
- assert(args.size() > 1);
+ if (args.size() < 2) {
+ status.SetError(cmStrCat(
+ args[0], " must be called with at least one additional argument."));
+ return false;
+ }
auto i = args.begin();
@@ -869,8 +877,8 @@ bool HandleGlobRecurseCommand(std::vector<std::string> const& args,
bool HandleMakeDirectoryCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
- // File command has at least one argument
- assert(args.size() > 1);
+ // Projects might pass a dynamically generated list of directories, and it
+ // could be an empty list. We should not assume there is at least one.
std::string expr;
for (std::string const& arg :
@@ -903,8 +911,8 @@ bool HandleMakeDirectoryCommand(std::vector<std::string> const& args,
bool HandleTouchImpl(std::vector<std::string> const& args, bool create,
cmExecutionStatus& status)
{
- // File command has at least one argument
- assert(args.size() > 1);
+ // Projects might pass a dynamically generated list of files, and it
+ // could be an empty list. We should not assume there is at least one.
for (std::string const& arg :
cmMakeRange(args).advance(1)) // Get rid of subcommand
@@ -3918,8 +3926,9 @@ bool HandleChmodRecurseCommand(std::vector<std::string> const& args,
bool cmFileCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
- if (args.size() < 2) {
- status.SetError("must be called with at least two arguments.");
+ if (args.empty()) {
+ status.SetError(
+ "given no arguments, but it requires at least a sub-command.");
return false;
}