From 2de0509cbb56f220e41b52b527e7530f2fc6f2ba Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Fri, 28 Aug 2020 15:27:59 +0800 Subject: [PATCH] [test]: Fix stringop-truncation warnings Fix this warning when building with newer GCC: warning: '__builtin_strncpy' specified bound 256 equals destination size [-Wstringop-truncation] | 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | In function 'strncpy', Change-Id: I6341fa4e507f644b143a8e266f3df267fbd9c566 Signed-off-by: Jeffy Chen --- test/mpi_dec_mt_test.c | 6 ++---- test/mpi_dec_multi_test.c | 6 ++---- test/mpi_dec_test.c | 9 +++------ test/mpi_enc_multi_test.c | 6 ++---- test/mpi_rc2_test.c | 12 ++++-------- test/mpi_rc_test.c | 12 ++++-------- 6 files changed, 17 insertions(+), 34 deletions(-) diff --git a/test/mpi_dec_mt_test.c b/test/mpi_dec_mt_test.c index a1566a0f..cf8780ad 100644 --- a/test/mpi_dec_mt_test.c +++ b/test/mpi_dec_mt_test.c @@ -497,8 +497,7 @@ static RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* c switch (*opt) { case 'i': if (next) { - strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH); - cmd->file_input[strlen(next)] = '\0'; + strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH - 1); cmd->have_input = 1; } else { mpp_err("input file is invalid\n"); @@ -507,8 +506,7 @@ static RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* c break; case 'o': if (next) { - strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH); - cmd->file_output[strlen(next)] = '\0'; + strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH - 1); cmd->have_output = 1; } else { mpp_log("output file is invalid\n"); diff --git a/test/mpi_dec_multi_test.c b/test/mpi_dec_multi_test.c index 3f4d277d..ff964812 100644 --- a/test/mpi_dec_multi_test.c +++ b/test/mpi_dec_multi_test.c @@ -653,8 +653,7 @@ static RK_S32 mpi_dec_multi_test_parse_options(int argc, char **argv, MpiDecTest switch (*opt) { case 'i': if (next) { - strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH); - cmd->file_input[strlen(next)] = '\0'; + strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH - 1); cmd->have_input = 1; } else { mpp_err("input file is invalid\n"); @@ -663,8 +662,7 @@ static RK_S32 mpi_dec_multi_test_parse_options(int argc, char **argv, MpiDecTest break; case 'o': if (next) { - strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH); - cmd->file_output[strlen(next)] = '\0'; + strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH - 1); cmd->have_output = 1; } else { mpp_log("output file is invalid\n"); diff --git a/test/mpi_dec_test.c b/test/mpi_dec_test.c index 22882b69..3fb259cd 100644 --- a/test/mpi_dec_test.c +++ b/test/mpi_dec_test.c @@ -784,8 +784,7 @@ static RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* c switch (*opt) { case 'i': if (next) { - strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH); - cmd->file_input[strlen(next)] = '\0'; + strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH - 1); cmd->have_input = 1; name_to_coding_type(cmd->file_input, &cmd->type); } else { @@ -795,8 +794,7 @@ static RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* c break; case 'o': if (next) { - strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH); - cmd->file_output[strlen(next)] = '\0'; + strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH - 1); cmd->have_output = 1; } else { mpp_log("output file is invalid\n"); @@ -805,8 +803,7 @@ static RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* c break; case 'c': if (next) { - strncpy(cmd->file_config, next, MAX_FILE_NAME_LENGTH); - cmd->file_config[strlen(next)] = '\0'; + strncpy(cmd->file_config, next, MAX_FILE_NAME_LENGTH - 1); cmd->have_config = 1; // enlarge packet buffer size for large input stream case diff --git a/test/mpi_enc_multi_test.c b/test/mpi_enc_multi_test.c index 60b303bd..b8d40684 100644 --- a/test/mpi_enc_multi_test.c +++ b/test/mpi_enc_multi_test.c @@ -876,8 +876,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, MpiEncTestCmd* c switch (*opt) { case 'i': if (next) { - strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH); - cmd->file_input[strlen(next)] = '\0'; + strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH - 1); cmd->have_input = 1; } else { mpp_err("input file is invalid\n"); @@ -886,8 +885,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, MpiEncTestCmd* c break; case 'o': if (next) { - strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH); - cmd->file_output[strlen(next)] = '\0'; + strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH - 1); cmd->have_output = 1; } else { mpp_log("output file is invalid\n"); diff --git a/test/mpi_rc2_test.c b/test/mpi_rc2_test.c index 4d83fb93..30a082c3 100644 --- a/test/mpi_rc2_test.c +++ b/test/mpi_rc2_test.c @@ -1214,8 +1214,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, switch (*opt) { case 'i': if (next) { - strncpy(cmd->file_input, next, MPI_RC_FILE_NAME_LEN); - cmd->file_input[strlen(next)] = '\0'; + strncpy(cmd->file_input, next, MPI_RC_FILE_NAME_LEN - 1); cmd->have_input = 1; } else { mpp_err("input file is invalid\n"); @@ -1224,8 +1223,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, break; case 'o': if (next) { - strncpy(cmd->file_enc_out, next, MPI_RC_FILE_NAME_LEN); - cmd->file_enc_out[strlen(next)] = '\0'; + strncpy(cmd->file_enc_out, next, MPI_RC_FILE_NAME_LEN - 1); cmd->have_enc_out = 1; } else { mpp_log("output file is invalid\n"); @@ -1261,8 +1259,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, break; case 's': if (next) { - strncpy(cmd->file_stat, next, MPI_RC_FILE_NAME_LEN); - cmd->file_stat[strlen(next)] = '\0'; + strncpy(cmd->file_stat, next, MPI_RC_FILE_NAME_LEN - 1); cmd->have_stat_out = 1; } else { mpp_log("stat file is invalid\n"); @@ -1271,8 +1268,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, break; case 'g': if (next) { - strncpy(cmd->file_config, next, MPI_RC_FILE_NAME_LEN); - cmd->file_config[strlen(next)] = '\0'; + strncpy(cmd->file_config, next, MPI_RC_FILE_NAME_LEN - 1); cmd->have_config_file = 1; } break; diff --git a/test/mpi_rc_test.c b/test/mpi_rc_test.c index 4abd5714..2a8084a3 100644 --- a/test/mpi_rc_test.c +++ b/test/mpi_rc_test.c @@ -1005,8 +1005,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, MpiRcTestCmd* cm switch (*opt) { case 'i': if (next) { - strncpy(cmd->file_input, next, MPI_RC_FILE_NAME_LEN); - cmd->file_input[strlen(next)] = '\0'; + strncpy(cmd->file_input, next, MPI_RC_FILE_NAME_LEN - 1); cmd->have_input = 1; } else { mpp_err("input file is invalid\n"); @@ -1015,8 +1014,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, MpiRcTestCmd* cm break; case 'o': if (next) { - strncpy(cmd->file_enc_out, next, MPI_RC_FILE_NAME_LEN); - cmd->file_enc_out[strlen(next)] = '\0'; + strncpy(cmd->file_enc_out, next, MPI_RC_FILE_NAME_LEN - 1); cmd->have_enc_out = 1; } else { mpp_log("output file is invalid\n"); @@ -1084,8 +1082,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, MpiRcTestCmd* cm break; case 'y': if (next) { - strncpy(cmd->file_dec_out, next, MPI_RC_FILE_NAME_LEN); - cmd->file_dec_out[strlen(next)] = '\0'; + strncpy(cmd->file_dec_out, next, MPI_RC_FILE_NAME_LEN - 1); cmd->have_dec_out = 1; } else { mpp_log("dec output file is invalid\n"); @@ -1094,8 +1091,7 @@ static RK_S32 mpi_enc_test_parse_options(int argc, char **argv, MpiRcTestCmd* cm break; case 's': if (next) { - strncpy(cmd->file_stat, next, MPI_RC_FILE_NAME_LEN); - cmd->file_stat[strlen(next)] = '\0'; + strncpy(cmd->file_stat, next, MPI_RC_FILE_NAME_LEN - 1); cmd->have_stat_out = 1; } else { mpp_log("stat file is invalid\n");