diff --git a/.release-notes/4180.md b/.release-notes/4180.md new file mode 100644 index 0000000000..e4c7f739fc --- /dev/null +++ b/.release-notes/4180.md @@ -0,0 +1,7 @@ +## Fix bug in `StdStream.print` + +When printing via `StdStream.print` strings containing null bytes, the standard library was printing the string until the first null byte and then padding the printed string with space characters until the string size was reached. + +This bug was introduced in Pony 0.12.0 while fixing a different printing bug. + +We've fixed the bug so that printing strings with null bytes works as expected. diff --git a/src/libponyrt/lang/stdfd.c b/src/libponyrt/lang/stdfd.c index ec6c77eedd..008a637cc3 100644 --- a/src/libponyrt/lang/stdfd.c +++ b/src/libponyrt/lang/stdfd.c @@ -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)