From: Bob Duff Date: Thu, 19 Sep 2019 08:12:47 +0000 (+0000) Subject: [Ada] gnatxref: infinite loop on symbols not found X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e516702202bcdc26181cf9fab120fcb15ca0c15d;p=gcc.git [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 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 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index b0fdcf97ac0..429e17ff286 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,12 @@ +2019-09-19 Bob Duff + + * 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. + 2019-09-19 Eric Botcazou * exp_ch6.adb (Is_Legal_Copy): Also return false for an aliased diff --git a/gcc/ada/xref_lib.adb b/gcc/ada/xref_lib.adb index 4d400f31be0..eabf8b450e8 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;