-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Conversation
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.
I'd consider this a high priority bug fix that should trigger a release and have marked as such. @ponylang/committer any disagreement? |
Agree. |
@@ -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); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This formatting string creates a problem for certain Strings. See also https://ponylang.zulipchat.com/#narrow/stream/189985-beginner-help/topic/Bug.20in.20String.2Efrom_array.28.29.20.3F/near/286809387
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 |
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
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.