From 1f1fdff7fa9f51ccdc91232606a6ade20e02d83f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 16 Feb 2021 10:14:36 -0500 Subject: cmListCommand: prefer strtol to atoi This allows for detecting errors. --- Source/cmListCommand.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index edfaeec..42f94b6 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -4,9 +4,7 @@ #include #include -#include #include -#include // required for atoi #include #include #include @@ -38,8 +36,14 @@ namespace { bool GetIndexArg(char const* arg, int* idx) { - *idx = atoi(arg); - // Ignore errors. + long value; + if (!cmStrToLong(arg, &value)) { + // An error was detected. + } + + // Truncation is happening here, but it had always been happening here. + *idx = static_cast(value); + return true; } -- cgit v0.12