Don't printf wstring_views by copying them into wstrings; use %.*s! #5647

Open
opened 2026-01-31 00:18:12 +00:00 by claunia · 0 comments
Owner

Originally created by @DHowett-MSFT on GitHub (Dec 19, 2019).

StringCchPrintf and--since C99--printf support a specifier that indicates that a string is counted:

auto size = /* ... */;
auto data = /* ... */;
printf("%.*s", size, data);

The .* suggests that printf should consume one register-width argument to determine how many characters the string that follows contains instead of waiting for a null terminator.

Originally created by @DHowett-MSFT on GitHub (Dec 19, 2019). `StringCchPrintf` and--since C99--`printf` support a specifier that indicates that a string is counted: ``` auto size = /* ... */; auto data = /* ... */; printf("%.*s", size, data); ``` The `.*` suggests that printf should consume one register-width argument to determine how many characters the string that follows contains instead of waiting for a null terminator.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#5647