Skip to content

Commit

Permalink
Fix unwanted indentation in StdStream.print
Browse files Browse the repository at this point in the history
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
  • Loading branch information
leonardoce committed Aug 21, 2022
1 parent f3f3b8d commit 9d0f44c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .release-notes/4180.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Fix unwanted indentation in `StdStream.print`

When printing via `StdStream.print` strings containing the null terminator, the
standard library was printing the string until the null terminator and then
padding the printed string with space characters until the string size was
reached.

That behavior was introduced in release 0.12.0, fixing a left-over from when
Pony strings were null terminated.

Now the `print` function is effectively printing every character in the string
plus an ending newline character.
6 changes: 2 additions & 4 deletions src/libponyrt/lang/stdfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,8 @@ PONY_API size_t pony_os_stdin_read(char* buffer, size_t space)

PONY_API void pony_os_std_print(FILE* fp, char* buffer, size_t len)
{
if(len == 0)
fprintf(fp, "\n");
else
fprintf(fp, "%*.*s\n", (int)len, (int)len, buffer);
fwrite(buffer, len, 1, fp);
fprintf(fp, "\n");
}

PONY_API void pony_os_std_write(FILE* fp, char* buffer, size_t len)
Expand Down

0 comments on commit 9d0f44c

Please sign in to comment.