Commit 259bc3a749f5619ca59219e8d7602b8692945113

Authored by Hayk
1 parent d89291b5

Fix bug in subscriber for binary data

Before, was relying on constructing an std::string from a char* that was
assumed to be null terminated. Now, specify length explicitly.
Showing 1 changed file with 5 additions and 3 deletions
src/subscriber.cpp
@@ -152,15 +152,17 @@ void Subscriber::subscribeBase(const string cmd_name, const string topic, @@ -152,15 +152,17 @@ void Subscriber::subscribeBase(const string cmd_name, const string topic,
152 // Message for subscribe 152 // Message for subscribe
153 else if ((reply->type == REDIS_REPLY_ARRAY) && (reply->elements == 3)) { 153 else if ((reply->type == REDIS_REPLY_ARRAY) && (reply->elements == 3)) {
154 char *msg = reply->element[2]->str; 154 char *msg = reply->element[2]->str;
  155 + int len = reply->element[2]->len;
155 if (msg && msg_callback) 156 if (msg && msg_callback)
156 - msg_callback(topic, reply->element[2]->str); 157 + msg_callback(topic, string(msg, len));
157 } 158 }
158 159
159 // Message for psubscribe 160 // Message for psubscribe
160 else if ((reply->type == REDIS_REPLY_ARRAY) && (reply->elements == 4)) { 161 else if ((reply->type == REDIS_REPLY_ARRAY) && (reply->elements == 4)) {
161 - char *msg = reply->element[2]->str; 162 + char *msg = reply->element[3]->str;
  163 + int len = reply->element[3]->len;
162 if (msg && msg_callback) 164 if (msg && msg_callback)
163 - msg_callback(reply->element[2]->str, reply->element[3]->str); 165 + msg_callback(reply->element[2]->str, string(msg, len));
164 } 166 }
165 167
166 else 168 else