Skip to content
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

Don't ignore buffer length when printing #1768

Merged
merged 1 commit into from
Mar 29, 2017
Merged

Conversation

SeanTAllen
Copy link
Member

As a left-over from when Pony strings where null terminated,
pony_os_std_print wasn't checking the length of the passed in
buffer and would print the entire buffer and beyond until it
hit a null terminator.

This PR fixes that issue so that we will now correctly only
print len elements from the buffer.

As a left-over from when Pony strings where null terminated,
pony_os_std_print wasn't checking the length of the passed in
buffer and would print the entire buffer and beyond until it
hit a null terminator.

This PR fixes that issue so that we will now correctly only
print `len` elements from the buffer.
@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Mar 29, 2017
@SeanTAllen
Copy link
Member Author

I'd consider this a high priority bug fix that should trigger a release and have marked as such.

@ponylang/committer any disagreement?

@SeanTAllen SeanTAllen added the triggers release Major issue that when fixed, results in an "emergency" release label Mar 29, 2017
@sylvanc
Copy link
Contributor

sylvanc commented Mar 29, 2017

Agree.

@SeanTAllen SeanTAllen mentioned this pull request Mar 29, 2017
@@ -512,7 +512,7 @@ PONY_API void pony_os_std_print(FILE* fp, char* buffer, size_t len)
if(len == 0)
return;

fprintf(fp, "%s\n", buffer);
fprintf(fp, "%*.*s\n", (int)len, (int)len, buffer);
Copy link
Member

Choose a reason for hiding this comment

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

I'd expect you to only need %*s\n here, does that not work?

fprintf(fp, "%*s\n", (int)len, buffer);

Copy link
Member

Choose a reason for hiding this comment

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

Never mind, I saw the note you sent about the first not working. I'll merge it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jemc jemc merged commit 15ac347 into master Mar 29, 2017
ponylang-main added a commit that referenced this pull request Mar 29, 2017
@jemc jemc deleted the pony_os_std_print-overflow branch March 29, 2017 16:01
@jemc
Copy link
Member

jemc commented Mar 29, 2017

Sorry, folks - I totally missed this one when doing the "allow strings to not be null terminated" PR.

I saw that the FFI call to pony_os_std_print was taking a len, and was assuming that it respected the len, without looking in the function. 😱

SeanTAllen pushed a commit that referenced this pull request Aug 26, 2022
When printing via `StdStream.print` strings containing the null
terminator, we were just printing the string until the null terminator
and replacing the unprinted characters by padding the printed string
with space characters.

This behavior made `String.size()` inconsistent with what `fprintf` was
really printing.

This behavior has been introduced in #1768, which ensure we respected
the buffer size.

Closes #4171
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge triggers release Major issue that when fixed, results in an "emergency" release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants