Skip to content

JIT: Fix Compiler::printfAlloc for long strings #116306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025

Conversation

jakobbotsch
Copy link
Member

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 4, 2025
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jakobbotsch jakobbotsch marked this pull request as ready for review June 4, 2025 17:54
@Copilot Copilot AI review requested due to automatic review settings June 4, 2025 17:54
@jakobbotsch
Copy link
Member Author

PTAL @dotnet/jit-contrib

@jakobbotsch jakobbotsch requested a review from a team June 4, 2025 17:54
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue in Compiler::printfAlloc to ensure it correctly handles long strings by accurately calculating the required buffer size and then properly formatting the output.

  • Utilizes _vscprintf to determine the correct buffer size.
  • Reinitializes the va_list to correctly pass arguments to vsprintf_s.
Comments suppressed due to low confidence (2)

src/coreclr/jit/compiler.cpp:10597

  • [nitpick] Consider renaming the variable 'result' to 'writtenCount' (or a similar name) to more clearly differentiate it from 'count', which represents the computed required size.
int result = vsprintf_s(resultStr, count + 1, format, args);

src/coreclr/jit/compiler.cpp:10596

  • [nitpick] It may be useful to add a comment explaining why va_start is called a second time to reinitialize the va_list for vsprintf_s, clarifying the two-pass approach for future maintainers.
va_start(args, format);

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jakobbotsch
Copy link
Member Author

/ba-g Failure is #116261

@jakobbotsch jakobbotsch merged commit 571861b into dotnet:main Jun 4, 2025
108 of 110 checks passed
@jakobbotsch jakobbotsch deleted the fix-printf-limit branch June 4, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants