summaryrefslogtreecommitdiffstats
path: root/Source/cmListCommand.cxx
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2021-02-16 15:29:37 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2021-02-18 13:30:55 (GMT)
commit79eaa908dc2ad339d5f92b10a30c4244975ab21a (patch)
tree822684b66b9a891c3c9e92ff1fdd8838fd28b45f /Source/cmListCommand.cxx
parent1f1fdff7fa9f51ccdc91232606a6ade20e02d83f (diff)
downloadCMake-79eaa908dc2ad339d5f92b10a30c4244975ab21a.zip
CMake-79eaa908dc2ad339d5f92b10a30c4244975ab21a.tar.gz
CMake-79eaa908dc2ad339d5f92b10a30c4244975ab21a.tar.bz2
cmListCommand: add a policy for failing on invalid indicies
Diffstat (limited to 'Source/cmListCommand.cxx')
-rw-r--r--Source/cmListCommand.cxx37
1 files changed, 30 insertions, 7 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index 42f94b6..1bafdf7 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -34,11 +34,34 @@
namespace {
-bool GetIndexArg(char const* arg, int* idx)
+bool GetIndexArg(char const* arg, int* idx, cmMakefile& mf)
{
long value;
if (!cmStrToLong(arg, &value)) {
- // An error was detected.
+ switch (mf.GetPolicyStatus(cmPolicies::CMP0121)) {
+ case cmPolicies::WARN: {
+ // Default is to warn and use old behavior OLD behavior is to allow
+ // compatibility, so issue a warning and use the previous behavior.
+ std::string warn =
+ cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0121),
+ " Invalid list index \"", arg, "\".");
+ mf.IssueMessage(MessageType::AUTHOR_WARNING, warn);
+ break;
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to allow compatibility, so just ignore the
+ // situation.
+ break;
+ case cmPolicies::NEW:
+ return false;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ std::string msg =
+ cmStrCat(cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0121),
+ " Invalid list index \"", arg, "\".");
+ mf.IssueMessage(MessageType::FATAL_ERROR, msg);
+ break;
+ }
}
// Truncation is happening here, but it had always been happening here.
@@ -166,7 +189,7 @@ bool HandleGetCommand(std::vector<std::string> const& args,
size_t nitem = varArgsExpanded.size();
for (cc = 2; cc < args.size() - 1; cc++) {
int item;
- if (!GetIndexArg(args[cc].c_str(), &item)) {
+ if (!GetIndexArg(args[cc].c_str(), &item, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[cc], " is not a valid index"));
return false;
}
@@ -378,7 +401,7 @@ bool HandleInsertCommand(std::vector<std::string> const& args,
// expand the variable
int item;
- if (!GetIndexArg(args[2].c_str(), &item)) {
+ if (!GetIndexArg(args[2].c_str(), &item, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[2], " is not a valid index"));
return false;
}
@@ -1303,11 +1326,11 @@ bool HandleSublistCommand(std::vector<std::string> const& args,
int start;
int length;
- if (!GetIndexArg(args[2].c_str(), &start)) {
+ if (!GetIndexArg(args[2].c_str(), &start, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[2], " is not a valid index"));
return false;
}
- if (!GetIndexArg(args[3].c_str(), &length)) {
+ if (!GetIndexArg(args[3].c_str(), &length, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[3], " is not a valid index"));
return false;
}
@@ -1366,7 +1389,7 @@ bool HandleRemoveAtCommand(std::vector<std::string> const& args,
size_t nitem = varArgsExpanded.size();
for (cc = 2; cc < args.size(); ++cc) {
int item;
- if (!GetIndexArg(args[cc].c_str(), &item)) {
+ if (!GetIndexArg(args[cc].c_str(), &item, status.GetMakefile())) {
status.SetError(cmStrCat("index: ", args[cc], " is not a valid index"));
return false;
}