From a319f5b18a37dc277a56be48330a831f003d138c Mon Sep 17 00:00:00 2001
From: Philipp Stephani
Date: Mon, 30 Mar 2026 18:50:19 +0200
Subject: [PATCH] Use %u format specifier instead of %d for unsigned integers
---
elisp/private/tools/system.cc | 36 +++++++++++++++++------------------
elisp/private/tools/tst.cc | 4 ++--
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/elisp/private/tools/system.cc b/elisp/private/tools/system.cc
index b9091f3ef..ed92a7df3 100644
--- a/elisp/private/tools/system.cc
+++ b/elisp/private/tools/system.cc
@@ -167,7 +167,7 @@ class HResultCategory final : public std::error_category {
std::string message(int val) const final {
const HRESULT hr{val};
std::string result = absl::StrFormat(
- "HRESULT %#010x (severity %d, facility %#06x, code %#06x)", hr,
+ "HRESULT %#010x (severity %u, facility %#06x, code %#06x)", hr,
HRESULT_SEVERITY(hr), HRESULT_FACILITY(hr), HRESULT_CODE(hr));
const std::optional win32 = ToWin32(hr);
if (win32.has_value()) absl::StrAppend(&result, "; ", win32->message());
@@ -516,17 +516,17 @@ absl::StatusOr ToNarrow(const NativeStringView string,
Multiply(string.length(), max_bytes_per_wchar);
if (!buffer_size.has_value()) {
return absl::InvalidArgumentError(
- absl::StrFormat("String too long (%d code units)", string.length()));
+ absl::StrFormat("String too long (%u code units)", string.length()));
}
const std::optional wide_length = CastNumber(string.length());
if (!wide_length.has_value()) {
return absl::InvalidArgumentError(
- absl::StrFormat("String too long (%d code units)", string.length()));
+ absl::StrFormat("String too long (%u code units)", string.length()));
}
const std::optional narrow_length = CastNumber(*buffer_size);
if (!narrow_length.has_value()) {
return absl::InvalidArgumentError(
- absl::StrFormat("String too long (%d code units)", string.length()));
+ absl::StrFormat("String too long (%u code units)", string.length()));
}
std::string buffer(*buffer_size, '\0');
const int result =
@@ -534,7 +534,7 @@ absl::StatusOr ToNarrow(const NativeStringView string,
buffer.data(), *narrow_length, nullptr, nullptr);
if (result == 0) {
return WindowsStatus(
- "WideCharToMultiByte(%d, %#x, ..., %d, ..., %d, nullptr, nullptr)",
+ "WideCharToMultiByte(%u, %#x, ..., %d, ..., %d, nullptr, nullptr)",
codepage, flags, *wide_length, *narrow_length);
}
return buffer.substr(0, CastNumber(result).value());
@@ -559,13 +559,13 @@ absl::StatusOr ToNative(
const std::optional length = CastNumber(string.length());
if (!length.has_value()) {
return absl::InvalidArgumentError(
- absl::StrFormat("String too long (%d bytes)", string.length()));
+ absl::StrFormat("String too long (%u bytes)", string.length()));
}
NativeString buffer(string.length(), L'\0');
const int result = ::MultiByteToWideChar(codepage, flags, string.data(),
*length, buffer.data(), *length);
if (result == 0) {
- return WindowsStatus("MultiByteToWideChar(%d, %#x, ..., %d, ..., %d)",
+ return WindowsStatus("MultiByteToWideChar(%u, %#x, ..., %d, ..., %d)",
codepage, flags, *length, *length);
}
return buffer.substr(0, CastNumber(result).value());
@@ -674,7 +674,7 @@ absl::StatusOr FileName::Resolve() const {
const HANDLE handle = ::CreateFileW(this->pointer(), access, share, nullptr,
disposition, open_flags, nullptr);
if (handle == INVALID_HANDLE_VALUE) {
- return WindowsStatus("CreateFileW(%#x, %#x, nullptr, %d, %#x, nullptr)",
+ return WindowsStatus("CreateFileW(%#x, %#x, nullptr, %u, %#x, nullptr)",
access, share, disposition, open_flags);
}
const absl::Cleanup cleanup = [handle] {
@@ -690,7 +690,7 @@ absl::StatusOr FileName::Resolve() const {
}
if (length >= buffer.size()) {
return absl::FailedPreconditionError(absl::StrFormat(
- "Resolved filename is too long (%d characters)", length));
+ "Resolved filename is too long (%u characters)", length));
}
const std::wstring_view result(buffer.data(), length);
return FileName::FromString(result);
@@ -732,7 +732,7 @@ absl::Status WriteFile(const FileName& file, const std::string_view contents) {
CastNumber(contents.size());
if (!count.has_value()) {
return absl::InvalidArgumentError(
- absl::StrFormat("Content too big (%d bytes)", contents.size()));
+ absl::StrFormat("Content too big (%u bytes)", contents.size()));
}
stream.write(contents.data(), *count);
stream.flush();
@@ -1023,7 +1023,7 @@ absl::Status CopyFile(const FileName& from, const FileName& to) {
if (w == 0) {
// Avoid infinite loop.
return absl::DataLossError(absl::StrFormat(
- "Cannot write %d bytes to file %s", view.size(), to));
+ "Cannot write %u bytes to file %s", view.size(), to));
}
view.remove_prefix(static_cast>(w));
}
@@ -1147,12 +1147,12 @@ static std::wstring CanonicalizeEnvironmentVariable(
const int length = CastNumber(string.length()).value();
int result = ::LCMapStringW(locale, flags, string.data(), length, nullptr, 0);
CHECK_GT(result, 0) << WindowsStatus(
- "LCMapStringW(%d, %#x, ..., %d, nullptr, 0)", locale, flags, length);
+ "LCMapStringW(%u, %#x, ..., %d, nullptr, 0)", locale, flags, length);
std::wstring buffer(result, L'\0');
result = ::LCMapStringW(locale, flags, string.data(), length, buffer.data(),
result);
CHECK_GT(result, 0) << WindowsStatus(
- "LCMapStringW(%d, %#x, ..., %d, ..., %d)", locale, flags, length,
+ "LCMapStringW(%u, %#x, ..., %d, ..., %u)", locale, flags, length,
buffer.size());
return buffer.substr(0, result);
}
@@ -1233,7 +1233,7 @@ absl::StatusOr SearchPath(const FileName& program) {
}
if (length >= buffer.size()) {
return absl::FailedPreconditionError(
- absl::StrFormat("Program filename too long (%d characters)", length));
+ absl::StrFormat("Program filename too long (%u characters)", length));
}
return FileName::FromString(std::wstring_view(buffer.data(), length));
#else
@@ -1315,7 +1315,7 @@ absl::StatusOr RunProcess(const FileName& program,
if (options.output_file.has_value()) {
startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
if (startup_info.hStdInput == INVALID_HANDLE_VALUE) {
- return WindowsStatus("GetStdHandle(%d)", STD_INPUT_HANDLE);
+ return WindowsStatus("GetStdHandle(%u)", STD_INPUT_HANDLE);
}
constexpr DWORD access = GENERIC_WRITE;
constexpr DWORD share = FILE_SHARE_READ;
@@ -1329,7 +1329,7 @@ absl::StatusOr RunProcess(const FileName& program,
::CreateFileW(options.output_file->pointer(), access, share, &security,
disposition, attributes, nullptr);
if (startup_info.hStdOutput == INVALID_HANDLE_VALUE) {
- return WindowsStatus("CreateFileW(%#s, %#x, %#x, ..., %d, %#x, nullptr)",
+ return WindowsStatus("CreateFileW(%#s, %#x, %#x, ..., %u, %#x, nullptr)",
*options.output_file, access, share, disposition,
attributes);
}
@@ -1371,14 +1371,14 @@ absl::StatusOr RunProcess(const FileName& program,
LOG(WARNING) << "Process timed out, sending CTRL + BREAK";
if (!::GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,
process_info.dwProcessId)) {
- LOG(ERROR) << WindowsStatus("GenerateConsoleCtrlEvent(%d, %d)",
+ LOG(ERROR) << WindowsStatus("GenerateConsoleCtrlEvent(%u, %u)",
CTRL_BREAK_EVENT, process_info.dwProcessId);
}
return absl::DeadlineExceededError(absl::StrFormat(
"Deadline %v exceeded waiting for process (timeout %v)",
options.deadline, absl::Milliseconds(timeout_ms)));
default:
- return WindowsStatus("WaitForSingleObject(..., %d)", timeout_ms);
+ return WindowsStatus("WaitForSingleObject(..., %u)", timeout_ms);
}
DWORD code;
if (!::GetExitCodeProcess(process_info.hProcess, &code)) {
diff --git a/elisp/private/tools/tst.cc b/elisp/private/tools/tst.cc
index 2dc22cdef..351ff19c5 100644
--- a/elisp/private/tools/tst.cc
+++ b/elisp/private/tools/tst.cc
@@ -1,4 +1,4 @@
-// Copyright 2020-2025 Google LLC
+// Copyright 2020-2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -99,7 +99,7 @@ static absl::Status FixCoverageManifest(const FileName& manifest_file,
CastNumber(file.length());
if (!length.has_value()) {
return absl::DataLossError(
- absl::StrFormat("Line too long (%d bytes)", file.length()));
+ absl::StrFormat("Line too long (%u bytes)", file.length()));
}
stream.write(file.data(), *length);
stream.put('\n');