The following valid code throws an exception: -- test_count.adb start with Ada.Strings.Fixed, Ada.Integer_Text_IO; use Ada.Strings.Fixed, Ada.Integer_Text_IO; procedure Test_Count is S : constant String (Positive'Last - 2 .. Positive'Last) := "Ada"; begin Put (Count (Source =>S, Pattern =>"AA")); Put (Count (Source =>S (S'First .. S'Last - 1), Pattern =>"A")); Put (Count (Source =>S, Pattern =>"A")); end; -- test_count.adb end Here is the program run: $ ./test_count 0 1 raised STORAGE_ERROR : stack overflow or erroneous memory access I mark severity minor, because this error is unlikely to appear in a real code. When fixing this bug, attention should be taken not to make new code much slower than the existing code.
Compiling a-strsea.adb with overflow checking enabled yields: raised CONSTRAINT_ERROR : a-strsea.adb:102 overflow check failed if Mapping'Address = Maps.Identity'Address then while Ind <= Source'Last - PL1 loop if Pattern = Source (Ind .. Ind + PL1) then Num := Num + 1; Ind := Ind + Pattern'Length; else Ind := Ind + 1; <=== 102 end if; end loop;