From 7532f47929211e0d2c425ade79c2c47341e3301f Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Sat, 27 Jan 2024 16:13:43 -0800 Subject: [PATCH] In printf, use %d instead of %i --- STYLE | 2 ++ tar/siginfo.c | 4 ++-- tests/shared_test_functions.sh | 2 +- tests/shared_valgrind_functions.sh | 2 +- tools/check_c_function_newline.py | 2 +- tools/check_includes_alphabetical.py | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/STYLE b/STYLE index 5eeed3f3..e3ca9856 100644 --- a/STYLE +++ b/STYLE @@ -47,6 +47,8 @@ not erroneous.) The first statement in main(), after variable declarations, should be "WARNP_INIT;" in order to set the program name used for printing warnings. +We use %d rather than %i in printf and warn0/warnp strings. + In general, functions should be structured with one return statement per status, e.g., one return() for success and one return() for failure. Errors should be handled by using goto to enter the error return path, e.g., diff --git a/tar/siginfo.c b/tar/siginfo.c index 585c0b3a..74bdbe06 100644 --- a/tar/siginfo.c +++ b/tar/siginfo.c @@ -183,14 +183,14 @@ siginfo_printinfo(struct bsdtar *bsdtar, off_t progress, int finalmsg) if ((s_total_uncompressed = humansize( siginfo->total_uncompressed)) == NULL) goto err0; - safe_fprintf(stderr, "Processed %i entries, %s", + safe_fprintf(stderr, "Processed %d entries, %s", siginfo->file_count, s_total_uncompressed); /* Clean up. */ free(s_total_uncompressed); } else { safe_fprintf(stderr, - "Processed %i entries, %" PRId64 " bytes", + "Processed %d entries, %" PRId64 " bytes", siginfo->file_count, siginfo->total_uncompressed); } diff --git a/tests/shared_test_functions.sh b/tests/shared_test_functions.sh index d4a12924..1c23bb07 100644 --- a/tests/shared_test_functions.sh +++ b/tests/shared_test_functions.sh @@ -143,7 +143,7 @@ wait_while() { while "$@"; do # Notify user (if desired) if [ "${VERBOSE}" -ne 0 ]; then - printf "waited\t%ims\t%s\n" \ + printf "waited\t%dms\t%s\n" \ "${_wait_while_ms}" "$*" 1>&2 fi diff --git a/tests/shared_valgrind_functions.sh b/tests/shared_valgrind_functions.sh index 2cd971b2..f56a0690 100644 --- a/tests/shared_valgrind_functions.sh +++ b/tests/shared_valgrind_functions.sh @@ -167,7 +167,7 @@ _val_generalize() { _val_generalize_i=1 while [ "${_val_generalize_i}" -le "${_val_generalize_num_segments}" ]; do # Process segment - _val_seg "$(printf "%s%02i" \ + _val_seg "$(printf "%s%02d" \ "${_val_generalize_filename}" "${_val_generalize_i}")" # Advance to the next suppression. diff --git a/tools/check_c_function_newline.py b/tools/check_c_function_newline.py index 040bc02e..a5e16273 100755 --- a/tools/check_c_function_newline.py +++ b/tools/check_c_function_newline.py @@ -20,7 +20,7 @@ def handle_file(filename): if " " in func_text_search.split("(")[0]: print("--------- WARNING: possible style violation") print("\t%s" % filename) - print("\tline %i" % i) + print("\tline %d" % i) print(func_text) func_text = "" if line[0] == "\t" or line[0] == " " or line[0] == "_": diff --git a/tools/check_includes_alphabetical.py b/tools/check_includes_alphabetical.py index 98d73ea9..36624652 100755 --- a/tools/check_includes_alphabetical.py +++ b/tools/check_includes_alphabetical.py @@ -61,7 +61,7 @@ def handle_file(filename): if not is_block_correct_order(include_block): print("Non-alphabetical include block") print("\t%s" % filename) - print("\tstarts line %i" % i) + print("\tstarts line %d" % i) print("\t%s" % include_block) include_block = []