From 8478ba91ca21de52bb9dc703bbe3d6f0899c4279 Mon Sep 17 00:00:00 2001
From: Kristof Szabados <Kristof.Szabados@ericsson.com>
Date: Wed, 23 Nov 2016 18:34:11 +0100
Subject: [PATCH] the get_next_token function should return size_t (unsigned
 value) ... and this also revealed some incorrect error handling in some parts
 of the code.

Signed-off-by: Kristof Szabados <Kristof.Szabados@ericsson.com>
---
 common/JSON_Tokenizer.cc     |  2 +-
 common/JSON_Tokenizer.hh     |  2 +-
 compiler2/enum.c             |  4 +--
 compiler2/record.c           | 10 +++----
 compiler2/record_of.c        | 36 +++++++++++------------
 compiler2/union.c            | 56 ++++++++++++++++++------------------
 core/ASN_Null.cc             |  4 +--
 core/Array.hh                | 12 ++++----
 core/Bitstring.cc            |  4 +--
 core/Boolean.cc              |  4 +--
 core/Charstring.cc           |  4 +--
 core/Float.cc                |  4 +--
 core/Hexstring.cc            |  4 +--
 core/Integer.cc              | 20 ++++++-------
 core/Objid.cc                |  4 +--
 core/Octetstring.cc          |  4 +--
 core/Optional.hh             |  4 +--
 core/Universal_charstring.cc |  4 +--
 core/Verdicttype.cc          |  8 +++---
 core2/Basetype2.cc           | 30 +++++++++----------
 20 files changed, 110 insertions(+), 110 deletions(-)

diff --git a/common/JSON_Tokenizer.cc b/common/JSON_Tokenizer.cc
index 1f866e382..7cba8c44c 100644
--- a/common/JSON_Tokenizer.cc
+++ b/common/JSON_Tokenizer.cc
@@ -202,7 +202,7 @@ bool JSON_Tokenizer::check_for_literal(const char* p_literal)
   return false;
 }
 
-int JSON_Tokenizer::get_next_token(json_token_t* p_token, char** p_token_str, size_t* p_str_len)
+size_t JSON_Tokenizer::get_next_token(json_token_t* p_token, char** p_token_str, size_t* p_str_len)
 {
   size_t start_pos = buf_pos;
   *p_token = JSON_TOKEN_NONE;
diff --git a/common/JSON_Tokenizer.hh b/common/JSON_Tokenizer.hh
index e6d5b95ca..a3d4fef2b 100644
--- a/common/JSON_Tokenizer.hh
+++ b/common/JSON_Tokenizer.hh
@@ -145,7 +145,7 @@ public:
     * @return The number of characters extracted 
     * @note The token data is not copied, *p_token_str will point to the start of the 
     * data in the tokenizer's buffer. */
-  int get_next_token(json_token_t* p_token, char** p_token_str, size_t* p_str_len);
+  size_t get_next_token(json_token_t* p_token, char** p_token_str, size_t* p_str_len);
   
   /** Gets the current read position in the buffer.
     * This is where get_next_token() will read from next. */
diff --git a/compiler2/enum.c b/compiler2/enum.c
index 761b55e53..c45d01b88 100644
--- a/compiler2/enum.c
+++ b/compiler2/enum.c
@@ -810,7 +810,7 @@ void defEnumClass(const enum_def *edef, output_struct *output)
       "  char* value = 0;\n"
       "  size_t value_len = 0;\n"
       "  boolean error = FALSE;\n"
-      "  int dec_len = 0;\n"
+      "  size_t dec_len = 0;\n"
       "  boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();\n"
       "  if (use_default) {\n"
       // No JSON data in the buffer -> use default value
@@ -843,7 +843,7 @@ void defEnumClass(const enum_def *edef, output_struct *output)
       "    enum_value = %s;\n"
       "    return JSON_ERROR_FATAL;\n"
       "  }\n"
-      "  return dec_len;\n"
+      "  return (int)dec_len;\n"
       "}\n\n"
       , name, unknown_value, unbound_value, unbound_value);
   }
diff --git a/compiler2/record.c b/compiler2/record.c
index 51a23f827..0a0384c88 100644
--- a/compiler2/record.c
+++ b/compiler2/record.c
@@ -4419,7 +4419,7 @@ void defRecordClass1(const struct_def *sdef, output_struct *output)
       "int %s::JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, boolean p_silent)\n"
       "{\n"
       "  json_token_t j_token = JSON_TOKEN_NONE;\n"
-      "  int dec_len = p_tok.get_next_token(&j_token, NULL, NULL);\n"
+      "  size_t dec_len = p_tok.get_next_token(&j_token, NULL, NULL);\n"
       "  if (JSON_TOKEN_ERROR == j_token) {\n"
       "    JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, \"\");\n"
       "    return JSON_ERROR_FATAL;\n"
