Fix mlw_codec build warnings

Fixed mlw_codec build warnings.

Signed-off-by: Fredrik Svedberg <fredrik.svedberg@arm.com>
Change-Id: I8ec8fb3b092cce0629c690677984549febf01adc
diff --git a/ethosu/mlw_codec/mlw_codecmodule.c b/ethosu/mlw_codec/mlw_codecmodule.c
index 75ea8e9..b752a4e 100644
--- a/ethosu/mlw_codec/mlw_codecmodule.c
+++ b/ethosu/mlw_codec/mlw_codecmodule.c
@@ -178,7 +178,7 @@
 
   /* Unpack the length of the input integer list.  */
   Py_ssize_t input_length = PyObject_Length (input_list_object);
-  if (input_length < 0) {
+  if (input_length < 0 || input_length > INT32_MAX) {
     return NULL;
   }
 
@@ -202,14 +202,14 @@
         PyErr_SetString(PyExc_ValueError, "Input value out of bounds");
         return NULL;
       }
-      input_buffer[i] = value;
+      input_buffer[i] = (int16_t)value;
     }
   if (PyErr_Occurred() != NULL) {
     PyErr_SetString(PyExc_ValueError, "Invalid input");
     return NULL;
   }
 
-  int output_length = mlw_encode(input_buffer, input_length, &output_buffer, verbose);
+  int output_length = mlw_encode(input_buffer, (int)input_length, &output_buffer, verbose);
 
   PyObject *output_byte_array = PyByteArray_FromStringAndSize ((char *) output_buffer, output_length);
 
@@ -253,6 +253,9 @@
   /* Unpack the input buffer and length from the bytearray object.  */
   uint8_t *input_buffer = (uint8_t *) PyByteArray_AsString(input_bytearray_object);
   Py_ssize_t input_length = PyByteArray_Size(input_bytearray_object);
+  if (input_length < 0 || input_length > INT32_MAX) {
+    return NULL;
+  }
 
   /* We don't know the output length required, we guess, but the guess
    * will be too small, the mlw_decode call will do a resize (upwards)
@@ -262,7 +265,7 @@
   if (output_buffer == NULL)
     return PyErr_NoMemory();
 
-  int output_length = mlw_decode (input_buffer, input_length, &output_buffer, verbose);
+  int output_length = mlw_decode (input_buffer, (int)input_length, &output_buffer, verbose);
 
   /* Construct a new integer list and marshall the output buffer
    * contents into the list.  */
diff --git a/ethosu/mlw_codec/mlw_encode.c b/ethosu/mlw_codec/mlw_encode.c
index 3a03091..cac5e98 100644
--- a/ethosu/mlw_codec/mlw_encode.c
+++ b/ethosu/mlw_codec/mlw_encode.c
@@ -1101,9 +1101,9 @@
 
     /* Then encode */
     int output_length = 0;
-    if (*padded_length > 0)
+    if (*padded_length > 0 && *padded_length <= INT32_MAX)
     {
-        output_length = mlw_encode(weights, *padded_length, outbuf, verbose);
+        output_length = mlw_encode(weights, (int)*padded_length, outbuf, verbose);
     }
     reorder_free(weights);