diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2021-02-16 15:14:36 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2021-02-18 13:30:55 (GMT) |
commit | 1f1fdff7fa9f51ccdc91232606a6ade20e02d83f (patch) | |
tree | 99c5903437ba9e73ef71e5d750d6651234dc3dbe /Source | |
parent | 9934a97642f82f35380fca7b5b1b1867abbd9688 (diff) | |
download | CMake-1f1fdff7fa9f51ccdc91232606a6ade20e02d83f.zip CMake-1f1fdff7fa9f51ccdc91232606a6ade20e02d83f.tar.gz CMake-1f1fdff7fa9f51ccdc91232606a6ade20e02d83f.tar.bz2 |
cmListCommand: prefer strtol to atoi
This allows for detecting errors.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmListCommand.cxx | 12 |
1 files 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 <algorithm> #include <cassert> -#include <cstddef> #include <cstdio> -#include <cstdlib> // required for atoi #include <functional> #include <iterator> #include <set> @@ -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<int>(value); + return true; } |