http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54736



--- Comment #5 from Shane Hart <shart6 at utk dot edu> 2012-09-30 20:56:39 UTC 
---

(In reply to comment #4)

> Am 30.09.2012 21:12, schrieb shart6 at utk dot edu:

> > If n_elist = 1, then high = low = 0, and the funtion will always return 0, 
> > even

> > if the unit passed in to search for is in the exception list.

> 

> If there are n_elist exceptions, then they can be found in

> elist[0], ..., elist[n_elist-1].

> 

> If there is one exception, then it can be found at elist[0].



That is true, but the function will not return 1 (true, a match was found in

elist) when there is only one exception stored.  It will skip over the while

loop, set *ip to 0, and return 0 (false, the exception was not found!).



This can be illustrated:



1) Call the program, setting only one exception (in this case unit 21):



[shane@shane-laptop ~/temp/testgfortran]$

GFORTRAN_CONVERT_UNIT='native;big_endian:21' gnu_wrap gdb ./test_read



2) Set a break point at where the library enquires as to the endianness of the

file to be opened:



Breakpoint 1, _gfortrani_get_unformatted_convert (unit=21) at

../../../libgfortran/runtime/environ.c:848



3) We will step into search_unit (with unit = 21).  Everything is great.

however, since n_elist = 1, high = low = 0, and the while loop is skipped over:



(gdb) step

471       while (high - low > 1)

(gdb) step

485       if (unit > elist[high].unit)



4) And 0 is returned (unit exception not found!)



(gdb) step

490       return 0;



5) The library is told to open unit 21 (which is in the exception list at 0) as

default endianness:



_gfortrani_get_unformatted_convert (unit=21) at

../../../libgfortran/runtime/environ.c:856

856         return def;

Reply via email to