Refactoring. Integrate converting string to unsigned int 25/276625/8
authorjiyong.min <jiyong.min@samsung.com>
Wed, 22 Jun 2022 06:36:53 +0000 (15:36 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 27 Jun 2022 22:57:25 +0000 (07:57 +0900)
Change-Id: Ie6dc2ac3c2d3b88998460715daaefa1e03cab298

common/include/mm_util_private.h
common/mm_util_private.c
gif/test/mm_util_gif_testsuite.c
heif/test/mm_util_heif_testsuite.c
imgp/test/mm_util_imgp_testsuite.c
jpeg/test/mm_util_jpeg_testsuite.c
jxl/test/mm_util_jxl_testsuite.c

index 091f62d..55f49a1 100644 (file)
@@ -91,6 +91,10 @@ int mm_util_file_write(const char *path, void *data, size_t size);
 // for reading ini
 int mm_util_ini_get_int(const char *category, const char *item, int default_value);
 
+// for testsuites
+gboolean mm_util_safe_str_to_uint(const char *str, unsigned int *number);
+gboolean mm_util_safe_str_to_valid_uint(const char *str, unsigned int min, unsigned int max, unsigned int *value);
+
 #ifdef __cplusplus
 }
 #endif
index 5a7d14b..8688e7c 100644 (file)
@@ -153,3 +153,36 @@ int mm_util_ini_get_int(const char *category, const char *item, int default_valu
 
        return val;
 }
+
+gboolean mm_util_safe_str_to_uint(const char *str, unsigned int *number)
+{
+       gint64 temp = 0;
+
+       if (!str || strlen(str) == 0)
+               return FALSE;
+
+       temp = g_ascii_strtoll(str, NULL, 10);
+       if (errno != 0) {
+               mm_util_stderror("g_ascii_strtoll");
+               return FALSE;
+       }
+
+       if (temp < 0 || temp > UINT_MAX)
+               return FALSE;
+
+       *number  = (unsigned int)temp;
+
+       return TRUE;
+}
+
+gboolean mm_util_safe_str_to_valid_uint(const char *str, unsigned int min, unsigned int max, unsigned int *value)
+{
+       unsigned int converted = 0;
+       gboolean is_num = mm_util_safe_str_to_uint(str, &converted);
+
+       if (!is_num || converted < min || converted > max)
+               return FALSE;
+
+       *value = converted;
+       return TRUE;
+}
index 7084e13..02da2d6 100644 (file)
@@ -58,7 +58,7 @@ static char *MODE_TO_STR[] = {
 };
 
 /* for arguments */
-static int g_test_mode = 0;
+static unsigned int g_test_mode = 0;
 static char *g_path = NULL;
 static unsigned int g_width = 0;
 static unsigned int g_height = 0;
@@ -69,20 +69,6 @@ static size_t g_read_size = 0;
 
 static mm_util_image_h g_decoded_data = NULL;
 
