1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 15:44:46 +02:00

Fix the config parser using int for values that can not be negative.

This commit is contained in:
Sadie Powell
2026-06-08 15:41:00 +01:00
parent 90da25f84f
commit a861a059f6
5 changed files with 19 additions and 15 deletions
+5 -5
View File
@@ -35,7 +35,7 @@ namespace Configuration
Anope::string name;
ItemMap items;
BlockMap blocks;
int linenum;
unsigned linenum;
/* Represents a missing tag. */
static Block EmptyBlock;
@@ -43,10 +43,10 @@ namespace Configuration
public:
Block(const Anope::string &);
const Anope::string &GetName() const;
int CountBlock(const Anope::string &name) const;
size_t CountBlock(const Anope::string &name) const;
BlockList GetBlocks(const Anope::string &name) const;
const Block &GetBlock(const Anope::string &name, int num = 0) const;
Block *GetMutableBlock(const Anope::string &name, int num = 0);
const Block &GetBlock(const Anope::string &name, size_t num = 0) const;
Block *GetMutableBlock(const Anope::string &name, size_t num = 0);
template<typename T> T Get(const Anope::string &tag, const Anope::string &def = "") const
{
@@ -88,7 +88,7 @@ namespace Configuration
{
private:
/** Replaces defined variables within a string. */
Anope::string ReplaceVars(const Anope::string &str, const File &file, int linenumber);
Anope::string ReplaceVars(const Anope::string &str, const File &file, unsigned linenumber);
public:
/* options:readtimeout */
+1 -1
View File
@@ -634,7 +634,7 @@ public:
{
const Anope::string &cname = it->first;
LDAPService *s = it->second;
int i;
size_t i;
++it;
+1 -1
View File
@@ -281,7 +281,7 @@ public:
{
const Anope::string &cname = it->first;
MySQLService *s = it->second;
int i;
size_t i;
++it;
+1 -1
View File
@@ -129,7 +129,7 @@ public:
{
const Anope::string &cname = it->first;
SQLiteService *s = it->second;
int i, num;
size_t i, num;
++it;
for (i = 0, num = config.CountBlock("sqlite"); i < num; ++i)
+11 -7
View File
@@ -38,7 +38,7 @@ const Anope::string &Configuration::Block::GetName() const
return name;
}
int Configuration::Block::CountBlock(const Anope::string &bname) const
size_t Configuration::Block::CountBlock(const Anope::string &bname) const
{
return blocks.count(bname);
}
@@ -48,23 +48,27 @@ Configuration::Block::BlockList Configuration::Block::GetBlocks(const Anope::str
return Anope::equal_range(blocks, bname);
}
const Configuration::Block &Configuration::Block::GetBlock(const Anope::string &bname, int num) const
const Configuration::Block &Configuration::Block::GetBlock(const Anope::string &bname, size_t num) const
{
auto it = blocks.equal_range(bname);
for (int i = 0; it.first != it.second; ++it.first, ++i)
for (size_t i = 0; it.first != it.second; ++it.first, ++i)
{
if (i == num)
return it.first->second;
}
return EmptyBlock;
}
Configuration::Block *Configuration::Block::GetMutableBlock(const Anope::string &bname, int num)
Configuration::Block *Configuration::Block::GetMutableBlock(const Anope::string &bname, size_t num)
{
auto it = blocks.equal_range(bname);
for (int i = 0; it.first != it.second; ++it.first, ++i)
for (size_t i = 0; it.first != it.second; ++it.first, ++i)
{
if (i == num)
return &it.first->second;
}
return NULL;
}
@@ -766,7 +770,7 @@ void Configuration::Conf::LoadConf(Configuration::File &file)
Anope::string itemname, wordbuffer;
std::stack<Configuration::Block *> block_stack;
int linenumber = 0;
unsigned linenumber = 0;
bool in_word = false, in_quote = false, in_comment = false;
Log(LOG_DEBUG) << "Start to read conf " << file.GetPath();
@@ -968,7 +972,7 @@ void Configuration::Conf::LoadConf(Configuration::File &file)
}
}
Anope::string Configuration::Conf::ReplaceVars(const Anope::string &str, const Configuration::File &file, int linenumber)
Anope::string Configuration::Conf::ReplaceVars(const Anope::string &str, const Configuration::File &file, unsigned linenumber)
{
Anope::string ret;
for (auto it = str.begin(); it != str.end(); )