io_lib:format probable bug

Ali Yakout ali.yakout@REDACTED
Wed Nov 24 12:36:27 CET 2010


Hi, 

I found a strange behaviour in io:format and io_lib:format, that I think is a bug.
The format string works in a different way than I use to know in other languages like (C, Java, Perl, Bash...).

The precision field is taken into consideration only if the field width is greater than the string length!

For example:
1> io:format("-~-6.3s-~n",["Hello"]).
-Hel   -
ok
2> io:format("-~-5.3s-~n",["Hello"]).
-Hello-
ok
3> io:format("-~-4.3s-~n",["Hello"]).
-Hell-
ok


The format string in 2 and 3 ignores the precision, when I expected the result to be like:

DB<1> printf("-%-6.3s-\n","Hello");
-Hel   -
DB<2> printf("-%-5.3s-\n","Hello");
-Hel  -
DB<3> printf("-%-4.3s-\n","Hello");
-Hel -


I've committed a fix at https://github.com/ayakout/otp/commit/349880780455989d186f961de11d655c97da98aa

Regards,
Ali


More information about the erlang-bugs mailing list