Browse files

EOF before first field is only ok for first character in io:fread

  • Loading branch information...
1 parent fd09fd9 commit f5b1153ea4eb536c44999debc7a9d7707a1e070b @RaimoNiskanen RaimoNiskanen committed Jul 21, 2011
Showing with 10 additions and 4 deletions.
  1. +4 −4 lib/stdlib/src/io_lib_fread.erl
  2. +6 −0 lib/stdlib/test/io_SUITE.erl
View
8 lib/stdlib/src/io_lib_fread.erl
@@ -123,8 +123,8 @@ fread([_F|_Format], [_C|_Line], _N, _Results) ->
fread_error(input);
fread([_|_]=Format, [], N, Results) ->
{more,Format,N,Results};
-fread([_|_], eof, _N, []) ->
- %% This is at start of format string so no error.
+fread([_|_], eof, 0, []) ->
+ %% This is at start of input so no error.
eof;
fread([_|_], eof, _N, _Results) ->
%% This is an error as there is no more input.
@@ -175,8 +175,8 @@ fread1([$l|Format], _F, Sup, _U, Line, N, Res, _AllFormat) ->
fread1(_Format, _F, _Sup, _U, [], N, Res, AllFormat) ->
%% Need more input here.
{more,[$~|AllFormat],N,Res};
-fread1(_Format, _F, _Sup, _U, eof, _N, [], _AllFormat) ->
- %% This is at start of format string so no error.
+fread1(_Format, _F, _Sup, _U, eof, 0, [], _AllFormat) ->
+ %% This is at start of input so no error.
eof;
fread1(_Format, _F, _Sup, _U, eof, _N, _Res, _AllFormat) ->
%% This is an error as there is no more input.
View
6 lib/stdlib/test/io_SUITE.erl
@@ -2011,7 +2011,13 @@ io_lib_fread_literal(Suite) when is_list(Suite) ->
%%
?line {done,eof,_} = io_lib:fread([], eof, "~d"),
?line {done,eof,_} = io_lib:fread([], eof, " ~d"),
+ ?line {more,C1} = io_lib:fread([], " \n", " ~d"),
+ ?line {done,{error,{fread,input}},_} = io_lib:fread(C1, eof, " ~d"),
+ ?line {done,{ok,[18]},""} = io_lib:fread(C1, "18\n", " ~d"),
%%
?line {done,eof,_} = io_lib:fread([], eof, "d"),
?line {done,eof,_} = io_lib:fread([], eof, " d"),
+ ?line {more,C2} = io_lib:fread([], " \n", " d"),
+ ?line {done,{error,{fread,input}},_} = io_lib:fread(C2, eof, " d"),
+ ?line {done,{ok,[]},[]} = io_lib:fread(C2, "d\n", " d"),
ok.

0 comments on commit f5b1153

Please sign in to comment.