0

when attempting to run this program i get the error:

raised CONSTRAINT_ERROR : bifid.adb:55 index check failed

I'm not really sure where this error is coming from or what it exactly means. The line in question is

End_String := End_String & Get_Character(
    S, Ind(Count*(length(Cipher_Text))/2), Ind(Count));

Any help would be greatly appreciated. I'm using Ada 95 and a GNAT compiler.

function Decipher(S : Square; Cipher_Text : Ustring) return Ustring is 

type IndArray is array(1..(length(Cipher_Text)*2)) of Integer;

Ind : IndArray;
Temp : Character;
Row : Integer;
Col : Integer;
Count : Integer := 1;
End_String : Ustring;
begin
    Ind := (others=>0);
    for I in 1..length(Cipher_Text) loop
        Temp := Uppercase(Element(Cipher_Text, I));
        if In_Square(S, Temp) then
            Get_Coordinates(S, Temp, Row, Col);
            Ind(I) := row;
            Ind(I + length(Cipher_Text)) := Col;
        end if;
    end loop;
    while Count <= length(Cipher_Text)*2 loop
        End_String := End_String & Get_Character(
            S, Ind(Count*(length(Cipher_Text))/2), Ind(Count));
        Count := Count + 2;
    end loop;
    return End_String;
end Decipher;
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
user2396120
  • 51
  • 1
  • 3
  • Without the declaration of Ustring, we probably won't be able to see what's wrong. –  May 26 '13 at 23:25
  • sorry i just declared Ustring as an Unbounded_String to shorten it within the specification file. – user2396120 May 26 '13 at 23:56

1 Answers1

1

For Count > 4 the expression

Count*(length(Cipher_Text))/2

will exceed the size of your IndArray. So your program is wrong.

As you store row and col values Length (Cipher_Text) elements apart, you should probably also decode them using indices like Length (Cipher_Text) + Count.

Using a record with Row and Col as fields would remove all fiddling with index offsets because you could store pairs (Row, Col) at index Count.