1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 01:12:39 +01:00

Codechange: Replace atoi and atoll with ParseInteger.

This commit is contained in:
frosch
2025-04-29 16:12:54 +02:00
committed by frosch
parent 3973199879
commit cdafc50c94
17 changed files with 108 additions and 47 deletions

View File

@@ -25,6 +25,7 @@
#include "../strings_func.h"
#include "../timer/timer.h"
#include "../timer/timer_window.h"
#include "../core/string_consumer.hpp"
#include "script_gui.h"
#include "script_log.hpp"
@@ -495,10 +496,10 @@ struct ScriptSettingsWindow : public Window {
void OnQueryTextFinished(std::optional<std::string> str) override
{
if (!str.has_value() || str->empty()) return;
int32_t value = atoi(str->c_str());
SetValue(value);
if (!str.has_value()) return;
auto value = ParseInteger<int32_t>(*str);
if (!value.has_value()) return;
SetValue(*value);
}
void OnDropdownSelect(WidgetID widget, int index) override

View File

@@ -14,6 +14,7 @@
#include "script_info.hpp"
#include "script_scanner.hpp"
#include "../core/string_consumer.hpp"
#include "../3rdparty/fmt/format.h"
#include "../safeguards.h"
@@ -229,8 +230,9 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
sign = -1;
key_string++;
}
int key = atoi(key_string) * sign;
config->labels[key] = StrMakeValid(label);
auto key = ParseInteger<int>(key_string);
if (!key.has_value()) return SQ_ERROR;
config->labels[*key * sign] = StrMakeValid(label);
sq_pop(vm, 2);
}