]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix m_randquote with 0 quotes
authorAdam <Adam@anope.org>
Thu, 16 May 2013 23:57:53 +0000 (19:57 -0400)
committerAdam <Adam@anope.org>
Thu, 16 May 2013 23:57:53 +0000 (19:57 -0400)
src/modules.cpp
src/modules/m_randquote.cpp

index a7b3364ae1c919ba5b075837ea087ef86e75e630..d25e145e3fdaa19ec1f61a4b312e42d68f1b3cd6 100644 (file)
@@ -765,7 +765,7 @@ bool FileReader::Exists()
 
 std::string FileReader::GetLine(int x)
 {
-       if ((x<0) || ((unsigned)x>fc.size()))
+       if ((x<0) || ((unsigned)x>=fc.size()))
                return "";
        return fc[x];
 }
index dab3c93cd3f0ada2cbd277dec34479133b91677c..668eea0e5cc0e8a2d1ae8fa83b247b3150c23b9a 100644 (file)
@@ -41,12 +41,13 @@ class CommandRandquote : public Command
 
        CmdResult Handle (const std::vector<std::string>& parameters, User *user)
        {
-               std::string str;
-               int fsize;
-
-               fsize = quotes->FileSize();
-               str = quotes->GetLine(ServerInstance->GenRandomInt(fsize));
-               user->WriteServ("NOTICE %s :%s%s%s",user->nick.c_str(),prefix.c_str(),str.c_str(),suffix.c_str());
+               int fsize = quotes->FileSize();
+               if (fsize)
+               {
+                       std::string str = quotes->GetLine(ServerInstance->GenRandomInt(fsize));
+                       if (!str.empty())
+                               user->WriteServ("NOTICE %s :%s%s%s",user->nick.c_str(),prefix.c_str(),str.c_str(),suffix.c_str());
+               }
 
                return CMD_SUCCESS;
        }