1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 17:24:49 +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; Anope::string name;
ItemMap items; ItemMap items;
BlockMap blocks; BlockMap blocks;
int linenum; unsigned linenum;
/* Represents a missing tag. */ /* Represents a missing tag. */
static Block EmptyBlock; static Block EmptyBlock;
@@ -43,10 +43,10 @@ namespace Configuration
public: public:
Block(const Anope::string &); Block(const Anope::string &);
const Anope::string &GetName() const; 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; BlockList GetBlocks(const Anope::string &name) const;
const Block &GetBlock(const Anope::string &name, int num = 0) const; const Block &GetBlock(const Anope::string &name, size_t num = 0) const;
Block *GetMutableBlock(const Anope::string &name, int num = 0); Block *GetMutableBlock(const Anope::string &name, size_t num = 0);
template<typename T> T Get(const Anope::string &tag, const Anope::string &def = "") const template<typename T> T Get(const Anope::string &tag, const Anope::string &def = "") const
{ {
@@ -88,7 +88,7 @@ namespace Configuration
{ {
private: private:
/** Replaces defined variables within a string. */ /** 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: public:
/* options:readtimeout */ /* options:readtimeout */
+1 -1
View File
@@ -634,7 +634,7 @@ public:
{ {
const Anope::string &cname = it->first; const Anope::string &cname = it->first;
LDAPService *s = it->second; LDAPService *s = it->second;
int i; size_t i;
++it; ++it;
+1 -1
View File
@@ -281,7 +281,7 @@ public:
{ {
const Anope::string &cname = it->first; const Anope::string &cname = it->first;
MySQLService *s = it->second; MySQLService *s = it->second;
int i; size_t i;
++it; ++it;
+1 -1
View File
@@ -129,7 +129,7 @@ public:
{ {
const Anope::string &cname = it->first; const Anope::string &cname = it->first;
SQLiteService *s = it->second; SQLiteService *s = it->second;
int i, num; size_t i, num;
++it; ++it;
for (i = 0, num = config.CountBlock("sqlite"); i < num; ++i) 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; 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); return blocks.count(bname);
} }
@@ -48,23 +48,27 @@ Configuration::Block::BlockList Configuration::Block::GetBlocks(const Anope::str
return Anope::equal_range(blocks, bname); 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); 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) if (i == num)
return it.first->second; return it.first->second;
}
return EmptyBlock; 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); 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) if (i == num)
return &it.first->second; return &it.first->second;
}
return NULL; return NULL;
} }
@@ -766,7 +770,7 @@ void Configuration::Conf::LoadConf(Configuration::File &file)
Anope::string itemname, wordbuffer; Anope::string itemname, wordbuffer;
std::stack<Configuration::Block *> block_stack; std::stack<Configuration::Block *> block_stack;
int linenumber = 0; unsigned linenumber = 0;
bool in_word = false, in_quote = false, in_comment = false; bool in_word = false, in_quote = false, in_comment = false;
Log(LOG_DEBUG) << "Start to read conf " << file.GetPath(); 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; Anope::string ret;
for (auto it = str.begin(); it != str.end(); ) for (auto it = str.begin(); it != str.end(); )