@@ -4533,7 +4533,7 @@ void defRecordClass1(const struct_def *sdef, output_struct *output)
         "           }\n"
         "           return JSON_ERROR_FATAL;\n"
         "         }\n"
-        "         dec_len += ret_val;\n"
+        "         dec_len += (size_t)ret_val;\n"
         , sdef->elements[i].dispname);
       if (has_metainfo_enabled) {
         src = mputstr(src, "        }\n");
@@ -4603,7 +4603,7 @@ void defRecordClass1(const struct_def *sdef, output_struct *output)
         "  }\n");
     }
     src = mputstr(src,
-      "\n  return dec_len;\n"
+      "\n  return (int)dec_len;\n"
       "}\n\n");
   }
   
@@ -6093,7 +6093,7 @@ static void defEmptyRecordClass(const struct_def *sdef,
       "int %s::JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, boolean p_silent)\n"
       "{\n"
       "  json_token_t token = JSON_TOKEN_NONE;\n"
-      "  int dec_len = p_tok.get_next_token(&token, NULL, NULL);\n"
+      "  size_t dec_len = p_tok.get_next_token(&token, NULL, NULL);\n"
       "  if (JSON_TOKEN_ERROR == token) {\n"
       "    JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, \"\");\n"
       "    return JSON_ERROR_FATAL;\n"
@@ -6107,7 +6107,7 @@ static void defEmptyRecordClass(const struct_def *sdef,
       "    return JSON_ERROR_FATAL;\n"
       "  }\n\n"
       "  bound_flag = TRUE;\n\n"
-      "  return dec_len;\n"
+      "  return (int)dec_len;\n"
       "}\n\n"
       , name);
   }
diff --git a/compiler2/record_of.c b/compiler2/record_of.c
index 8a6e9874c..fd4cf3675 100644
--- a/compiler2/record_of.c
+++ b/compiler2/record_of.c
@@ -1139,7 +1139,7 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
         "    if (own_tag)");
     }
     src=mputprintf(src,
-      "    {\n" /* Do empty element tag */
+      " {\n" /* Do empty element tag */
       "%s"
       "      p_buf.put_c('<');\n"
       "      if (e_xer) write_ns_prefix(p_td, p_buf);\n"
@@ -1327,7 +1327,7 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
         , force_gen_seof ? " && (p_td.xer_bits & XER_ATTRIBUTE)" : "");
     }
     src=mputstr(src,
-      "    if (own_tag){\n"
+      "    if (own_tag) {\n"
       "      p_buf.put_c('<');\n"
       "      p_buf.put_c('/');\n"
       "      if (e_xer) write_ns_prefix(p_td, p_buf);\n"
@@ -1565,7 +1565,7 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
       "int %s::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent)\n"
       "{\n"
       "  json_token_t token = JSON_TOKEN_NONE;\n"
-      "  int dec_len = p_tok.get_next_token(&token, NULL, NULL);\n"
+      "  size_t dec_len = p_tok.get_next_token(&token, NULL, NULL);\n"
       "  if (JSON_TOKEN_ERROR == token) {\n"
       "    JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, \"\");\n"
       "    return JSON_ERROR_FATAL;\n"
@@ -1576,7 +1576,7 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
       "  set_size(0);\n"
       "  for (int nof_elements = 0; TRUE; ++nof_elements) {\n"
       "    size_t buf_pos = p_tok.get_buf_pos();\n"
-      "    int ret_val;\n"
+      "    size_t ret_val;\n"
       "    if (NULL != p_td.json && p_td.json->metainfo_unbound) {\n"
       // check for metainfo object
       "      ret_val = p_tok.get_next_token(&token, NULL, NULL);\n"
@@ -1601,13 +1601,13 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
       "      p_tok.set_buf_pos(buf_pos);\n"
       "    }\n"
       "    %s* val = new %s;\n"
-      "    ret_val = val->JSON_decode(*p_td.oftype_descr, p_tok, p_silent);\n"
-      "    if (JSON_ERROR_INVALID_TOKEN == ret_val) {\n"
+      "    int ret_val2 = val->JSON_decode(*p_td.oftype_descr, p_tok, p_silent);\n"
+      "    if (JSON_ERROR_INVALID_TOKEN == ret_val2) {\n"
       "      p_tok.set_buf_pos(buf_pos);\n"
       "      delete val;\n"
       "      break;\n"
       "    }\n"
-      "    else if (JSON_ERROR_FATAL == ret_val) {\n"
+      "    else if (JSON_ERROR_FATAL == ret_val2) {\n"
       "      delete val;\n"
       "      if (p_silent) {\n"
       "        clean_up();\n"
@@ -1618,7 +1618,7 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
       "      (void**)val_ptr->value_elements, val_ptr->n_elements, nof_elements + 1);\n"
       "    val_ptr->value_elements[nof_elements] = val;\n"
       "    val_ptr->n_elements = nof_elements + 1;\n"
-      "    dec_len += ret_val;\n"
+      "    dec_len += (size_t)ret_val2;\n"
       "  }\n\n"
       "  dec_len += p_tok.get_next_token(&token, NULL, NULL);\n"
       "  if (JSON_TOKEN_ARRAY_END != token) {\n"
@@ -1628,7 +1628,7 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
       "    }\n"
       "    return JSON_ERROR_FATAL;\n"
       "  }\n\n"
-      "  return dec_len;\n"
+      "  return (int)dec_len;\n"
       "}\n\n"
       , name, type, type, type);
   }
