]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/hashcomp.cpp
Added some missing parameter checking in m_swhois
[user/henk/code/inspircd.git] / src / hashcomp.cpp
index a0394b0f95667d61e8ae710f9136694dc004ee87..caf93ec1be9ebec29ca450d6476aeaeef93842da 100644 (file)
@@ -138,15 +138,15 @@ int irc::irc_char_traits::compare(const char* str1, const char* str2, size_t n)
        for(unsigned int i = 0; i < n; i++)
        {
                if(lowermap[(unsigned char)*str1] > lowermap[(unsigned char)*str2])
-                               return 1;
+                       return 1;
 
                if(lowermap[(unsigned char)*str1] < lowermap[(unsigned char)*str2])
-                       return -1;
+                       return -1;
 
                if(*str1 == 0 || *str2 == 0)
-                       return 0;
+                       return 0;
 
-               str1++;
+               str1++;
                str2++;
        }
        return 0;
@@ -211,10 +211,34 @@ bool irc::tokenstream::GetToken(std::string &token)
 
                n++;
        }
-       token = "";
+       token.clear();
        return false;
 }
 
+bool irc::tokenstream::GetToken(irc::string &token)
+{
+       std::string stdstring;
+       bool returnval = GetToken(stdstring);
+       token = assign(stdstring);
+       return returnval;
+}
+
+bool irc::tokenstream::GetToken(int &token)
+{
+       std::string tok;
+       bool returnval = GetToken(tok);
+       token = ConvToInt(tok);
+       return returnval;
+}
+
+bool irc::tokenstream::GetToken(long &token)
+{
+       std::string tok;
+       bool returnval = GetToken(tok);
+       token = ConvToInt(tok);
+       return returnval;
+}
+
 irc::sepstream::sepstream(const std::string &source, char seperator) : tokens(source), sep(seperator)
 {
        last_starting_position = tokens.begin();
@@ -266,19 +290,17 @@ std::string irc::hex(const unsigned char *raw, size_t rawsz)
        /* EWW! This used to be using sprintf, which is WAY inefficient. -Special */
        
        const char *hex = "0123456789abcdef";
-
-       std::string buf;
-       buf.reserve(rawsz * 2 + 1);
+       static char hexbuf[MAXBUF];
 
        size_t i, j;
        for (i = 0, j = 0; j < rawsz; ++j)
        {
-               buf[i++] = hex[raw[j] / 16];
-               buf[i++] = hex[raw[j] % 16];
+               hexbuf[i++] = hex[raw[j] / 16];
+               hexbuf[i++] = hex[raw[j] % 16];
        }
-       buf[i] = '\0';
+       hexbuf[i] = 0;
 
-       return buf;
+       return hexbuf;
 }
 
 CoreExport const char* irc::Spacify(const char* n)
@@ -336,7 +358,7 @@ int irc::modestacker::GetStackedLine(std::deque<std::string> &result, int max_li
        if (sequence.size() > 1)
                nextsize = sequence[1].length() + 2;
 
-       while (!sequence[0].empty() && (sequence.size() > 1) && (result.size() < MAXMODES+1) && ((size + nextsize) < max_line_size))
+       while (!sequence[0].empty() && (sequence.size() > 1) && (result.size() < MAXMODES) && ((size + nextsize) < max_line_size))
        {
                result[0] += *(sequence[0].begin());
                if (!sequence[1].empty())
@@ -433,14 +455,14 @@ long irc::portparser::GetToken()
 
        std::string x = sep->GetToken();
 
-       if (x == "")
+       if (x.empty())
                return 0;
 
        while (Overlaps(atoi(x.c_str())))
        {
                x = sep->GetToken();
 
-               if (x == "")
+               if (x.empty())
                        return 0;
        }
 
@@ -484,7 +506,7 @@ irc::dynamicbitmask::~dynamicbitmask()
        /* Tidy up the entire used memory on delete */
        delete[] bits;
 }
-                         
+
 irc::bitfield irc::dynamicbitmask::Allocate()
 {
        /* Yeah, this isnt too efficient, however a module or the core