aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/xref_lib.adb
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2019-09-19 08:12:47 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-09-19 08:12:47 +0000
commite516702202bcdc26181cf9fab120fcb15ca0c15d (patch)
tree31f92ae686a693ce3670782d8fd53b11dde69d63 /gcc/ada/xref_lib.adb
parent5d66b937e3d1bbdbaace1da7bc5fac8a94793108 (diff)
downloadgcc-e516702202bcdc26181cf9fab120fcb15ca0c15d.zip
gcc-e516702202bcdc26181cf9fab120fcb15ca0c15d.tar.gz
gcc-e516702202bcdc26181cf9fab120fcb15ca0c15d.tar.bz2
[Ada] gnatxref: infinite loop on symbols not found
This patch fixes a bug in which if a symbol is not found, gnatxref can sometimes enter an infinite loop. No impact on compilation. 2019-09-19 Bob Duff <duff@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. From-SVN: r275932
Diffstat (limited to 'gcc/ada/xref_lib.adb')
-rw-r--r--gcc/ada/xref_lib.adb17
1 files changed, 9 insertions, 8 deletions
diff --git a/gcc/ada/xref_lib.adb b/gcc/ada/xref_lib.adb
index 4d400f3..eabf8b4 100644
--- a/gcc/ada/xref_lib.adb
+++ b/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;