From 8dd18983880ce07e5242d789d2073aef2968aa20 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Wed, 29 Nov 2023 16:07:33 -0800 Subject: [PATCH] printf -> fmt::print in files inc warm_storage/integration/ws_client/tests/CppClientTests.cpp Summary: One of our [C++ 2024 Modern Code Better Engineering Goals](https://fb.workplace.com/groups/fbcode.fyi/posts/6837863056249437) is to reduce or eliminate the use of printf in our codebase, replacing it with safer and more performant alternatives. This diff replaces `printf` with its preferred alternative: `fmt::print`. This diff was auto-generated by fbcode/scripts/rbarnes/printf_upgrader.py, please reach out to r-barnes if you see problems. - If you approve of this diff, please use the "Accept & Ship" button :-) (11 file modified.) Reviewed By: bcardosolopes Differential Revision: D51486601 fbshipit-source-id: 5825c141956e17f40183f08f833cdd73352e617e --- watchman/Options.cpp | 3 ++- watchman/main.cpp | 2 +- watchman/test/BserTest.cpp | 13 +++++++------ watchman/winbuild/susres.cpp | 14 ++++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/watchman/Options.cpp b/watchman/Options.cpp index 2142d90c121c..281198336fcf 100644 --- a/watchman/Options.cpp +++ b/watchman/Options.cpp @@ -6,6 +6,7 @@ */ #include "watchman/Options.h" +#include #include #include "watchman/CommandRegistry.h" #include "watchman/LogConfig.h" @@ -446,7 +447,7 @@ std::vector parseOptions(int* argcp, char*** argvp) { usage(opts, stdout); } if (flags.show_version) { - printf("%s\n", PACKAGE_VERSION); + fmt::print("{}\n", PACKAGE_VERSION); exit(0); } return daemon_argv; diff --git a/watchman/main.cpp b/watchman/main.cpp index 4cbcbc3e8aa0..edcc3bff2d83 100644 --- a/watchman/main.cpp +++ b/watchman/main.cpp @@ -882,7 +882,7 @@ static bool try_client_mode_command(const Command& command, bool pretty) { client->responses.front(), stdout, pretty ? JSON_INDENT(4) : JSON_COMPACT); - printf("\n"); + fmt::print("\n"); } return res; diff --git a/watchman/test/BserTest.cpp b/watchman/test/BserTest.cpp index 07a14cad589c..699f35e2f837 100644 --- a/watchman/test/BserTest.cpp +++ b/watchman/test/BserTest.cpp @@ -6,6 +6,7 @@ */ #include "watchman/bser.h" +#include #include #include #include @@ -46,19 +47,19 @@ void hexdump(const char* start, const char* end) { if (limit > maxbytes) { limit = maxbytes; } - printf("# "); + fmt::print("# "); for (i = 0; i < limit; i++) { - printf("%02x", (int)(uint8_t)start[i]); + fmt::print("{:02x}", (int)(uint8_t)start[i]); } while (i <= maxbytes) { - printf(" "); + fmt::print(" "); i++; } - printf(" "); + fmt::print(" "); for (i = 0; i < limit; i++) { - printf("%c", isprint((uint8_t)start[i]) ? start[i] : '.'); + fmt::print("{}", isprint((uint8_t)start[i]) ? start[i] : '.'); } - printf("\n"); + fmt::print("\n"); start += limit; } } diff --git a/watchman/winbuild/susres.cpp b/watchman/winbuild/susres.cpp index dff082f36fb1..586086635b5d 100644 --- a/watchman/winbuild/susres.cpp +++ b/watchman/winbuild/susres.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -37,8 +38,8 @@ int apply(DWORD pid, BOOL suspend) { func = (sus_res_func)GetProcAddress(GetModuleHandle("ntdll"), name); if (!func) { - printf( - "Failed to GetProcAddress(%s): %s\n", + fmt::print( + "Failed to GetProcAddress({}): {}\n", name, win32_strerror(GetLastError())); return 1; @@ -46,15 +47,16 @@ int apply(DWORD pid, BOOL suspend) { proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); if (proc == INVALID_HANDLE_VALUE) { - printf( - "Failed to OpenProcess(%d): %s\n", pid, win32_strerror(GetLastError())); + fmt::print( + "Failed to OpenProcess({}): {}\n", pid, win32_strerror(GetLastError())); return 1; } res = func(proc); if (res) { - printf("%s(%d) returns %x: %s\n", name, pid, res, win32_strerror(res)); + fmt::print( + "{}({}) returns {:x}: {}\n", name, pid, res, win32_strerror(res)); } CloseHandle(proc); @@ -63,7 +65,7 @@ int apply(DWORD pid, BOOL suspend) { } void usage() { - printf( + fmt::print( "Usage: susres suspend [pid]\n" " susres resume [pid\n"); exit(1);