aboutsummaryrefslogtreecommitdiff
path: root/src/cli/stasis/args.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/stasis/args.c')
-rw-r--r--src/cli/stasis/args.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/cli/stasis/args.c b/src/cli/stasis/args.c
index dbc9c2f..98b4479 100644
--- a/src/cli/stasis/args.c
+++ b/src/cli/stasis/args.c
@@ -85,28 +85,30 @@ void usage(char *progname) {
int width = get_option_max_width(long_options);
for (int x = 0; long_options[x].name != 0; x++) {
char tmp[STASIS_NAME_MAX] = {0};
- char output[sizeof(tmp)] = {0};
+ char output[STASIS_NAME_MAX] = {0};
char opt_long[50] = {0}; // --? [ARG]?
char opt_short[50] = {0}; // -? [ARG]?
- strcat(opt_long, "--");
- strcat(opt_long, long_options[x].name);
+ strncat(opt_long, "--", sizeof(opt_long) - strlen(opt_long) - 1);
+ strncat(opt_long, long_options[x].name, sizeof(opt_long) - strlen(opt_long) - 1);
if (long_options[x].has_arg) {
- strcat(opt_long, " ARG");
+ strncat(opt_long, " ARG", sizeof(opt_long) - strlen(opt_long) - 1);
}
if (long_options[x].val <= 'z') {
- strcat(opt_short, "-");
+ strncat(opt_short, "-", sizeof(opt_short) - strlen(opt_short) - 1);
opt_short[1] = (char) long_options[x].val;
if (long_options[x].has_arg) {
- strcat(opt_short, " ARG");
+ strncat(opt_short, " ARG", sizeof(opt_short) - strlen(opt_short) - 1);
}
} else {
- strcat(opt_short, " ");
+ strncat(opt_short, " ", sizeof(opt_short) - strlen(opt_short) - 1);
}
- sprintf(tmp, " %%-%ds\t%%s\t\t%%s", width + 4);
- sprintf(output, tmp, opt_long, opt_short, long_options_help[x]);
+ const char *opt_fmt = " %%-%ds\t%%s\t\t%%s";
+ size_t opt_fmt_len = snprintf(NULL, 0, opt_fmt, width);
+ snprintf(tmp, sizeof(tmp) - opt_fmt_len, opt_fmt, width + 4);
+ snprintf(output, sizeof(output), tmp, opt_long, opt_short, long_options_help[x]);
puts(output);
}
}