Unwanted indentation when printing null-terminated strings with StdStream.print
#4171
Labels
bug
Something isn't working
good first issue
Good for newcomers
help wanted
Extra attention is needed
The example below prints "Hello, world" when using
printf
, and " Hello, world" (note the extra leading space) when using@pony_os_std_print
(which is whatStdStream.print
is using).Note that
@pony_os_std_print
will put as many leading spaces as\0
are present in the original string.This was introduced in #1768, which ensured that we respect the size of a string when printing to standard output:
ponyc/src/libponyrt/lang/stdfd.c
Lines 516 to 522 in 5978d14
This is done by using the
%*
format, which specifies the minimum field width. The manual mentions that if the supplied string is shorter than this, then the result is padded with space characters.Since
fprintf
will stop printing as soon as it encounters the first null terminator, there's a mismatch between what is reporter byString.size()
and whatfprintf
considers to be the true size of the string.The text was updated successfully, but these errors were encountered: