Browse Source

* fill the data in the DataSegments array when parsing the WASM_SEGMENT_INFO subsection

Nikolay Nikolov 1 year ago
parent
commit
56fe6cadc8
1 changed files with 22 additions and 19 deletions
  1. 22 19
      compiler/ogwasm.pas

+ 22 - 19
compiler/ogwasm.pas

@@ -2169,6 +2169,9 @@ implementation
           Len: uint32;
           Len: uint32;
           Offset: int32;
           Offset: int32;
           DataPos: LongInt;
           DataPos: LongInt;
+          SegName: ansistring;
+          SegAlignment: uint32;
+          SegFlags: uint32;
         end;
         end;
 
 
       function ReadSection: Boolean;
       function ReadSection: Boolean;
@@ -2293,9 +2296,8 @@ implementation
 
 
             function ReadSegmentInfo: Boolean;
             function ReadSegmentInfo: Boolean;
               var
               var
-                SegmentCount, SegAlignment, SegFlags: uint32;
+                SegmentCount: uint32;
                 i: Integer;
                 i: Integer;
-                SegName: ansistring;
               begin
               begin
                 Result:=False;
                 Result:=False;
                 if SegmentInfoSectionRead then
                 if SegmentInfoSectionRead then
@@ -2315,23 +2317,24 @@ implementation
                     exit;
                     exit;
                   end;
                   end;
                 for i:=0 to SegmentCount-1 do
                 for i:=0 to SegmentCount-1 do
-                  begin
-                    if not ReadName(SegName) then
-                      begin
-                        InputError('Error reading segment name from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
-                        exit;
-                      end;
-                    if not ReadUleb32(SegAlignment) then
-                      begin
-                        InputError('Error reading segment alignment from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
-                        exit;
-                      end;
-                    if not ReadUleb32(SegFlags) then
-                      begin
-                        InputError('Error reading segment flags from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
-                        exit;
-                      end;
-                  end;
+                  with DataSegments[i] do
+                    begin
+                      if not ReadName(SegName) then
+                        begin
+                          InputError('Error reading segment name from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
+                          exit;
+                        end;
+                      if not ReadUleb32(SegAlignment) then
+                        begin
+                          InputError('Error reading segment alignment from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
+                          exit;
+                        end;
+                      if not ReadUleb32(SegFlags) then
+                        begin
+                          InputError('Error reading segment flags from the WASM_SEGMENT_INFO subsection of the ''linking'' section');
+                          exit;
+                        end;
+                    end;
                 if AReader.Pos<>(SectionStart+SectionSize) then
                 if AReader.Pos<>(SectionStart+SectionSize) then
                   begin
                   begin
                     InputError('Unexpected WASM_SEGMENT_INFO section size');
                     InputError('Unexpected WASM_SEGMENT_INFO section size');