SSqlStatement::row_t row;
d_GetLastInsertedKeyIdQuery_stmt->nextRow(row);
ASSERT_ROW_COLUMNS("get-last-inserted-key-id-query", row, 1);
- keyId = std::stoi(row[0]);
+ pdns::checked_stoi_into(keyId, row[0]);
d_GetLastInsertedKeyIdQuery_stmt->reset();
if (keyId == 0) {
// No insert took place, report as error.
}
if (d_abiVersion >= 3) {
- r.scopeMask = std::stoi(parts[1]);
+ pdns::checked_stoi_into(r.scopeMask, parts[1]);
r.auth = (parts[2] == "1");
parts.erase(parts.begin() + 1, parts.begin() + 3);
}
if (d_AddDomainKeyQuery_stmt->hasNextRow()) {
SSqlStatement::row_t row;
d_AddDomainKeyQuery_stmt->nextRow(row);
- keyId = std::stoi(row[0]);
+ pdns::checked_stoi_into(keyId, row[0]);
d_AddDomainKeyQuery_stmt->reset();
return true;
} else {
SSqlStatement::row_t row;
d_GetLastInsertedKeyIdQuery_stmt->nextRow(row);
ASSERT_ROW_COLUMNS("get-last-inserted-key-id-query", row, 1);
- keyId = std::stoi(row[0]);
+ pdns::checked_stoi_into(keyId, row[0]);
d_GetLastInsertedKeyIdQuery_stmt->reset();
if (keyId == 0) {
// No insert took place, report as error.
continue;
}
if (pdns_iequals(key,"slot")) {
- int slot = std::stoi(value);
+ auto slot = pdns::checked_stoi<int>(value);
stormap["slot"]=std::to_string(slot);
continue;
}
if (val.is_string()) {
try {
- return std::stoi(val.string_value());
+ return pdns::checked_stoi<int>(val.string_value());
} catch (std::logic_error&) {
throw JsonException("Key '" + string(key) + "' is not a valid number");
}
std::size_t found = host4.find(':');
vector<uint16_t> ports{80, 443};
if (found != std::string::npos) {
- int port = std::stoi(host4.substr(found + 1));
- if (port <= 0 || port > 65535)
- throw std::overflow_error("Invalid port number");
- ports = {(uint16_t)port};
+ auto port = pdns::checked_stoi<uint16_t>(host4.substr(found + 1));
+ ports = {port};
host4 = host4.substr(0, found);
}
// see if we can find it with slotId
try {
- slotId = std::stoi(tokenId);
+ pdns::checked_stoi_into(slotId, tokenId);
if ((err = functions->C_GetSlotInfo(slotId, info))) {
SLOG(g_log<<Logger::Warning<<"C_GetSlotInfo("<<slotId<<", info) = " << err << std::endl,
slog->info(Logr::Warning, "C_GetSlotInfo failed", "slotId", Logging::Loggable(slotId), "errorcode", Logging::Loggable(err)));
{
int inquireKeyId = -1;
if (req->parameters.count("key_id") == 1) {
- inquireKeyId = std::stoi(req->parameters["key_id"]);
+ pdns::checked_stoi_into(inquireKeyId, req->parameters["key_id"]);
apiZoneCryptoKeysCheckKeyExists(zonename, inquireKeyId, dnsseckeeper);
}
return inquireKeyId;