Skip to content

State of destination buffer when ISpanFormattable.TryFormat returns false? #100548

Answered by bartonjs
mawosoft asked this question in Q&A
Discussion options

You must be logged in to vote

I believe our current stance for a Span-based TryWrite is "any part of the buffer between written and Length should be assumed to be garbage on the part of a caller". So if you pass in a 100-item span, and it says it wrote 5, [5] isn't guaranteed unchanged, it might have been used for an intermediate calculation.

If TryWrite returns false it's supposed to out written as 0, in which case the whole of the destination buffer should be assumed garbage.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@EgorBo
Comment options

@stephentoub
Comment options

Answer selected by mawosoft
Comment options

You must be logged in to vote
3 replies
@bartonjs
Comment options

@stephentoub
Comment options

@mawosoft
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants