STORAGE_ERROR on assignment to array element

82 Views Asked by At

I have this array type:

type Rowid_X_Mv is array (Metadata_Version range Mv_1_0 .. Mv_2_3) of Integer;

where Metadata_Version is defined as:

   type Metadata_Version is (Mv_1_0, Mv_1_1, Mv_1_2, Mv_2_1, Mv_2_2, Mv_2_3);
   for Metadata_Version use
     (Mv_1_0 => 1,
      Mv_1_1 => 2,
      Mv_1_2 => 3,
      Mv_2_1 => 4,
      Mv_2_2 => 5,
      Mv_2_3 => 6);

I can create instances of this array, and I can access individual elements, but assignment doesn't work. Why?

   function Rowids_For_Chosen (Db : Gnade.Database; Chosen : Integer) return Rowid_X_Mv is
      use Gnade;
      Result : Rowid_X_Mv      := (others => -1);
      Raw    : constant String := "select ... where rowid = ?";
      Stmt   : Gnade.Statement;
   begin
      Cd.Prepare (Db, Raw, Stmt);
      Gnade.Bind_Int (Stmt, 1, Interfaces.C.int (Chosen));
      if Cd.Fetch (Db, Stmt) then
         if Gnade.Column_Type (Stmt, 0) /= Gnade.Sqlite_Null then
            Ati.Put_Line ("found base id " & Integer'Image (Gnade.Column_Int (Stmt, 0)));
            Ati.Put_Line ("result " & Result'Image);
            Ati.Put_Line ("result v1.0: " & Result (Mv_1_0)'Image);
            -- This line raises the storage exception
            Result (Mv_1_0) := Gnade.Column_Int (Stmt, 0);
            -- ...

On a side note, if there's a better way to have named constants that behave like a range of numeric values, and it also addresses my problem, that'd be great. Esp. since in other places I need to figure out next / previous versions and the way I currently have it is asking for a better solution.


Update: This appears to be independent of compiler version, whether Metadata_Version type defines a "non-standard" representation or not. It doesn't matter what index is used (i.e. Mv_1_1 is just as bad as Mv_1_0). Assignment also fails if the index is Result'First).


Update 2: Sorry for the trouble. This turned out a memory corruption that sipped in through C bindings to SQLite. Essentially, a use after free. It just affected Ada code in a bad way that made it look like the error is coming from it.

0

There are 0 best solutions below