Fixes #3847 by using puts() and by NUL-terminating szMsg[]#3851
Fixes #3847 by using puts() and by NUL-terminating szMsg[]#3851mignon-p wants to merge 1 commit intoMicrosoftDocs:mainfrom
Conversation
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.
|
@ppelleti : Thanks for your contribution! The author(s) have been notified to review your proposed change. |
|
@TylerMSFT – Can you review the proposed changes? IMPORTANT: When the changes are ready for publication, add a #label:"aq-pr-triaged" |
There was a problem hiding this comment.
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.
|
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(). |
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()toputs(), sinceprintf()was not being used to do any formatting. Sinceputs()prints a newline after printing the string, I removed the newlines from theg_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!