diff --git a/src/MQTTClient.c b/src/MQTTClient.c index 295505ec9182abd3f9dac6d5c841d2260db4476a..8f156b08bfada23cc349a0ae3e30983acc0a8169 100644 --- a/src/MQTTClient.c +++ b/src/MQTTClient.c @@ -2080,12 +2080,19 @@ MQTTResponse MQTTClient_subscribeMany5(MQTTClient handle, int count, char* const } else { - ListElement* current = NULL; - i = 0; - while (ListNextElement(sub->qoss, ¤t)) + ListElement *current = NULL; + + /* if the returned count is greater than requested, it's an error*/ + if (sub->qoss->count > count) + rc = MQTTCLIENT_FAILURE; + else { - int* reqqos = (int*)(current->content); - qos[i++] = *reqqos; + i = 0; + while (ListNextElement(sub->qoss, ¤t)) + { + int *reqqos = (int*) (current->content); + qos[i++] = *reqqos; + } } resp.reasonCode = rc; }