Skip to content

Fixes #3847 by using puts() and by NUL-terminating szMsg[] #3851

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

Closed
wants to merge 1 commit into from

Conversation

mignon-p
Copy link

This is one potential way to solve the issues with the _getdiskfree() example I brought up in #3847. There's more than one way to solve those problems, so if there's a different way you prefer better, that's fine. I just wanted to suggest one potential way.

I changed printf() to puts(), since printf() was not being used to do any formatting. Since puts() prints a newline after printing the string, I removed the newlines from the g_szXXX[] constants.

I added a check to see if the error message was longer than g_szLine[], and if so, terminate the message with a NUL character, to avoid potentially reading past the end of the buffer.

Note: I don't currently have a Windows VM set up (it's on my to-do list) so I wasn't able to test my fixed version of the program. So if you decide to go with my solution, please be sure to test it first, and make sure it compiles and runs. Thanks!

I changed printf() to puts(), since printf() was not being used to do
any formatting.  Since puts() prints a newline after printing the
string, I removed the newlines from the g_szXXX[] constants.

I added a check to see if the error message was longer than
g_szLine[], and if so, terminate the message with a NUL character, to
avoid potentially reading past the end of the buffer.
@ghost
Copy link

ghost commented Apr 24, 2022

CLA assistant check
All CLA requirements met.

@PRMerger-2 PRMerger-2 requested a review from TylerMSFT April 24, 2022 19:57
@PRMerger-2
Copy link
Contributor

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

@ShannonLeavitt
Copy link
Contributor

@TylerMSFT – Can you review the proposed changes? IMPORTANT: When the changes are ready for publication, add a #sign-off comment to signal that the PR is ready for the review team to merge.

#label:"aq-pr-triaged"

@PRMerger9 PRMerger9 added the aq-pr-triaged Tracking label for the PR review team label Apr 25, 2022
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.

Hi @ppelleti,
Thank you for taking the time to work on this example.

I don't think we want to try to patch up the output formatting in this example.

The point of the example should be to illustrate the _getdiskfree() function, but that gets lost in all this text formatting stuff, much of which looks like it is fraught with peril. I'd rather remove the formatting stuff entirely and come up with a simpler way to output the results of _getdiskfree().

If you want to work on that, that'd be great. Otherwise, I'll give it a go. But I think the end result should get rid of all this string formatting code. The output doesn't have to be fancy.

@TylerMSFT
Copy link
Collaborator

I've fixed this by removing all the table formatting code, which just obscured what the topic was trying to demonstrate in the first place, which is _getdiskfree().

@TylerMSFT TylerMSFT closed this May 11, 2022
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.

6 participants