]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_chghost.cpp
Improved to avoid strlen
[user/henk/code/inspircd.git] / src / modules / m_chghost.cpp
index 8a2e696bc3917ecde9028b74959a1cd230edd40c..d77ddf515488212c73027ea66c54c4f6a78cc226 100644 (file)
@@ -25,8 +25,7 @@ using namespace std;
 
 /* $ModDesc: Provides support for the CHGHOST command */
 
-Server *Srv;
-
+static Server *Srv;
 
 class cmd_chghost : public command_t
 {
@@ -38,22 +37,24 @@ class cmd_chghost : public command_t
         
         void Handle(char **parameters, int pcnt, userrec *user)
        {
-                if (strlen(parameters[1]) > 64)
-                {
-                        WriteServ(user->fd,"NOTICE %s :*** CHGHOST: Host too long",user->nick);
-                       return;
-                }
-               for (unsigned int x = 0; x < strlen(parameters[1]); x++)
+               char * x = parameters[1];
+
+               for (; *x; x++)
                {
-                       if (((tolower(parameters[1][x]) < 'a') || (tolower(parameters[1][x]) > 'z')) && (parameters[1][x] != '.'))
+                       if (((tolower(*x) < 'a') || (tolower(*x) > 'z')) && (*x != '.'))
                        {
-                               if (((parameters[1][x] < '0') || (parameters[1][x]> '9')) && (parameters[1][x] != '-'))
+                               if (((*x < '0') || (*x > '9')) && (*x != '-'))
                                {
                                        Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
                                        return;
                                }
                        }
-               }       
+               }
+               if ((parameters[1] - x) > 63)
+               {
+                       WriteServ(user->fd,"NOTICE %s :*** CHGHOST: Host too long",user->nick);
+                       return;
+               }
                userrec* dest = Srv->FindNick(std::string(parameters[0]));
                if (dest)
                {