@@ -2607,7 +2607,7 @@ void defRecordOfClassMemAllocOptimized(const struct_of_def *sdef, output_struct
         "    if (own_tag)");
     }
     src=mputprintf(src,
-      "    {\n" /* Do empty element tag */
+      " {\n" /* Do empty element tag */
       "%s"
       "      p_buf.put_c('<');\n"
       "      if (e_xer) write_ns_prefix(p_td, p_buf);\n"
@@ -2790,7 +2790,7 @@ void defRecordOfClassMemAllocOptimized(const struct_of_def *sdef, output_struct
         , force_gen_seof ? " && (p_td.xer_bits & XER_ATTRIBUTE)" : "");
     }
     src=mputstr(src,
-      "    if (own_tag){\n"
+      "    if (own_tag) {\n"
       "      p_buf.put_c('<');\n"
       "      p_buf.put_c('/');\n"
       "      if (e_xer) write_ns_prefix(p_td, p_buf);\n"
@@ -3017,7 +3017,7 @@ void defRecordOfClassMemAllocOptimized(const struct_of_def *sdef, output_struct
       "int %s::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent)\n"
       "{\n"
       "  json_token_t token = JSON_TOKEN_NONE;\n"
-      "  int dec_len = p_tok.get_next_token(&token, NULL, NULL);\n"
+      "  size_t dec_len = p_tok.get_next_token(&token, NULL, NULL);\n"
       "  if (JSON_TOKEN_ERROR == token) {\n"
       "    JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, \"\");\n"
       "    return JSON_ERROR_FATAL;\n"
@@ -3028,7 +3028,7 @@ void defRecordOfClassMemAllocOptimized(const struct_of_def *sdef, output_struct
       "  set_size(0);\n"
       "  for (int nof_elements = 0; TRUE; ++nof_elements) {\n"
       "    size_t buf_pos = p_tok.get_buf_pos();\n"
-      "    int ret_val;\n"
+      "    size_t ret_val;\n"
       "    if (NULL != p_td.json && p_td.json->metainfo_unbound) {\n"
       // check for metainfo object
       "      ret_val = p_tok.get_next_token(&token, NULL, NULL);\n"
@@ -3053,12 +3053,12 @@ void defRecordOfClassMemAllocOptimized(const struct_of_def *sdef, output_struct
       "      p_tok.set_buf_pos(buf_pos);\n"
       "    }\n"
       "    %s val;\n"
-      "    ret_val = val.JSON_decode(*p_td.oftype_descr, p_tok, p_silent);\n"
-      "    if (JSON_ERROR_INVALID_TOKEN == ret_val) {\n"
+      "    int ret_val2 = val.JSON_decode(*p_td.oftype_descr, p_tok, p_silent);\n"
+      "    if (JSON_ERROR_INVALID_TOKEN == ret_val2) {\n"
       "      p_tok.set_buf_pos(buf_pos);\n"
       "      break;\n"
       "    }\n"
-      "    else if (JSON_ERROR_FATAL == ret_val) {\n"
+      "    else if (JSON_ERROR_FATAL == ret_val2) {\n"
       "      if (p_silent) {\n"
       "        clean_up();\n"
       "      }\n"
@@ -3066,7 +3066,7 @@ void defRecordOfClassMemAllocOptimized(const struct_of_def *sdef, output_struct
       "    }\n"
       "    set_size(nof_elements + 1);\n"
       "    value_elements[nof_elements] = val;\n"
-      "    dec_len += ret_val;\n"
+      "    dec_len += (size_t)ret_val2;\n"
       "  }\n\n"
       "  dec_len += p_tok.get_next_token(&token, NULL, NULL);\n"
       "  if (JSON_TOKEN_ARRAY_END != token) {\n"
@@ -3076,7 +3076,7 @@ void defRecordOfClassMemAllocOptimized(const struct_of_def *sdef, output_struct
       "    }\n"
       "    return JSON_ERROR_FATAL;\n"
       "  }\n\n"
-      "  return dec_len;\n"
+      "  return (int)dec_len;\n"
       "}\n\n"
       , name, type);
   }
diff --git a/compiler2/union.c b/compiler2/union.c
index 4cd7e6ed5..7f3e175bb 100644
--- a/compiler2/union.c
+++ b/compiler2/union.c
@@ -1379,7 +1379,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
       if (sdef->xerUseUnion || i > 0) src = mputprintf(src,
           "      need_type = (%s_xer_.namelens[1] > 2) || %s_xer_.xsd_type != XSD_NONE;\n"
           , sdef->elements[i].typegen
-          , sdef->elements[i].typegen);
+        , sdef->elements[i].typegen);
       src = mputstr(src, "      break;\n");
     }
 
@@ -1459,18 +1459,18 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
           , selection_prefix, sdef->elements[i].name);
         if (!sdef->xerUseUnion) { // UseType
           src = mputprintf(src,
-            "      if (%s_xer_.my_module != 0 && %s_xer_.ns_index != -1 &&\n"
-            "          %s_xer_.namelens[1] > 2) {\n"
-            /* add the namespace prefix to the type attribute (if the name is not empty) */
-            "        const namespace_t *my_ns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
-            "        if (my_ns->px[0] != 0) {\n"
-            "          type_name = mprintf(\"%%s:\", my_ns->px);\n"
-            "        }\n"
-            "      }\n"
-            "      type_name = mputstrn(type_name, %s_xer_.names[1], %s_xer_.namelens[1] - 2);\n"
-            , sdef->elements[i].typegen, sdef->elements[i].typegen
-            , sdef->elements[i].typegen, sdef->elements[i].typegen
-            , sdef->elements[i].typegen, sdef->elements[i].typegen
+          "      if (%s_xer_.my_module != 0 && %s_xer_.ns_index != -1 &&\n"
+          "          %s_xer_.namelens[1] > 2) {\n"
+          /* add the namespace prefix to the type attribute (if the name is not empty) */
+          "        const namespace_t *my_ns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
+          "        if (my_ns->px[0] != 0) {\n"
+          "          type_name = mprintf(\"%%s:\", my_ns->px);\n"
+          "        }\n"
+          "      }\n"
+          "      type_name = mputstrn(type_name, %s_xer_.names[1], %s_xer_.namelens[1] - 2);\n"
+          , sdef->elements[i].typegen, sdef->elements[i].typegen
+          , sdef->elements[i].typegen, sdef->elements[i].typegen
+          , sdef->elements[i].typegen, sdef->elements[i].typegen
             , sdef->elements[i].typegen);
         }
         if (sdef->elements[i].xsd_type != XSD_NONE) {
@@ -1600,18 +1600,18 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
             , selection_prefix, sdef->elements[i].name);
           if (!sdef->xerUseUnion) { // UseType
             src = mputprintf(src,
-              "      if (%s_xer_.my_module != 0 && %s_xer_.ns_index != -1 &&\n"
-              "          %s_xer_.namelens[1] > 2) {\n"
-              /* add the namespace prefix to the type attribute (if the name is not empty) */
-              "        const namespace_t *my_ns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
-              "        if (my_ns->px[0] != 0) {\n"
-              "          type_name = mprintf(\"%%s:\", my_ns->px);\n"
-              "        }\n"
-              "      }\n"
-              "      type_name = mputstrn(type_name, %s_xer_.names[1], %s_xer_.namelens[1] - 2);\n"
-              , sdef->elements[i].typegen, sdef->elements[i].typegen
-              , sdef->elements[i].typegen, sdef->elements[i].typegen
-              , sdef->elements[i].typegen, sdef->elements[i].typegen
+            "      if (%s_xer_.my_module != 0 && %s_xer_.ns_index != -1 &&\n"
+            "          %s_xer_.namelens[1] > 2) {\n"
+            /* add the namespace prefix to the type attribute (if the name is not empty) */
+            "        const namespace_t *my_ns = %s_xer_.my_module->get_ns(%s_xer_.ns_index);\n"
+            "        if (my_ns->px[0] != 0) {\n"
+            "          type_name = mprintf(\"%%s:\", my_ns->px);\n"
+            "        }\n"
+            "      }\n"
+            "      type_name = mputstrn(type_name, %s_xer_.names[1], %s_xer_.namelens[1] - 2);\n"
+            , sdef->elements[i].typegen, sdef->elements[i].typegen
+            , sdef->elements[i].typegen, sdef->elements[i].typegen
+            , sdef->elements[i].typegen, sdef->elements[i].typegen
               , sdef->elements[i].typegen);
           }
           if (sdef->elements[i].xsd_type != XSD_NONE) {
@@ -2205,7 +2205,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
         "}\n\n");
     } else { // not "as value"
       src = mputprintf(src,
-        "  int dec_len = p_tok.get_next_token(&j_token, NULL, NULL);\n"
+        "  size_t dec_len = p_tok.get_next_token(&j_token, NULL, NULL);\n"
         "  if (JSON_TOKEN_ERROR == j_token) {\n"
         "    JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, \"\");\n"
         "    return JSON_ERROR_FATAL;\n"
@@ -2232,7 +2232,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
           "        }\n"
           "        return JSON_ERROR_FATAL;\n"
           "      } else {\n"
-          "        dec_len += ret_val;\n"
+          "        dec_len += (size_t)ret_val;\n"
           "      }\n"
           "    } else "
           , sdef->elements[i].jsonAlias ? sdef->elements[i].jsonAlias : sdef->elements[i].dispname
@@ -2252,7 +2252,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
         "    JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_STATIC_OBJECT_END_TOKEN_ERROR, \"\");\n"
         "    return JSON_ERROR_FATAL;\n"
         "  }\n\n"
-        "  return dec_len;\n"
+        "  return (int)dec_len;\n"
         "}\n\n");
     }
   }
