Skip to content

Commit 1043f00

Browse files
Fix incorrect format string arguments (#67464)
* Fix cpp/wrong-type-format-argument * Remove <cinttypes> from src/coreclr; update zd -> zu * Remove %zx format strings from coreclr tree
1 parent 623b187 commit 1043f00

File tree

13 files changed

+28
-25
lines changed

13 files changed

+28
-25
lines changed

src/coreclr/tools/metainfo/mdinfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ void MDInfo::DisplayMD()
360360
// WriteLine("Unresolved MemberRefs");
361361
// DisplayMemberRefs(0x00000001, "\t");
362362

363-
VWrite("\n\nCoff symbol name overhead: %d\n", g_cbCoffNames);
363+
VWrite("\n\nCoff symbol name overhead: %Iu\n", g_cbCoffNames);
364364
}
365365
WriteLine("===========================================================");
366366
if (m_DumpFilter & dumpUnsat)
@@ -1939,7 +1939,7 @@ void MDInfo::DisplayCustomAttributeInfo(mdCustomAttribute inValue, const char *p
19391939

19401940
VWrite("%s\tCustomAttributeName: %ls", preFix, rcName);
19411941
if (pSig && pMethName)
1942-
VWrite(" :: %S", qSigName.Ptr());
1942+
VWrite(" :: %S", (LPWSTR)qSigName.Ptr());
19431943

19441944
// Keep track of coff overhead.
19451945
if (!wcscmp(W("__DecoratedName"), rcName))
@@ -2039,7 +2039,7 @@ void MDInfo::DisplayCustomAttributeInfo(mdCustomAttribute inValue, const char *p
20392039
case ELEMENT_TYPE_U8:
20402040
CA.GetU8(&u8);
20412041
uI64 = u8;
2042-
VWrite("%#lx", uI64);
2042+
VWrite("%#I64x", uI64);
20432043
break;
20442044
case ELEMENT_TYPE_R4:
20452045
dblVal = CA.GetR4();

src/coreclr/vm/clrex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ void EEResourceException::GetMessage(SString &result)
11381138
// since we don't want to call managed code here.
11391139
//
11401140

1141-
result.Printf("%s (message resource %s)",
1141+
result.Printf("%s (message resource %S)",
11421142
CoreLibBinder::GetExceptionName(m_kind), m_resourceName.GetUnicode());
11431143
}
11441144

src/coreclr/vm/eepolicy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void EEPolicy::LogFatalError(UINT exitCode, UINT_PTR address, LPCWSTR pszMessage
486486
if(!ssErrorFormat.LoadResource(CCompRC::Optional, IDS_ER_UNMANAGEDFAILFASTMSG ))
487487
ssErrorFormat.Set(W("at IP 0x%x (0x%x) with exit code 0x%x."));
488488
SmallStackSString addressString;
489-
addressString.Printf(W("%p"), pExceptionInfo? (UINT_PTR)pExceptionInfo->ExceptionRecord->ExceptionAddress : address);
489+
addressString.Printf(W("%p"), pExceptionInfo? (PVOID)pExceptionInfo->ExceptionRecord->ExceptionAddress : (PVOID)address);
490490

491491
// We should always have the reference to the runtime's instance
492492
_ASSERTE(GetClrModuleBase() != NULL);

src/coreclr/vm/eventreporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ void DoReportForUnhandledNativeException(PEXCEPTION_POINTERS pExceptionInfo)
679679
SmallStackSString exceptionCodeString;
680680
exceptionCodeString.Printf(W("%x"), pExceptionInfo->ExceptionRecord->ExceptionCode);
681681
SmallStackSString addressString;
682-
addressString.Printf(W("%p"), (UINT_PTR)pExceptionInfo->ExceptionRecord->ExceptionAddress);
682+
addressString.Printf(W("%p"), (PVOID)pExceptionInfo->ExceptionRecord->ExceptionAddress);
683683
s.FormatMessage(FORMAT_MESSAGE_FROM_STRING, (LPCWSTR)ssErrorFormat, 0, 0, exceptionCodeString, addressString);
684684
reporter.AddDescription(s);
685685
if (pThread)

src/coreclr/vm/stubgen.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ ILStubLinker::LogILInstruction(
466466

467467
if (isLabeled)
468468
{
469-
strLabel.Printf(W("IL_%04x:"), curOffset);
469+
strLabel.Printf(W("IL_%04Ix:"), curOffset);
470470
}
471471
else
472472
{
@@ -502,7 +502,7 @@ ILStubLinker::LogILInstruction(
502502
{
503503
size_t branchDistance = (size_t)pInstruction->uArg;
504504
size_t targetOffset = curOffset + s_rgbOpcodeSizes[instr] + branchDistance;
505-
strArgument.Printf(W("IL_%04x"), targetOffset);
505+
strArgument.Printf(W("IL_%04Ix"), targetOffset);
506506
}
507507
else if ((ILCodeStream::ILInstrEnum)CEE_NOP == instr)
508508
{
@@ -520,7 +520,7 @@ ILStubLinker::LogILInstruction(
520520
case ShortInlineVar:
521521
case ShortInlineI:
522522
case InlineI:
523-
strArgument.Printf(W("0x%x"), pInstruction->uArg);
523+
strArgument.Printf(W("0x%Ix"), pInstruction->uArg);
524524
break;
525525

526526
case InlineI8:
@@ -536,7 +536,7 @@ ILStubLinker::LogILInstruction(
536536
case InlineTok:
537537
// No token value when we dump IL for ETW
538538
if (pDumpILStubCode == NULL)
539-
strArgument.Printf(W("0x%08x"), pInstruction->uArg);
539+
strArgument.Printf(W("0x%08Ix"), pInstruction->uArg);
540540

541541
// Dump to szTokenNameBuffer if logging, otherwise dump to szArgumentBuffer to avoid an extra space because we are omitting the token
542542
_ASSERTE(FitsIn<mdToken>(pInstruction->uArg));
@@ -620,11 +620,11 @@ ILStubLinker::LogILStubWorker(
620620
{
621621
if (pDumpILStubCode)
622622
{
623-
pDumpILStubCode->AppendPrintf(W("IL_%04x:\n"), *pcbCode);
623+
pDumpILStubCode->AppendPrintf(W("IL_%04Ix:\n"), *pcbCode);
624624
}
625625
else
626626
{
627-
LOG((LF_STUBS, LL_INFO1000, "IL_%04x:\n", *pcbCode));
627+
LOG((LF_STUBS, LL_INFO1000, "IL_%04Ix:\n", *pcbCode));
628628
}
629629
}
630630
}

src/native/corehost/bundle/extractor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "dir_utils.h"
77
#include "pal.h"
88
#include "utils.h"
9+
#include <cinttypes>
910

1011
#ifdef __sun
1112
#include <alloca.h>
@@ -178,7 +179,7 @@ void extractor_t::extract(const file_entry_t &entry, reader_t &reader)
178179

179180
if (extracted_size != cast_size)
180181
{
181-
trace::error(_X("Failure extracting contents of the application bundle. Expected size:%d Actual size:%d"), size, extracted_size);
182+
trace::error(_X("Failure extracting contents of the application bundle. Expected size:%" PRId64 " Actual size:%zu"), size, extracted_size);
182183
trace::error(_X("I/O failure when writing extracted files."));
183184
throw StatusCode::BundleExtractionIOError;
184185
}

src/native/corehost/bundle/info.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "trace.h"
55
#include "info.h"
66
#include "utils.h"
7+
#include <cinttypes>
78

89
using namespace bundle;
910

@@ -48,8 +49,8 @@ StatusCode info_t::process_bundle(const pal::char_t* bundle_path, const pal::cha
4849
}
4950

5051
trace::info(_X("Single-File bundle details:"));
51-
trace::info(_X("DepsJson Offset:[%lx] Size[%lx]"), info.m_header.deps_json_location().offset, info.m_header.deps_json_location().size);
52-
trace::info(_X("RuntimeConfigJson Offset:[%lx] Size[%lx]"), info.m_header.runtimeconfig_json_location().offset, info.m_header.runtimeconfig_json_location().size);
52+
trace::info(_X("DepsJson Offset:[%" PRIx64 "] Size[%" PRIx64 "]"), info.m_header.deps_json_location().offset, info.m_header.deps_json_location().size);
53+
trace::info(_X("RuntimeConfigJson Offset:[%" PRIx64 "] Size[%" PRIx64 "]"), info.m_header.runtimeconfig_json_location().offset, info.m_header.runtimeconfig_json_location().size);
5354
trace::info(_X(".net core 3 compatibility mode: [%s]"), info.m_header.is_netcoreapp3_compat_mode() ? _X("Yes") : _X("No"));
5455

5556
the_app = &info;

src/native/corehost/corehost.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "trace.h"
1010
#include "utils.h"
1111
#include "hostfxr_resolver.h"
12+
#include <cinttypes>
1213

1314
#if defined(FEATURE_APPHOST)
1415
#include "bundle_marker.h"
@@ -200,7 +201,7 @@ int exe_start(const int argc, const pal::char_t* argv[])
200201
trace::info(_X("Host path: [%s]"), host_path.c_str());
201202
trace::info(_X("Dotnet path: [%s]"), fxr.dotnet_root().c_str());
202203
trace::info(_X("App path: [%s]"), app_path.c_str());
203-
trace::info(_X("Bundle Header Offset: [%lx]"), bundle_header_offset);
204+
trace::info(_X("Bundle Header Offset: [%" PRId64 "]"), bundle_header_offset);
204205

205206
auto set_error_writer = fxr.resolve_set_error_writer();
206207
propagate_error_writer_t propagate_error_writer_to_hostfxr(set_error_writer);

src/native/corehost/deps_format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void deps_json_t::reconcile_libraries_with_targets(
9898

9999
if (trace::is_enabled())
100100
{
101-
trace::info(_X("Parsed %s deps entry %d for asset name: %s from %s: %s, library version: %s, relpath: %s, assemblyVersion %s, fileVersion %s"),
101+
trace::info(_X("Parsed %s deps entry %zu for asset name: %s from %s: %s, library version: %s, relpath: %s, assemblyVersion %s, fileVersion %s"),
102102
deps_entry_t::s_known_asset_types[i],
103103
m_deps_entries[i].size() - 1,
104104
entry.asset.name.c_str(),

src/native/corehost/fxr/command_line.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ namespace
134134
for (const auto& opt : known_opts)
135135
{
136136
const host_option &arg = get_host_option(opt);
137-
trace::error(_X(" %s %-*s %s"), arg.option, 36 - pal::strlen(arg.option), arg.argument, arg.description);
137+
trace::error(_X(" %s %-*s %s"), arg.option, 36 - (int)pal::strlen(arg.option), arg.argument, arg.description);
138138
}
139139
return StatusCode::InvalidArgFailure;
140140
}
@@ -329,7 +329,7 @@ void command_line::print_muxer_usage(bool is_sdk_present)
329329
for (const auto& opt : known_opts)
330330
{
331331
const host_option &arg = get_host_option(opt);
332-
trace::println(_X(" %s %-*s %s"), arg.option, 29 - pal::strlen(arg.option), arg.argument, arg.description);
332+
trace::println(_X(" %s %-*s %s"), arg.option, 29 - (int)pal::strlen(arg.option), arg.argument, arg.description);
333333
}
334334
trace::println(_X(" --list-runtimes Display the installed runtimes"));
335335
trace::println(_X(" --list-sdks Display the installed SDKs"));

0 commit comments

Comments
 (0)