From 9ba1f1a9724430322c144fad5ceb18eb31f57ef7 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sun, 15 Apr 2018 22:54:27 -0500 Subject: [PATCH] Fix compile warning on strings in tests --- tests/rigctl.c | 9 +++------ tests/rigctl_parse.c | 16 +++++++--------- tests/rotctl_parse.c | 16 +++++++--------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/tests/rigctl.c b/tests/rigctl.c index 2c5d1a36d..50df20e2d 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -546,13 +546,10 @@ int main(int argc, char *argv[]) fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir); } - hist_path = (char *)calloc((sizeof(char) - * (strlen(hist_dir) - + strlen(hist_file) + 1)), - sizeof(char)); + int hist_path_size = sizeof(char)*(strlen(hist_dir)+strlen(hist_file) + 1); + hist_path = (char *)calloc(hist_path_size, sizeof(char)); - strncpy(hist_path, hist_dir, strlen(hist_dir)); - strncat(hist_path, hist_file, strlen(hist_file)); + snprintf(hist_path, hist_path_size, "%s%s", hist_dir, hist_file); } if (rd_hist && hist_path) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 999235bf2..ba7a0f37d 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -1096,11 +1096,9 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn #endif /* The starting position of the source string is the first - * character past the initial '\'. Using MAXNAMSIZ for the - * length leaves enough space for the '\0' string terminator in the - * cmd_name array. + * character past the initial '\'. */ - strncpy(cmd_name, parsed_input[0] + 1, MAXNAMSIZ); + snprintf(cmd_name, sizeof(cmd_name), "%s", parsed_input[0] + 1); /* Sanity check as valid multiple character commands consist of * alpha-numeric characters and the underscore ('_') character. @@ -1206,7 +1204,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXNAMSIZ); } @@ -1293,7 +1291,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1356,7 +1354,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1422,7 +1420,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1488,7 +1486,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index 3d10b3ab9..ca9e746e1 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -1007,11 +1007,9 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) #endif /* The starting position of the source string is the first - * character past the initial '\'. Using MAXNAMSIZ for the - * length leaves enough space for the '\0' string terminator in the - * cmd_name array. + * character past the initial '\'. */ - strncpy(cmd_name, parsed_input[0] + 1, MAXNAMSIZ); + snprintf(cmd_name, sizeof(cmd_name), parsed_input[0] + 1); /* Sanity check as valid multiple character commands consist of * alpha-numeric characters and the underscore ('_') character. @@ -1111,7 +1109,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1169,7 +1167,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1230,7 +1228,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1291,7 +1289,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1352,7 +1350,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (rp_hist_buf) { - strncat(rp_hist_buf, " ", 1); + strncat(rp_hist_buf, " ", 2); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); }