Three IO library related problems

Robert Virding rv@REDACTED
Fri Sep 7 11:29:59 CEST 2001


matthias@REDACTED writes:
>
>Robert wrote
> > No, this is perfectly correct.  io_lib:fread/2 takes a format string
> > and an input string and tries to extract ALL the specified fields.  It
> > is not re-entrant!
>
>If it's not intended to be re-entrant, why does fread/2 return {more, ...}
>in some cases? Consider these two cases:
>
>  io_lib:fread("~d.~d", "22")        crashes the process (function_clause)
>  io_lib:fread("~d~d", "22")         returns {more,"~d",2,[22]}
>
>If this is perfectly correct, then (a) how can I guess whether the
>fread/2 is going to crash or return {more, ...} for a particular input
>which only satisfies part of the format string and (b) why is it
>crashing with function_clause as a reason instead of badarg?

This is definitely a bug and I will fix it.  If I can still remember
how the code works. :-)  As you have already noticed the format of the
{more,...} tuple is different:

5> io_lib:fread("~d~d", "22").    
{more,"~d",2,[22]}
6> io_lib:fread([],"~d~d", "22").
{more,{"~d~d","22",0,[]}}

Which "proves" that there is a bug.  Actually it seems quite buggy.
Sigh!

	Robert



More information about the erlang-questions mailing list