From 96ec7898e1acda99dca1c34fbe7a83f1166b2019 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 12 Nov 2006 13:28:46 +0000 Subject: [PATCH] We now have only one string copy for remote topics. We still need two for local though (ick) -- see comments git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5700 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/cmd_topic.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cmd_topic.cpp b/src/cmd_topic.cpp index 6d2f6cf9e..bb6e418bd 100644 --- a/src/cmd_topic.cpp +++ b/src/cmd_topic.cpp @@ -75,25 +75,36 @@ CmdResult cmd_topic::Handle (const char** parameters, int pcnt, userrec *user) return CMD_FAILURE; } } + char topic[MAXTOPIC]; - strlcpy(topic,parameters[1],MAXTOPIC-1); if (IS_LOCAL(user)) { + /* XXX: we need two string copies for a local topic, because we cant + * let a module see the topic as longer than it actually is + */ int MOD_RESULT = 0; + + strlcpy(topic,parameters[1],MAXTOPIC-1); FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic)); if (MOD_RESULT) return CMD_FAILURE; + + strlcpy(Ptr->topic,topic,MAXTOPIC-1); + } + else + { + /* Sneaky shortcut, one string copy for a remote topic */ + strlcpy(Ptr->topic, parameters[1], MAXTOPIC-1); } - strlcpy(Ptr->topic,topic,MAXTOPIC-1); strlcpy(Ptr->setby,user->nick,NICKMAX-1); Ptr->topicset = ServerInstance->Time(); Ptr->WriteChannel(user, "TOPIC %s :%s", Ptr->name, Ptr->topic); + if (IS_LOCAL(user)) - { - FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user,Ptr,topic)); - } + /* We know 'topic' will contain valid data here */ + FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user, Ptr, topic)); } else { -- 2.39.5