common: Fix isChannelName crash on empty string
authorShane Synan <digitalcircuit36939@gmail.com>
Mon, 4 Sep 2017 08:52:25 +0000 (03:52 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 4 Sep 2017 17:20:59 +0000 (19:20 +0200)
Add check to isChannelName for an empty string; return false if so
and don't try to index it.  This avoids crashing on connect for some
situations.

Closes GH-307.

src/common/util.cpp

index 3d199a1..a59db8f 100644 (file)
@@ -64,6 +64,8 @@ QString hostFromMask(const QString &mask)
 
 bool isChannelName(const QString &str)
 {
+    if (str.isEmpty())
+        return false;
     static constexpr std::array<quint8, 4> prefixes{{'#', '&', '!', '+'}};
     return std::any_of(prefixes.cbegin(), prefixes.cend(), [&str](quint8 c) { return c == str[0]; });
 }