mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +08:00
cmListCommand: prefer strtol to atoi
This allows for detecting errors.
This commit is contained in:
@@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib> // required for atoi
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -38,8 +36,14 @@ namespace {
|
|||||||
|
|
||||||
bool GetIndexArg(char const* arg, int* idx)
|
bool GetIndexArg(char const* arg, int* idx)
|
||||||
{
|
{
|
||||||
*idx = atoi(arg);
|
long value;
|
||||||
// Ignore errors.
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user