Same algorithm, same fix as provided for the MQTT decoder in the previous patch
Signed-off-by: Alexander Kaiser <alexander.kaiser@relayr.de>
diff --git a/src/MQTT_v3_1_1_Size.cc b/src/MQTT_v3_1_1_Size.cc
index bcbad11..41b9e5f 100644
--- a/src/MQTT_v3_1_1_Size.cc
+++ b/src/MQTT_v3_1_1_Size.cc
@@ -15,7 +15,7 @@
namespace MQTT__v3__1__1__IPL4SizeFunction {
INTEGER f__calc__MQTT__length(const OCTETSTRING& data){
-
+
int multiplier, value, i, j;
i = 0; // encoded byte
j = 2; // additional real size
@@ -24,7 +24,6 @@
do {
i++;
value += (oct2int(data[i]) & 127) * multiplier + j;
- multiplier *= 128;
if (multiplier > 128*128*128){
if(TTCN_Logger::log_this_event(LOG_ALL)){
TTCN_Logger::begin_event(LOG_ALL);
@@ -33,7 +32,8 @@
}
return -1; //error case, bigger than the MQTT limit
}
- j = 1;
+ multiplier *= 128;
+ j = 1;
}while((oct2int(data[i]) & 128) != 0);
return value;
diff --git a/src/negative_testing/MQTT_v3_1_1_Size.cc b/src/negative_testing/MQTT_v3_1_1_Size.cc
index 19c8831..4eb5e63 100644
--- a/src/negative_testing/MQTT_v3_1_1_Size.cc
+++ b/src/negative_testing/MQTT_v3_1_1_Size.cc
@@ -7,7 +7,7 @@
*
* Contributors:
* Spaseski Naum - initial implementation
-* Bence Janos Szabo - negative testing branch
+* Bence Janos Szabo - negative testing branch
******************************************************************************/
#include "MQTT_v3_1_1_IPL4SizeFunction.hh"
@@ -16,7 +16,7 @@
namespace MQTT__v3__1__1__IPL4SizeFunction {
INTEGER f__calc__MQTT__length(const OCTETSTRING& data){
-
+
int multiplier, value, i, j;
i = 0; // encoded byte
j = 2; // additional real size
@@ -25,7 +25,6 @@
do {
i++;
value += (oct2int(data[i]) & 127) * multiplier + j;
- multiplier *= 128;
if (multiplier > 128*128*128){
if(TTCN_Logger::log_this_event(LOG_ALL)){
TTCN_Logger::begin_event(LOG_ALL);
@@ -34,7 +33,8 @@
}
return -1; //error case, bigger than the MQTT limit
}
- j = 1;
+ multiplier *= 128;
+ j = 1;
}while((oct2int(data[i]) & 128) != 0);
return value;