From 40a781a89fcedff2589d0e0f52a4ac466df01401 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Sat, 6 Nov 2021 17:12:20 -0700 Subject: [PATCH] Use correct types for format specifers (or use the correct specifiers for the type if we can.) These are hard to track down because we can't get compile-time warnings for the wprintf family of in libc like is possible for the narrow versions. --- src/builtin_math.cpp | 4 ++-- src/builtin_status.cpp | 7 +++---- src/builtin_string.cpp | 2 +- src/builtin_ulimit.cpp | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/builtin_math.cpp b/src/builtin_math.cpp index fd9d3b66b..97a9c1840 100644 --- a/src/builtin_math.cpp +++ b/src/builtin_math.cpp @@ -188,10 +188,10 @@ static const wchar_t *math_describe_error(const te_error_t &error) { static wcstring format_double(double v, const math_cmd_opts_t &opts) { if (opts.base == 16) { v = trunc(v); - return format_string(L"0x%x", (long)v); + return format_string(L"0x%x", (unsigned int)v); } else if (opts.base == 8) { v = trunc(v); - return format_string(L"0%o", (long)v); + return format_string(L"0%o", (unsigned int)v); } // As a special-case, a scale of 0 means to truncate to an integer diff --git a/src/builtin_status.cpp b/src/builtin_status.cpp index 27d371c67..ec3013a26 100644 --- a/src/builtin_status.cpp +++ b/src/builtin_status.cpp @@ -147,10 +147,9 @@ static bool set_status_cmd(const wchar_t *cmd, status_cmd_opts_t &opts, status_c /// Print the features and their values. static void print_features(io_streams_t &streams) { - size_t max_len = std::numeric_limits::min(); - for (const auto &md : features_t::metadata) { - max_len = std::max(max_len, wcslen(md.name)); - } + auto max_len = std::numeric_limits::min(); + for (const auto &md : features_t::metadata) + max_len = std::max(max_len, static_cast(wcslen(md.name))); for (const auto &md : features_t::metadata) { int set = feature_test(md.flag); streams.out.append_format(L"%-*ls%-3s %ls %ls\n", max_len + 1, md.name, set ? "on" : "off", diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index f15ef5163..c7a93e876 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -911,7 +911,7 @@ struct compiled_regex_t : noncopyable_t { string_error(streams, _(L"%ls: Regular expression compile error: %ls\n"), argv0, pcre2_strerror(err_code).c_str()); string_error(streams, L"%ls: %ls\n", argv0, pattern.c_str()); - string_error(streams, L"%ls: %*ls\n", argv0, err_offset, L"^"); + string_error(streams, L"%ls: %*ls\n", argv0, static_cast(err_offset), L"^"); return; } diff --git a/src/builtin_ulimit.cpp b/src/builtin_ulimit.cpp index 236c1bd5a..cf54e76f4 100644 --- a/src/builtin_ulimit.cpp +++ b/src/builtin_ulimit.cpp @@ -72,7 +72,7 @@ static void print(int resource, int hard, io_streams_t &streams) { if (l == RLIM_INFINITY) streams.out.append(L"unlimited\n"); else - streams.out.append_format(L"%d\n", l / get_multiplier(resource)); + streams.out.append_format(L"%lu\n", l / get_multiplier(resource)); } /// Print values of all resource limits. @@ -101,7 +101,7 @@ static void print_all(int hard, io_streams_t &streams) { if (l == RLIM_INFINITY) { streams.out.append(L"unlimited\n"); } else { - streams.out.append_format(L"%d\n", l / get_multiplier(resource_arr[i].resource)); + streams.out.append_format(L"%lu\n", l / get_multiplier(resource_arr[i].resource)); } } }