-gboolean _get_input_data(const char *argv, const long min, const long max, int *data)
-{
-       if (argv == NULL || strlen(argv) == 0)
-               return FALSE;
-
-       long temp = g_ascii_strtoll(argv, NULL, 10);
-       if (temp < min || temp > max)
-               return FALSE;
-
-       *data  = (int)temp;
-
-       return TRUE;
-}
-
 void _print_help(const char *argv0)
 {
        fprintf(stderr, "\t[usage]\n");
@@ -94,9 +80,7 @@ void _print_help(const char *argv0)
 
 gboolean _get_arguments(int argc, char *argv[])
 {
-       int width = 0, height = 0;
-
-       if (FALSE == _get_input_data(argv[1], TEST_AUTO, TEST_NUM - 1, &g_test_mode)) {
+       if (FALSE == mm_util_safe_str_to_valid_uint(argv[1], TEST_AUTO, TEST_NUM - 1, &g_test_mode)) {
                fprintf(stderr, "\t[GIF_testsuite] wrong mode(%s) for test\n", argv[1]);
                _print_help(argv[0]);
                return FALSE;
@@ -112,16 +96,15 @@ gboolean _get_arguments(int argc, char *argv[])
                        _print_help(argv[0]);
                        return FALSE;
                }
-               if (FALSE == _get_input_data(argv[3], 0, INT_MAX, &width)) {
+               if (FALSE == mm_util_safe_str_to_uint(argv[3], &g_width)) {
                        fprintf(stderr, "\t[GIF_testsuite] wrong width %s\n", argv[3]);
                        return FALSE;
                }
-               g_width = (unsigned int)width;
-               if (FALSE == _get_input_data(argv[4], 0, INT_MAX, &height)) {
+
+               if (FALSE == mm_util_safe_str_to_uint(argv[4], &g_height)) {
                        fprintf(stderr, "\t[GIF_testsuite] wrong height %s\n", argv[4]);
                        return FALSE;
                }
-               g_height = (unsigned int)height;
        } else {
                fprintf(stderr, "\t[GIF_testsuite] wrong mode for test %s\n", argv[1]);
                return FALSE;
index ba2db2d..2f783e1 100644 (file)
@@ -42,9 +42,9 @@ static char *MODE_TO_STR[] = {
 };
 
 /* for arguments */
-static int g_test_mode = 0;
+static unsigned int g_test_mode = 0;
 static char *g_path = NULL;
-static int g_color = MM_UTIL_COLOR_RGB24;
+static unsigned int g_color = MM_UTIL_COLOR_RGB24;
 
 /* for reading file */
 static void *g_read_data = NULL;
@@ -97,23 +97,6 @@ static const char *g_test_filename[TEST_NUM][MM_UTIL_COLOR_NUM] = {
 
 static mm_util_image_h g_decoded_data = NULL;
 
-static gboolean __get_input_data(const char *argv, const long min, const long max, int *data)
-{
-       if (!argv || strlen(argv) == 0)
-               return FALSE;
-
-       if (!data)
-               return FALSE;
-
-       long temp = g_ascii_strtoll(argv, NULL, 10);
-       if (temp < min || temp > max)
-               return FALSE;
-
-       *data  = (int)temp;
-
-       return TRUE;
-}
-
 static void __print_help(const char *argv0)
 {
        g_print("\t[usage]\n");
@@ -125,7 +108,7 @@ static void __print_help(const char *argv0)
 
 static gboolean __get_arguments(int argc, char *argv[])
 {
-       if (!__get_input_data(argv[1], TEST_AUTO, TEST_NUM - 1, &g_test_mode)) {
+       if (!mm_util_safe_str_to_valid_uint(argv[1], TEST_AUTO, TEST_NUM - 1, &g_test_mode)) {
                g_print("\t[HEIF_testsuite] wrong mode(%s) for test\n", argv[1]);
                __print_help(argv[0]);
                return FALSE;
@@ -136,10 +119,10 @@ static gboolean __get_arguments(int argc, char *argv[])
        if (g_test_mode == TEST_AUTO) {
                // do nothing
        } else if (g_test_mode == TEST_DECODE_FILE) {
-               if (!__get_input_data(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
+               if (!mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
                        g_print("\t[HEIF_testsuite] color is default(%d)\n", g_color);
        } else if (g_test_mode == TEST_DECODE_BUFFER) {
-               if (!__get_input_data(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
+               if (!mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
                        g_print("\t[HEIF_testsuite] color is default(%d)\n", g_color);
        } else {
                g_print("\t[HEIF_testsuite] wrong mode for test %s\n", argv[1]);
index 8954973..dbd265a 100644 (file)
@@ -65,21 +65,6 @@ typedef struct {
 static input_params g_args;
 static output_values g_transformed;
 
-gboolean _get_input_data(const char *argv, const unsigned long min, const unsigned long max, unsigned int *data)
-{
-       if (argv == NULL || strlen(argv) == 0)
-               return FALSE;
-
-       unsigned long temp = g_ascii_strtoll(argv, NULL, 10);
-
-       if (temp < min || temp > max)
-               return FALSE;
-
-       *data  = (unsigned int)temp;
-
-       return TRUE;
-}
-
 void _print_help(const char *argv0)
 {
        fprintf(stderr, "\t[usage]\n");
@@ -102,15 +87,15 @@ gboolean _get_arguments(int argc, char *argv[])
        g_args.path = g_strdup(argv[index++]);
        g_args.cmd = g_strdup(argv[index++]);
 
-       if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.width)) {
+       if (FALSE == mm_util_safe_str_to_uint(argv[index++], &g_args.width)) {
                fprintf(stderr, "\t[IMGP_testsuite] wrong src_width %s\n", argv[index-1]);
                return FALSE;
        }
-       if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.height)) {
+       if (FALSE == mm_util_safe_str_to_uint(argv[index++], &g_args.height)) {
                fprintf(stderr, "\t[IMGP_testsuite] wrong src_height %s\n", argv[index-1]);
                return FALSE;
        }
-       if (FALSE == _get_input_data(argv[index++], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_args.colorspace)) {
+       if (FALSE == mm_util_safe_str_to_valid_uint(argv[index++], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_args.colorspace)) {
                fprintf(stderr, "\t[IMGP_testsuite] wrong src_format %s\n", argv[index-1]);
                return FALSE;
        }
@@ -120,7 +105,7 @@ gboolean _get_arguments(int argc, char *argv[])
                        return FALSE;
                }
 
-               if (FALSE == _get_input_data(argv[index++], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_args.cs)) {
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[index++], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_args.cs)) {
                        fprintf(stderr, "\t[IMGP_testsuite] wrong dst_format %s\n", argv[index-1]);
                        return FALSE;
                }
@@ -130,11 +115,11 @@ gboolean _get_arguments(int argc, char *argv[])
                        return FALSE;
                }
 
-               if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.w)) {
+               if (FALSE == mm_util_safe_str_to_uint(argv[index++], &g_args.w)) {
                        fprintf(stderr, "\t[IMGP_testsuite] wrong dst_width %s\n", argv[index-1]);
                        return FALSE;
                }
-               if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.h)) {
+               if (FALSE == mm_util_safe_str_to_uint(argv[index++], &g_args.h)) {
                        fprintf(stderr, "\t[IMGP_testsuite] wrong dst_height %s\n", argv[index-1]);
                        return FALSE;
                }
@@ -144,7 +129,7 @@ gboolean _get_arguments(int argc, char *argv[])
                        return FALSE;
                }
 
-               if (FALSE == _get_input_data(argv[index++], MM_UTIL_ROTATE_0, MM_UTIL_ROTATE_NUM - 1, &g_args.rot)) {
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[index++], MM_UTIL_ROTATE_0, MM_UTIL_ROTATE_NUM - 1, &g_args.rot)) {
                        fprintf(stderr, "\t[IMGP_testsuite] wrong rotation %s\n", argv[index-1]);
                        return FALSE;
                }
@@ -154,19 +139,19 @@ gboolean _get_arguments(int argc, char *argv[])
                        return FALSE;
                }
 
-               if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.x)) {
+               if (FALSE == mm_util_safe_str_to_uint(argv[index++], &g_args.x)) {
                        fprintf(stderr, "\t[IMGP_testsuite] wrong start_x %s\n", argv[index-1]);
                        return FALSE;
                }
-               if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.y)) {
+               if (FALSE == mm_util_safe_str_to_uint(argv[index++], &g_args.y)) {
                        fprintf(stderr, "\t[IMGP_testsuite] wrong start_y %s\n", argv[index-1]);
                        return FALSE;
                }
-               if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.w)) {
+               if (FALSE == mm_util_safe_str_to_uint(argv[index++], &g_args.w)) {
                        fprintf(stderr, "\t[IMGP_testsuite] wrong dst_width %s\n", argv[index-1]);
                        return FALSE;
                }
-               if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.h)) {
+               if (FALSE == mm_util_safe_str_to_uint(argv[index++], &g_args.h)) {
                        fprintf(stderr, "\t[IMGP_testsuite] wrong dst_height %s\n", argv[index-1]);
                        return FALSE;
                }
index 1cb4c08..40b5389 100644 (file)
@@ -57,13 +57,13 @@ static char *MODE_TO_STR[] = {
 };
 
 /* for arguments */
-static int g_test_mode = 0;
+static unsigned int g_test_mode = 0;
 static char *g_path = NULL;
 static unsigned int g_width = 0;
 static unsigned int g_height = 0;
-static int g_color = MM_UTIL_COLOR_RGB24;
-static int g_quality = 75;
-static int g_downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
+static unsigned int g_color = MM_UTIL_COLOR_RGB24;
+static unsigned int g_quality = 75;
+static unsigned int g_downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
 
 /* for reading file */
 static void *g_read_data = NULL;
@@ -71,20 +71,6 @@ static size_t g_read_size = 0;
 
 static mm_util_image_h g_decoded_data = NULL;
 
-gboolean _get_input_data(const char *argv, const long min, const long max, int *data)
-{
-       if (argv == NULL || strlen(argv) == 0)
-               return FALSE;
-
-       long temp = g_ascii_strtoll(argv, NULL, 10);
-       if (temp < min || temp > max)
-               return FALSE;
-
-       *data  = (int)temp;
-
-       return TRUE;
-}
-
 void _print_help(const char *argv0)
 {
        fprintf(stderr, "\t[usage]\n");
@@ -96,9 +82,7 @@ void _print_help(const char *argv0)
 
 gboolean _get_arguments(int argc, char *argv[])
 {
-       int width = 0, height = 0;
-
-       if (FALSE == _get_input_data(argv[1], TEST_AUTO, TEST_NUM - 1, &g_test_mode)) {
+       if (FALSE == mm_util_safe_str_to_valid_uint(argv[1], TEST_AUTO, TEST_NUM - 1, &g_test_mode)) {
                fprintf(stderr, "\t[JPEG_testsuite] wrong mode(%s) for test\n", argv[1]);
                _print_help(argv[0]);
                return FALSE;
@@ -107,18 +91,18 @@ gboolean _get_arguments(int argc, char *argv[])
        g_path = g_strdup(argv[2]);
 
        if (g_test_mode == TEST_AUTO) {
-               if (FALSE == _get_input_data(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
                        fprintf(stderr, "\t[JPEG_testsuite] color is default(%d)\n", g_color);
-               if (FALSE == _get_input_data(argv[4], 1, 100, &g_quality))
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[4], 1, 100, &g_quality))
                        fprintf(stderr, "\t[JPEG_testsuite] quality is default(%d)\n", g_quality);
                /* min: MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, max: MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8 */
-               if (FALSE == _get_input_data(argv[5], 1, 8, &g_downscale))
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[5], 1, 8, &g_downscale))
                        fprintf(stderr, "\t[JPEG_testsuite] downscale is default(%d)\n", g_downscale);
        } else if (g_test_mode == TEST_DECODE_FILE) {
-               if (FALSE == _get_input_data(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
                        fprintf(stderr, "\t[JPEG_testsuite] color is default(%d)\n", g_color);
        } else if (g_test_mode == TEST_DECODE_MEMORY) {
-               if (FALSE == _get_input_data(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
                        fprintf(stderr, "\t[JPEG_testsuite] color is default(%d)\n", g_color);
        } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_MEMORY) {
                if (argc < 5) {
@@ -126,25 +110,23 @@ gboolean _get_arguments(int argc, char *argv[])
                        _print_help(argv[0]);
                        return FALSE;
                }
-               if (FALSE == _get_input_data(argv[3], 0, INT_MAX, &width)) {
+               if (FALSE == mm_util_safe_str_to_uint(argv[3], &g_width)) {
                        fprintf(stderr, "\t[JPEG_testsuite] wrong width %s\n", argv[3]);
                        return FALSE;
                }
-               g_width = (unsigned int)width;
-               if (FALSE == _get_input_data(argv[4], 0, INT_MAX, &height)) {
+               if (FALSE == mm_util_safe_str_to_uint(argv[4], &g_height)) {
                        fprintf(stderr, "\t[JPEG_testsuite] wrong height %s\n", argv[4]);
                        return FALSE;
                }
-               g_height = (unsigned int)height;
-               if (FALSE == _get_input_data(argv[5], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color)) {
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[5], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color)) {
                        fprintf(stderr, "\t[JPEG_testsuite] wrong color %s\n", argv[5]);
                        return FALSE;
                }
-               if (FALSE == _get_input_data(argv[6], 1, 100, &g_quality))
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[6], 1, 100, &g_quality))
                        fprintf(stderr, "\t[JPEG_testsuite] quality is default(%d)\n", g_quality);
 
                /* min: MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, max: MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8 */
-               if (FALSE == _get_input_data(argv[7], 1, 8, &g_downscale))
+               if (FALSE == mm_util_safe_str_to_valid_uint(argv[7], 1, 8, &g_downscale))
                        fprintf(stderr, "\t[JPEG_testsuite] downscale is default(%d)\n", g_downscale);
        } else {
                fprintf(stderr, "\t[JPEG_testsuite] wrong mode for test %s\n", argv[1]);
@@ -232,13 +214,13 @@ gboolean _test_encode(const jpeg_test_mode_e mode)
 
        /* test encoding jpeg */
        if (mode == TEST_ENCODE_FILE) {
-               ret = mm_util_jpeg_encode_to_file(g_decoded_data, g_quality, ENCODE_FILE_PATH);
+               ret = mm_util_jpeg_encode_to_file(g_decoded_data, (int)g_quality, ENCODE_FILE_PATH);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[JPEG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
                        return FALSE;
                }
        } else if (mode == TEST_ENCODE_MEMORY) {
-               ret = mm_util_encode_to_jpeg_memory(g_decoded_data, g_quality, &encoded_data, &encoded_size);
+               ret = mm_util_encode_to_jpeg_memory(g_decoded_data, (int)g_quality, &encoded_data, &encoded_size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        fprintf(stderr, "\t[JPEG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
                        SAFE_FREE(encoded_data);
index 97b4c3d..def4d60 100644 (file)
@@ -46,11 +46,11 @@ static char *MODE_TO_STR[] = {
 };
 
 /* for arguments */
-static int g_test_mode = 0;
+static unsigned int g_test_mode = 0;
 static char *g_path = NULL;
 static unsigned int g_width = 0;
 static unsigned int g_height = 0;
-static int g_color = MM_UTIL_COLOR_RGB24;
+static unsigned int g_color = MM_UTIL_COLOR_RGB24;
 static bool g_lossless = false;
 
 /* for reading file */
@@ -80,23 +80,6 @@ static const char *g_test_filename[TEST_NUM][MM_UTIL_COLOR_NUM] = {
 static mm_util_image_h g_decoded_data = NULL;
 static mm_util_enc_opt_h g_enc_opt = NULL;
 
-static gboolean __get_input_data(const char *argv, const long min, const long max, int *data)
-{
-       if (!argv || strlen(argv) == 0)
-               return FALSE;
-
-       if (!data)
-               return FALSE;
-
-       long temp = g_ascii_strtoll(argv, NULL, 10);
-       if (temp < min || temp > max)
-               return FALSE;
-
-       *data  = (int)temp;
-
-       return TRUE;
-}
-
 static void __print_help(const char *argv0)
 {
        g_print("\t[usage]\n");
@@ -110,10 +93,9 @@ static void __print_help(const char *argv0)
 
 static gboolean __get_arguments(int argc, char *argv[])
 {
-       int width = 0, height = 0;
-       int lossless = 0;
+       unsigned int lossless = 0;
 
-       if (!__get_input_data(argv[1], TEST_AUTO, TEST_NUM - 1, &g_test_mode)) {
+       if (!mm_util_safe_str_to_valid_uint(argv[1], TEST_AUTO, TEST_NUM - 1, &g_test_mode)) {
                g_print("\t[JXL_testsuite] wrong mode(%s) for test\n", argv[1]);
                __print_help(argv[0]);
                return FALSE;
@@ -123,12 +105,12 @@ static gboolean __get_arguments(int argc, char *argv[])
 
        if (g_test_mode == TEST_AUTO) {
                // optional : lossless
-               if (!__get_input_data(argv[3], 0, 1, &lossless))
+               if (!mm_util_safe_str_to_valid_uint(argv[3], 0, 1, &lossless))
                        g_print("\t[JXL_testsuite] lossless is default(%d)\n", g_lossless);
                else
                        g_lossless = (lossless == 1) ? true : false;
        } else if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_BUFFER)) {
-               if (!__get_input_data(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
+               if (!mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
                        g_print("\t[JXL_testsuite] color is default(%d)\n", g_color);
        } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_BUFFER) {
                if (argc < 5) {
@@ -137,25 +119,23 @@ static gboolean __get_arguments(int argc, char *argv[])
                        return FALSE;
                }
 
-               if (!__get_input_data(argv[3], 0, INT_MAX, &width)) {
+               if (!mm_util_safe_str_to_uint(argv[3], &g_width)) {
                        g_print("\t[JXL_testsuite] wrong width %s\n", argv[3]);
                        return FALSE;
                }
-               g_width = (unsigned int)width;
 
-               if (!__get_input_data(argv[4], 0, INT_MAX, &height)) {
+               if (!mm_util_safe_str_to_uint(argv[4], &g_height)) {
                        g_print("\t[JXL_testsuite] wrong height %s\n", argv[4]);
                        return FALSE;
                }
-               g_height = (unsigned int)height;
 
-               if (!__get_input_data(argv[5], 0, MM_UTIL_COLOR_NUM - 1, &g_color)) {
+               if (!mm_util_safe_str_to_valid_uint(argv[5], 0, MM_UTIL_COLOR_NUM - 1, &g_color)) {
                        g_print("\t[JXL_testsuite] wrong color %s\n", argv[5]);
                        return FALSE;
                }
 
                // optional : lossless
-               if (!__get_input_data(argv[6], 0, 1, &lossless))
+               if (!mm_util_safe_str_to_valid_uint(argv[6], 0, 1, &lossless))
                        g_print("\t[JXL_testsuite] lossless is default(%d)\n", g_lossless);
                else
                        g_lossless = (lossless == 1) ? true : false;