This patch fixes a bug in which if a symbol is not found, gnatxref can
sometimes enter an infinite loop. No impact on compilation.
Tested on x86_64-pc-linux-gnu, committed on trunk
2019-09-19 Bob Duff <d...@adacore.com>
gcc/ada/
* xref_lib.adb (Get_Symbol_Name): If we reach EOF in the first
loop without finding the symbol, return "???". Otherwise, it's
an infinite loop.
(Parse_EOL): Assert that we're not already at EOF. Remove
processing of LF/CR -- there are no operating systems that use
that.
--- gcc/ada/xref_lib.adb
+++ gcc/ada/xref_lib.adb
@@ -723,6 +723,8 @@ package body Xref_Lib is
is
begin
loop
+ pragma Assert (Source (Ptr) /= EOF);
+
-- Skip to end of line
while Source (Ptr) /= ASCII.CR and then Source (Ptr) /= ASCII.LF
@@ -737,11 +739,9 @@ package body Xref_Lib is
Ptr := Ptr + 1;
end if;
- -- Skip past CR/LF or LF/CR combination
+ -- Skip past CR/LF
- if (Source (Ptr) = ASCII.CR or else Source (Ptr) = ASCII.LF)
- and then Source (Ptr) /= Source (Ptr - 1)
- then
+ if Source (Ptr - 1) = ASCII.CR and then Source (Ptr) = ASCII.LF then
Ptr := Ptr + 1;
end if;
@@ -783,6 +783,7 @@ package body Xref_Lib is
-- line and column in the dependent unit number Eun. For this we need
-- to parse the ali file again because the parent entity is not in
-- the declaration table if it did not match the search pattern.
+ -- If the symbol is not found, we return "???".
procedure Skip_To_Matching_Closing_Bracket;
-- When Ptr points to an opening square bracket, moves it to the
@@ -803,6 +804,10 @@ package body Xref_Lib is
-- Look for the X lines corresponding to unit Eun
loop
+ if Ali (Ptr) = EOF then
+ return "???";
+ end if;
+
if Ali (Ptr) = 'X' then
Ptr := Ptr + 1;
Parse_Number (Ali, Ptr, E_Eun);
@@ -832,10 +837,6 @@ package body Xref_Lib is
exit when Ali (Ptr) = EOF;
end loop;
- -- We were not able to find the symbol, this should not happen but
- -- since we don't want to stop here we return a string of three
- -- question marks as the symbol name.
-
return "???";
end Get_Symbol_Name;