From 4a20dd4dac14f5d5fe6d571386172f0c366f63db Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Mon, 14 Jul 2014 09:55:19 -0400 Subject: [PATCH] fix a bug with the chat synposis generated by dbus notifications When searching for the next line, if it didn't find one, index npos would cause it to wrap around unexpectedly. --- src/desktop/dbus_notification.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/desktop/dbus_notification.cpp b/src/desktop/dbus_notification.cpp index cdf8d86cefb2..fac3fd6cfa1a 100644 --- a/src/desktop/dbus_notification.cpp +++ b/src/desktop/dbus_notification.cpp @@ -170,6 +170,8 @@ uint32_t send_dbus_notification(DBusConnection *connection, uint32_t replaces_id namespace dbus { +const int MAX_MSG_LINES = 5; + void send_notification(const std::string & owner, const std::string & message) { DBusConnection *connection = get_dbus_connection(); @@ -181,9 +183,14 @@ void send_notification(const std::string & owner, const std::string & message) if (i != i_end) { i->message = message + "\n" + i->message; - int endl_pos = -1; - for (int ctr = 0; ctr < 5; ctr++) + + size_t endl_pos = i->message.find('\n'); + size_t ctr = 1; + + while (ctr < MAX_MSG_LINES && endl_pos != std::string::npos) { endl_pos = i->message.find('\n', endl_pos+1); + ctr++; + } i->message = i->message.substr(0,endl_pos);