Skip to content

Add format attribute to printf-style wrappers and fix format string errors#123920

Draft
Copilot wants to merge 8 commits intomainfrom
copilot/add-format-attribute-to-wrappers
Draft

Add format attribute to printf-style wrappers and fix format string errors#123920
Copilot wants to merge 8 commits intomainfrom
copilot/add-format-attribute-to-wrappers

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

Add format attribute to printf-style wrappers and fix format string errors

Completed Work:

  • Added format attributes to 60+ printf-style wrapper functions
  • Fixed all format string errors found by the compiler
  • Addressed all PR review feedback
  • Fixed additional format errors in corehost

Review Feedback Addressed:

1. Use PRI macros from inttypes.h (@jkotas) ✅

  • Changed all #ifdef TARGET_64BIT blocks to use PRIX64, PRIx64, PRIu64, PRId64 macros
  • Includes <inttypes.h> in JIT and VM files for correct host-platform format specifiers

2. Use printf("%s", str) pattern (@jkotas) ✅

  • Changed all printf(sstr) to printf("%s", sstr)
  • Removed all #pragma GCC diagnostic blocks
  • Fixed in emitxarch.cpp, emitarm64.cpp, emitarm64sve.cpp, stresslog.h, and all corehost files

3. Use MINIPAL_ATTR_FORMAT_PRINTF throughout (@jkoritzinsky) ✅

  • Moved format attribute macro to src/native/minipal/types.h
  • Updated all CoreCLR headers to use MINIPAL_ATTR_FORMAT_PRINTF
  • Removed all inline #ifdef __GNUC__ blocks
  • Consistent macro usage throughout

Additional Format Errors Found & Fixed:

The format attribute caught additional errors in corehost:

  • sdk_resolver.cpp: format-security (non-literal format string)
  • hostpolicy_init.cpp: sizeof() result format (%d → %zu)
  • hostpolicy.cpp: unused format argument
  • hostpolicy_context.cpp: invalid %hs specifier on Unix
  • deps_format.cpp: missing format argument

Files Modified (21 total):

Headers (13): format attributes using MINIPAL_ATTR_FORMAT_PRINTF
Sources (11): format error fixes using inttypes.h and "%s" pattern

Summary:

  • 170 lines removed: Eliminated duplicated #ifdef blocks
  • Consistent pattern: Single MINIPAL_ATTR_FORMAT_PRINTF macro
  • Portable formats: Standard inttypes.h PRI macros
  • No pragmas: All warnings fixed properly
  • 75+ bugs fixed: Format errors that could cause crashes or security issues

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits February 2, 2026 23:48
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Add format attribute to printf-style API wrappers Add format attribute to printf-style wrappers and fix format string errors Feb 3, 2026
Copilot AI requested a review from jkoritzinsky February 3, 2026 00:20
@jkotas
Copy link
Member

jkotas commented Feb 3, 2026

@copilot

Copilot AI and others added 2 commits February 3, 2026 00:55
…, str) pattern

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants