Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/ucioption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <algorithm>
#include <cassert>
#include <cerrno>
#include <cctype>
#include <cstdlib>
#include <iostream>
Expand Down Expand Up @@ -153,10 +154,24 @@ Option& Option::operator=(const std::string& v) {
assert(!type.empty());

if ((type != "button" && type != "string" && v.empty())
|| (type == "check" && v != "true" && v != "false")
|| (type == "spin" && (std::stoi(v) < min || std::stoi(v) > max)))
|| (type == "check" && v != "true" && v != "false"))
return *this;

// For spin options, reject values that don't parse as a full int or fall
// outside [min, max]. std::strtol is used instead of std::stoi because the
// codebase is compiled with -fno-exceptions, so throwing on malformed UCI
// input would terminate the engine.
if (type == "spin")
{
errno = 0;
char* end = nullptr;
const char* begin = v.c_str();
const long parsed = std::strtol(begin, &end, 10);

if (begin == end || *end != '\0' || errno == ERANGE || parsed < min || parsed > max)
return *this;
}

if (type == "combo")
{
OptionsMap comboMap; // To have case insensitive compare
Expand Down
Loading