Skip to content

Clarify return values of vsnprintf-s-vsnprintf-s-vsnprintf-s-l-vsnwprintf-s-vsnwprintf-s-l #2349

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 8 commits into from
Sep 28, 2020

Conversation

definedrisk
Copy link
Contributor

No description provided.

@PRMerger18
Copy link
Contributor

@definedrisk : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@TylerMSFT
Copy link
Collaborator

@definedrisk - thanks for the contribution. I've been away at a conference. I'll take a look at this and get back to you.

Copy link
Collaborator

@TylerMSFT TylerMSFT left a comment

Choose a reason for hiding this comment

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

Thank you for trying to clear this up. I wonder if we can do a little more to clear this up. What do you think of updating your change like this:

  • If count is less than the number of characters of data, or is _TRUNCATE, as much of the string as will fit in buffer is written and the functions returns -1 without invoking the invalid parameter handler.
  • If the storage required to store count characters of data and a terminating NULL exceeds sizeOfBuffer, the invalid parameter handler is invoked as described in Parameter Validation. If execution continues after the invalid parameter handler, these functions set buffer to an empty string, set errno to ERANGE, and return -1.

@PRMerger8 PRMerger8 requested a review from TylerMSFT September 23, 2020 17:10
@PRMerger8
Copy link
Contributor

@definedrisk : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@PRMerger6
Copy link
Contributor

@definedrisk : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@definedrisk
Copy link
Contributor Author

I think I wanted to highlight that there is a subtle difference between truncation with a full buffer and truncation caused by sending more than count characters of data...

  • If the storage required to store the data with a terminating null exceeds sizeOfBuffer, the invalid parameter handler is invoked, as described in Parameter Validation. If execution continues after the invalid parameter handler, these functions set buffer to an empty string, set errno to ERANGE, and return -1.

  • If count is _TRUNCATE and the data with a terminating null exceeds sizeOfBuffer, then as much of the string as will fit in buffer is written. If count is less than sizeOfBuffer but the data exceeds count characters, then the first count characters are written. Either way some truncation of the data occurs and -1 is returned without invoking the invalid parameter handler.

Copy link
Collaborator

@TylerMSFT TylerMSFT left a comment

Choose a reason for hiding this comment

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

Thank you for the updates.
I believe the first statement is now incorrect. The invalid parameter isn't invoked if count == _TRUNCATE. We need the 'unless' part in there. Then the clarifying points that follow can flesh out the details. It'd also be good to put each condition on it's own line. When it's all together (as it unfortunately was in the original), it's hard to tease out the flow quickly. We should start most general and get more specific in with each following point about the behavior. Thanks for hanging in there with me on this.

@PRMerger8 PRMerger8 requested a review from TylerMSFT September 25, 2020 20:10
@PRMerger8
Copy link
Contributor

@definedrisk : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@ghost
Copy link

ghost commented Sep 25, 2020

CLA assistant check
All CLA requirements met.

@PRMerger8
Copy link
Contributor

@definedrisk : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@definedrisk
Copy link
Contributor Author

I moved the second sentence of the first paragraph of Return Value section to the Remarks section as it is not directly related to return value, I thought it was better placed as a remark. If you disagree I will move back.

Copy link
Collaborator

@TylerMSFT TylerMSFT left a comment

Choose a reason for hiding this comment

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

I think it was good to move the part of compliance and backward compatibility to the remarks section.
Thank you for making the docs better! People will benefit from the more complete explanation about what this function returns that you've worked out here.

@TylerMSFT
Copy link
Collaborator

Thank you, @definedrisk Really appreciate working with you on this.
#sign-off

@ktoliver ktoliver merged commit c54cdcf into MicrosoftDocs:master Sep 28, 2020
@definedrisk definedrisk deleted the vsnprintf_s branch September 29, 2020 08:53
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.

8 participants