Skip to content

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Oct 14, 2025

sprintf_s pops a crt assert dialog in checked/debug if the buffer is too short.
_snprintf_s with _TRUNCATE does not have such problem.

We may see some pretty long names here.

An example that was triggering the assert in #119432 was:
System.Collections.Generic.IAsyncEnumerator<System.ValueTuple<Microsoft.CodeAnalysis.Project,System.Collections.Immutable.ImmutableArray<System.ValueTuple<Microsoft.CodeAnalysis.ISymbol,Microsoft.CodeAnalysis.FindSymbols.SymbolGroup>>>>.MoveNextAsync

@Copilot Copilot AI review requested due to automatic review settings October 14, 2025 15:44
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 a CRT assert dialog issue in debug/checked builds when creating async resumption stub names. The change replaces sprintf_s with _snprintf_s using the _TRUNCATE option to handle cases where method names are too long for the fixed-size buffer.

Key changes:

  • Switches from sprintf_s to _snprintf_s with _TRUNCATE flag to prevent CRT assertion dialogs
  • Maintains the same buffer size and error checking logic

Copy link
Contributor

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

Comment on lines 14824 to 14825
char name[256];
int numWritten = sprintf_s(name, ARRAY_SIZE(name), "IL_STUB_AsyncResume_%s_%s", m_pMethodBeingCompiled->GetName(), optimizationTierName);
int numWritten = _snprintf_s(name, ARRAY_SIZE(name), _TRUNCATE, "IL_STUB_AsyncResume_%s_%s", m_pMethodBeingCompiled->GetName(), optimizationTierName);
Copy link
Member

Choose a reason for hiding this comment

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

Can we change the logic to make a long enough buffer instead?

Copy link
Member Author

@VSadov VSadov Oct 14, 2025

Choose a reason for hiding this comment

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

I assumed we wanted to cap how large the name may get. The names could end up arbitrary long and this is not a debug-only code.

Is there a purpose for resumption stub names in Release?
Can they all be just called "ResumptionStub"?

Copy link
Member

Choose a reason for hiding this comment

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

Is there a purpose for resumption stub names in Release?
Can they all be just called "ResumptionStub"?

Yeah, I think this should be debug-only. There is already a default name given to these stubs here:

case DynamicMethodDesc::StubAsyncResume: return "IL_STUB_AsyncResume";

The extra info was just for diagnostic purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants