| ... | @@ -1038,7 +1038,7 @@ fn replaceVecSectionHeader( | ... | @@ -1038,7 +1038,7 @@ fn replaceVecSectionHeader( |
| 1038 | section: std.wasm.Section, | 1038 | section: std.wasm.Section, |
| 1039 | n_items: u32, | 1039 | n_items: u32, |
| 1040 | ) void { | 1040 | ) void { |
| 1041 | const size: u32 = @intCast(bytes.items.len - offset - section_header_size); | 1041 | const size: u32 = @intCast(bytes.items.len - offset - section_header_reserve_size + uleb128size(n_items)); |
| 1042 | var buf: [section_header_reserve_size]u8 = undefined; | 1042 | var buf: [section_header_reserve_size]u8 = undefined; |
| 1043 | var fbw = std.io.fixedBufferStream(&buf); | 1043 | var fbw = std.io.fixedBufferStream(&buf); |
| 1044 | const w = fbw.writer(); | 1044 | const w = fbw.writer(); |
| ... | @@ -1395,14 +1395,9 @@ fn emitSegmentInfo(wasm: *Wasm, binary_bytes: *std.ArrayList(u8)) !void { | ... | @@ -1395,14 +1395,9 @@ fn emitSegmentInfo(wasm: *Wasm, binary_bytes: *std.ArrayList(u8)) !void { |
| 1395 | // } | 1395 | // } |
| 1396 | //} | 1396 | //} |
| 1397 | | 1397 | |
| 1398 | fn getUleb128Size(uint_value: anytype) u32 { | 1398 | fn uleb128size(x: u32) u32 { |
| 1399 | const T = @TypeOf(uint_value); | 1399 | var value = x; |
| 1400 | const U = if (@typeInfo(T).int.bits < 8) u8 else T; | | |
| 1401 | var value = @as(U, @intCast(uint_value)); | | |
| 1402 | | | |
| 1403 | var size: u32 = 0; | 1400 | var size: u32 = 0; |
| 1404 | while (value != 0) : (size += 1) { | 1401 | while (value != 0) : (size += 1) value >>= 7; |
| 1405 | value >>= 7; | | |
| 1406 | } | | |
| 1407 | return size; | 1402 | return size; |
| 1408 | } | 1403 | } |