From 3f782d5cad84165d695203977c75d2a3877f4644 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 16 May 2013 19:57:53 -0400 Subject: Fix m_randquote with 0 quotes --- src/modules.cpp | 2 +- src/modules/m_randquote.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/modules.cpp b/src/modules.cpp index a7b3364ae..d25e145e3 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -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]; } diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp index dab3c93cd..668eea0e5 100644 --- a/src/modules/m_randquote.cpp +++ b/src/modules/m_randquote.cpp @@ -41,12 +41,13 @@ class CommandRandquote : public Command CmdResult Handle (const std::vector& 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; } -- cgit v1.2.3