]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Tidy up strlens which are not required
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 6 Oct 2006 09:09:27 +0000 (09:09 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 6 Oct 2006 09:09:27 +0000 (09:09 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5428 e03df62e-2008-0410-955e-edbf42e46eb7

src/modules/m_httpd.cpp
src/modules/m_sethost.cpp
src/modules/m_setident.cpp

index 6df26e9c0c72a8ea76a2b8c8a41852c11fa12431..189a80b8971788c203ea9a371f2f655dbb94fec2 100644 (file)
@@ -72,7 +72,6 @@ class HttpSocket : public InspSocket
        std::string uri;
        std::string http_version;
        unsigned int postsize;
-       unsigned int amount;
        HTTPTimeout* Timeout;
 
  public:
@@ -254,7 +253,6 @@ class HttpSocket : public InspSocket
                                {
                                        /* Do we need to fetch postdata? */
                                        postdata = "";
-                                       amount = 0;
                                        InternalState = HTTP_SERVE_RECV_POSTDATA;
                                        std::string header_item;
                                        while (headers >> header_item)
@@ -286,9 +284,8 @@ class HttpSocket : public InspSocket
                                else if (InternalState == HTTP_SERVE_RECV_POSTDATA)
                                {
                                        /* Add postdata, once we have it all, send the event */
-                                       amount += strlen(data);
                                        postdata.append(data);
-                                       if (amount >= postsize)
+                                       if (postdata.length() >= postsize)
                                                ServeData();
                                }
                                else
index 3ec9fc4cadb4a85b2355254a95b70c5bdc2f006e..6787867577d38ba997053e7d0f4d53bce81b480c 100644 (file)
@@ -40,22 +40,23 @@ class cmd_sethost : public command_t
 
        CmdResult Handle (const char** parameters, int pcnt, userrec *user)
        {
-               if (strlen(parameters[0]) > 64)
+               size_t len = 0;
+               for (const char* x = parameters[0]; *x; x++, len++)
                {
-                       user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick);
-                       return CMD_FAILURE;
-               }
-               for (unsigned int x = 0; x < strlen(parameters[0]); x++)
-               {
-                       if (((tolower(parameters[0][x]) < 'a') || (tolower(parameters[0][x]) > 'z')) && (parameters[0][x] != '.'))
+                       if (((tolower(*x) < 'a') || (tolower(*x) > 'z')) && (*x != '.'))
                        {
-                               if (((parameters[0][x] < '0') || (parameters[0][x]> '9')) && (parameters[0][x] != '-'))
+                               if (((*x < '0') || (*x> '9')) && (*x != '-'))
                                {
                                        user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
                                        return CMD_FAILURE;
                                }
                        }
                }
+               if (len > 64)
+               {
+                       user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick);
+                       return CMD_FAILURE;
+               }
                if (user->ChangeDisplayedHost(parameters[0]))
                {
                        ServerInstance->WriteOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
index 2bcdceeb17abf37ad9c1ba3b123384a53ed7664a..d1f67bb1400a07bc088c8395cbb1d620e363d55b 100644 (file)
@@ -15,14 +15,20 @@ class cmd_setident : public command_t
 
        CmdResult Handle(const char** parameters, int pcnt, userrec *user)
        {
-               for(unsigned int x = 0; x < strlen(parameters[0]); x++)
+               size_t len = 0;
+               for(const char* x = parameters[0]; *x; x++, len++)
                {
-                       if(((parameters[0][x] >= 'A') && (parameters[0][x] <= '}')) || strchr(".-0123456789", parameters[0][x]))
+                       if(((*x >= 'A') && (*x <= '}')) || strchr(".-0123456789", *x))
                                continue;
-                       
+
                        user->WriteServ("NOTICE %s :*** Invalid characters in ident", user->nick);
                        return CMD_FAILURE;
                }
+               if (len > IDENTMAX)
+               {
+                       user->WriteServ("NOTICE %s :*** Ident is too long", user->nick);
+                       return CMD_FAILURE;
+               }
 
                user->ChangeIdent(parameters[0]);
                ServerInstance->WriteOpers("%s used SETIDENT to change their ident to '%s'", user->nick, user->ident);