diff --git a/core/ASN_Null.cc b/core/ASN_Null.cc
index e804d9404..ef8c4e07c 100644
--- a/core/ASN_Null.cc
+++ b/core/ASN_Null.cc
@@ -307,7 +307,7 @@ int ASN_NULL::JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok) c
 int ASN_NULL::JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, boolean p_silent)
 {
   json_token_t token = JSON_TOKEN_NONE;
-  int dec_len = p_tok.get_next_token(&token, NULL, NULL);
+  size_t dec_len = p_tok.get_next_token(&token, NULL, NULL);
   if (JSON_TOKEN_ERROR == token) {
     JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, "");
     return JSON_ERROR_FATAL;
@@ -316,7 +316,7 @@ int ASN_NULL::JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, b
     return JSON_ERROR_INVALID_TOKEN;
   }
   bound_flag = TRUE;
-  return dec_len;
+  return (int)dec_len;
 }
 
 boolean operator==(asn_null_type, const ASN_NULL& other_value)
diff --git a/core/Array.hh b/core/Array.hh
index 5012c95d8..2531ef95a 100644
--- a/core/Array.hh
+++ b/core/Array.hh
@@ -549,7 +549,7 @@ int VALUE_ARRAY<T_type,array_size,index_offset>::JSON_decode(
   const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent)
 {
   json_token_t token = JSON_TOKEN_NONE;
-  int dec_len = p_tok.get_next_token(&token, NULL, NULL);
+  size_t dec_len = p_tok.get_next_token(&token, NULL, NULL);
   if (JSON_TOKEN_ERROR == token) {
     JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, "");
     return JSON_ERROR_FATAL;
@@ -560,7 +560,7 @@ int VALUE_ARRAY<T_type,array_size,index_offset>::JSON_decode(
   
   for (unsigned int i = 0; i < array_size; ++i) {
     size_t buf_pos = p_tok.get_buf_pos();
-    int ret_val;
+    size_t ret_val;
     if (NULL != p_td.json && p_td.json->metainfo_unbound) {
       // check for metainfo object
       ret_val = p_tok.get_next_token(&token, NULL, NULL);
@@ -584,19 +584,19 @@ int VALUE_ARRAY<T_type,array_size,index_offset>::JSON_decode(
       // metainfo object not found, jump back and let the element type decode it
       p_tok.set_buf_pos(buf_pos);
     }
-    ret_val = array_elements[i].JSON_decode(*get_elem_descr(), p_tok, p_silent);
-    if (JSON_ERROR_INVALID_TOKEN == ret_val) {
+    int ret_val2 = array_elements[i].JSON_decode(*get_elem_descr(), p_tok, p_silent);
+    if (JSON_ERROR_INVALID_TOKEN == ret_val2) {
       JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_ARRAY_ELEM_TOKEN_ERROR,
         array_size - i, (array_size - i > 1) ? "s" : "");
       return JSON_ERROR_FATAL;
     } 
-    else if (JSON_ERROR_FATAL == ret_val) {
+    else if (JSON_ERROR_FATAL == ret_val2) {
       if (p_silent) {
         clean_up();
       }
       return JSON_ERROR_FATAL;
     }
-    dec_len += ret_val;
+    dec_len += (size_t)ret_val2;
   }
   
   dec_len += p_tok.get_next_token(&token, NULL, NULL);
diff --git a/core/Bitstring.cc b/core/Bitstring.cc
index ace5b3707..7dd470baa 100644
--- a/core/Bitstring.cc
+++ b/core/Bitstring.cc
@@ -1189,7 +1189,7 @@ int BITSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_
   char* value = 0;
   size_t value_len = 0;
   boolean error = FALSE;
-  int dec_len = 0;
+  size_t dec_len = 0;
   boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();
   if (use_default) {
     // No JSON data in the buffer -> use default value
@@ -1232,7 +1232,7 @@ int BITSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_
     }
     return JSON_ERROR_FATAL;    
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 
diff --git a/core/Boolean.cc b/core/Boolean.cc
index a36cd0df4..df037f74a 100644
--- a/core/Boolean.cc
+++ b/core/Boolean.cc
@@ -746,7 +746,7 @@ int BOOLEAN::JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok) co
 int BOOLEAN::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent)
 {
   json_token_t token = JSON_TOKEN_NONE;
-  int dec_len = 0;
+  size_t dec_len = 0;
   if (p_td.json->default_value && 0 == p_tok.get_buffer_length()) {
     // No JSON data in the buffer -> use default value
     if (strcmp(p_td.json->default_value, "true") == 0) {
@@ -774,7 +774,7 @@ int BOOLEAN::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_to
     bound_flag = FALSE;
     return JSON_ERROR_INVALID_TOKEN;
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 
diff --git a/core/Charstring.cc b/core/Charstring.cc
index 260b9be70..13afe2c2a 100644
--- a/core/Charstring.cc
+++ b/core/Charstring.cc
@@ -1733,7 +1733,7 @@ int CHARSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p
   json_token_t token = JSON_TOKEN_NONE;
   char* value = 0;
   size_t value_len = 0;
-  int dec_len = 0;
+  size_t dec_len = 0;
   boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();
   if (use_default) {
     // No JSON data in the buffer -> use default value
@@ -1755,7 +1755,7 @@ int CHARSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p
   } else {
     return JSON_ERROR_INVALID_TOKEN;
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 
diff --git a/core/Float.cc b/core/Float.cc
index b8021cdc9..b4ea60745 100644
--- a/core/Float.cc
+++ b/core/Float.cc
@@ -1111,7 +1111,7 @@ int FLOAT::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok,
   json_token_t token = JSON_TOKEN_NONE;
   char* value = 0;
   size_t value_len = 0;
-  int dec_len = 0;
+  size_t dec_len = 0;
   boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();
   if (use_default) {
     // No JSON data in the buffer -> use default value
@@ -1165,7 +1165,7 @@ int FLOAT::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok,
     bound_flag = TRUE;
     Free(value2);
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 
diff --git a/core/Hexstring.cc b/core/Hexstring.cc
index d2b3e022d..1515b3de9 100644
--- a/core/Hexstring.cc
+++ b/core/Hexstring.cc
@@ -1079,7 +1079,7 @@ int HEXSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_
   char* value = 0;
   size_t value_len = 0;
   boolean error = FALSE;
-  int dec_len = 0;
+  size_t dec_len = 0;
   boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();
   if (use_default) {
     // No JSON data in the buffer -> use default value
@@ -1122,7 +1122,7 @@ int HEXSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_
     }
     return JSON_ERROR_FATAL;    
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 
diff --git a/core/Integer.cc b/core/Integer.cc
index dc6442f7d..2850f7d11 100644
--- a/core/Integer.cc
+++ b/core/Integer.cc
@@ -1738,7 +1738,7 @@ int INTEGER::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_to
   json_token_t token = JSON_TOKEN_NONE;
   char* value = 0;
   size_t value_len = 0;
-  int dec_len = 0;
+  size_t dec_len = 0;
   boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();
   if (use_default) {
     // No JSON data in the buffer -> use default value
@@ -1765,7 +1765,7 @@ int INTEGER::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_to
     bound_flag = FALSE;
     return JSON_ERROR_INVALID_TOKEN;
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 
@@ -2104,9 +2104,9 @@ boolean INTEGER_template::match(int other_value, boolean /* legacy */) const
     // Lower boundary is set.
     if (!lower_boundary) {
       if (!value_range.min_is_exclusive) {
-        lower_boundary = (likely(value_range.min_value.native_flag) ?
-          int_val_t(value_range.min_value.val.native) :
-            int_val_t(BN_dup(value_range.min_value.val.openssl))) <= other_value;
+      lower_boundary = (likely(value_range.min_value.native_flag) ?
+        int_val_t(value_range.min_value.val.native) :
+          int_val_t(BN_dup(value_range.min_value.val.openssl))) <= other_value;
       } else {
         lower_boundary = (likely(value_range.min_value.native_flag) ?
         int_val_t(value_range.min_value.val.native) :
@@ -2116,9 +2116,9 @@ boolean INTEGER_template::match(int other_value, boolean /* legacy */) const
     // Upper boundary is set.
     if (!upper_boundary) {
       if (!value_range.max_is_exclusive) {
-        upper_boundary = (likely(value_range.max_value.native_flag) ?
-          int_val_t(value_range.max_value.val.native) :
-            int_val_t(BN_dup(value_range.max_value.val.openssl))) >= other_value;
+      upper_boundary = (likely(value_range.max_value.native_flag) ?
+        int_val_t(value_range.max_value.val.native) :
+          int_val_t(BN_dup(value_range.max_value.val.openssl))) >= other_value;
       } else {
         upper_boundary = (likely(value_range.max_value.native_flag) ?
         int_val_t(value_range.max_value.val.native) :
@@ -2177,8 +2177,8 @@ boolean INTEGER_template::match(const INTEGER& other_value,
         } else {
           upper_boundary = (likely(value_range.max_value.native_flag) ?
             int_val_t(value_range.max_value.val.native) :
-              int_val_t(BN_dup(value_range.max_value.val.openssl))) >= other_value.get_val();
-        }
+            int_val_t(BN_dup(value_range.max_value.val.openssl))) >= other_value.get_val();
+      }
       }
       return lower_boundary && upper_boundary; }
     default:
diff --git a/core/Objid.cc b/core/Objid.cc
index ee8b4bcb0..522c7a6ca 100644
--- a/core/Objid.cc
+++ b/core/Objid.cc
@@ -622,7 +622,7 @@ int OBJID::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok,
   char* value = 0;
   size_t value_len = 0;
   boolean error = FALSE;
-  int dec_len = 0;
+  size_t dec_len = 0;
   boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();
   if (use_default) {
     // No JSON data in the buffer -> use default value
@@ -659,7 +659,7 @@ int OBJID::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok,
     }
     return JSON_ERROR_FATAL;    
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 void OBJID_template::clean_up()
diff --git a/core/Octetstring.cc b/core/Octetstring.cc
index 0ee71520f..4f5ef7b9c 100644
--- a/core/Octetstring.cc
+++ b/core/Octetstring.cc
@@ -1302,7 +1302,7 @@ int OCTETSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&
   char* value = 0;
   size_t value_len = 0;
   boolean error = FALSE;
-  int dec_len = 0;
+  size_t dec_len = 0;
   boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();
   if (use_default) {
     // No JSON data in the buffer -> use default value
@@ -1348,7 +1348,7 @@ int OCTETSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&
     }
     return JSON_ERROR_FATAL;    
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 // octetstring element class
diff --git a/core/Optional.hh b/core/Optional.hh
index 2900d5fc8..becc7ec38 100644
--- a/core/Optional.hh
+++ b/core/Optional.hh
@@ -873,13 +873,13 @@ int OPTIONAL<T_type>::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokeni
     // able to decode a "null" value
     p_tok.set_buf_pos(buf_pos);
     json_token_t token = JSON_TOKEN_NONE;
-    dec_len = p_tok.get_next_token(&token, NULL, NULL);
+    p_tok.get_next_token(&token, NULL, NULL);
     if (JSON_TOKEN_LITERAL_NULL == token) {
       set_to_omit();
     }
     else {
       // cannot get JSON_TOKEN_ERROR here, that was already checked by the optional value
-      dec_len = JSON_ERROR_INVALID_TOKEN;
+      return JSON_ERROR_INVALID_TOKEN;
     }
   }
   return dec_len;
diff --git a/core/Universal_charstring.cc b/core/Universal_charstring.cc
index eefcb9190..0bb572077 100644
--- a/core/Universal_charstring.cc
+++ b/core/Universal_charstring.cc
@@ -2536,7 +2536,7 @@ int UNIVERSAL_CHARSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_To
   json_token_t token = JSON_TOKEN_NONE;
   char* value = 0;
   size_t value_len = 0;
-  int dec_len = 0;
+  size_t dec_len = 0;
   boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();
   if (use_default) {
     // No JSON data in the buffer -> use default value
@@ -2567,7 +2567,7 @@ int UNIVERSAL_CHARSTRING::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_To
   } else {
     return JSON_ERROR_INVALID_TOKEN;
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 
diff --git a/core/Verdicttype.cc b/core/Verdicttype.cc
index 592d8c871..26be2197b 100644
--- a/core/Verdicttype.cc
+++ b/core/Verdicttype.cc
@@ -385,7 +385,7 @@ int VERDICTTYPE::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&
   json_token_t token = JSON_TOKEN_NONE;
   char* value = 0;
   size_t value_len = 0;
-  int dec_len = 0;
+  size_t dec_len = 0;
   boolean use_default = p_td.json->default_value && 0 == p_tok.get_buffer_length();
   if (use_default) {
     // No JSON data in the buffer -> use default value
@@ -417,14 +417,14 @@ int VERDICTTYPE::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&
   } else {
     error = FALSE;
     verdict_value = UNBOUND_VERDICT;
-    dec_len = JSON_ERROR_INVALID_TOKEN;
+    return JSON_ERROR_INVALID_TOKEN;
   }
   if (error) {
     JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_FORMAT_ERROR, "string", "verdicttype");
     verdict_value = UNBOUND_VERDICT;
-    dec_len = JSON_ERROR_FATAL;
+    return JSON_ERROR_FATAL;
   }
-  return dec_len;
+  return (int)dec_len;
 }
 
 
diff --git a/core2/Basetype2.cc b/core2/Basetype2.cc
index 86533d1b6..e889ceb2e 100644
--- a/core2/Basetype2.cc
+++ b/core2/Basetype2.cc
@@ -1574,7 +1574,7 @@ int Record_Of_Type::JSON_encode_negtest(const Erroneous_descriptor_t* p_err_desc
 int Record_Of_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent)
 {
   json_token_t token = JSON_TOKEN_NONE;
-  int dec_len = p_tok.get_next_token(&token, NULL, NULL);
+  size_t dec_len = p_tok.get_next_token(&token, NULL, NULL);
   if (JSON_TOKEN_ERROR == token) {
     JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, "");
     return JSON_ERROR_FATAL;
@@ -1587,7 +1587,7 @@ int Record_Of_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenize
   for (int nof_elements = 0; TRUE; ++nof_elements) {
     // Read value tokens until we reach some other token
     size_t buf_pos = p_tok.get_buf_pos();
-    int ret_val;
+    size_t ret_val;
     if (NULL != p_td.json && p_td.json->metainfo_unbound) {
       // check for metainfo object
       ret_val = p_tok.get_next_token(&token, NULL, NULL);
@@ -1612,14 +1612,14 @@ int Record_Of_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenize
       p_tok.set_buf_pos(buf_pos);
     }
     Base_Type* val = create_elem();
-    ret_val = val->JSON_decode(*p_td.oftype_descr, p_tok, p_silent);
-    if (JSON_ERROR_INVALID_TOKEN == ret_val) {
+    int ret_val2 = val->JSON_decode(*p_td.oftype_descr, p_tok, p_silent);
+    if (JSON_ERROR_INVALID_TOKEN == ret_val2) {
       // undo the last action on the buffer
       p_tok.set_buf_pos(buf_pos);
       delete val;
       break;
     } 
-    else if (JSON_ERROR_FATAL == ret_val) {
+    else if (JSON_ERROR_FATAL == ret_val2) {
       delete val;
       if (p_silent) {
         clean_up();
@@ -1636,7 +1636,7 @@ int Record_Of_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenize
       get_at(nof_elements)->set_value(val);
       delete val;
     }
-    dec_len += ret_val;
+    dec_len += (size_t)ret_val2;
   }
   
   dec_len += p_tok.get_next_token(&token, NULL, NULL);
@@ -1648,7 +1648,7 @@ int Record_Of_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenize
     return JSON_ERROR_FATAL;
   }
   
-  return dec_len;
+  return (int)dec_len;
 }
 
 void Record_Of_Type::encode(const TTCN_Typedescriptor_t& p_td,
@@ -5889,7 +5889,7 @@ int Record_Type::JSON_encode_negtest(const Erroneous_descriptor_t* p_err_descr,
 int Record_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok, boolean p_silent)
 {
   json_token_t token = JSON_TOKEN_NONE;
-  int dec_len = p_tok.get_next_token(&token, NULL, NULL);
+  size_t dec_len = p_tok.get_next_token(&token, NULL, NULL);
   if (JSON_TOKEN_ERROR == token) {
     JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, "");
     return JSON_ERROR_FATAL;
@@ -5990,9 +5990,9 @@ int Record_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&
       }
       else {
         buf_pos = p_tok.get_buf_pos();
-        int ret_val = get_at(field_idx)->JSON_decode(*fld_descr(field_idx), p_tok, p_silent);
-        if (0 > ret_val) {
-          if (JSON_ERROR_INVALID_TOKEN == ret_val) {
+        int ret_val2 = get_at(field_idx)->JSON_decode(*fld_descr(field_idx), p_tok, p_silent);
+        if (0 > ret_val2) {
+          if (JSON_ERROR_INVALID_TOKEN == ret_val2) {
             // undo the last action on the buffer, check if the invalid token was a null token 
             p_tok.set_buf_pos(buf_pos);
             p_tok.get_next_token(&token, NULL, NULL);
@@ -6011,7 +6011,7 @@ int Record_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&
           }
           return JSON_ERROR_FATAL;
         }
-        dec_len += ret_val;
+        dec_len += (size_t)ret_val2;
       }
     }
   }
@@ -6047,7 +6047,7 @@ int Record_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&
   
   delete[] metainfo;
   
-  return dec_len;
+  return (int)dec_len;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -6403,7 +6403,7 @@ int Empty_Record_Type::JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&
 int Empty_Record_Type::JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok, boolean p_silent)
 {
   json_token_t token = JSON_TOKEN_NONE;
-  int dec_len = p_tok.get_next_token(&token, NULL, NULL);
+  size_t dec_len = p_tok.get_next_token(&token, NULL, NULL);
   if (JSON_TOKEN_ERROR == token) {
     JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_BAD_TOKEN_ERROR, "");
     return JSON_ERROR_FATAL;
@@ -6420,7 +6420,7 @@ int Empty_Record_Type::JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&
   
   bound_flag = TRUE;
   
-  return dec_len;
+  return (int)dec_len;
 }
 
 boolean operator==(null_type /*null_value*/, const Empty_Record_Type& other_value)
-- 
GitLab