Skip to content

Commit 97ce244

Browse files
committed
wasm-linker: fix splitSegmentName and add unit test
1 parent fe3a98d commit 97ce244

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/link/Wasm/Flush.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,10 +1182,18 @@ fn emitProducerSection(gpa: Allocator, binary_bytes: *std.ArrayListUnmanaged(u8)
11821182

11831183
fn splitSegmentName(name: []const u8) struct { []const u8, []const u8 } {
11841184
const start = @intFromBool(name.len >= 1 and name[0] == '.');
1185-
const pivot = mem.indexOfScalarPos(u8, name, start, '.') orelse 0;
1185+
const pivot = mem.indexOfScalarPos(u8, name, start, '.') orelse name.len;
11861186
return .{ name[0..pivot], name[pivot..] };
11871187
}
11881188

1189+
test splitSegmentName {
1190+
{
1191+
const a, const b = splitSegmentName(".data");
1192+
try std.testing.expectEqualStrings(".data", a);
1193+
try std.testing.expectEqualStrings("", b);
1194+
}
1195+
}
1196+
11891197
fn wantSegmentMerge(
11901198
wasm: *const Wasm,
11911199
a_id: Wasm.DataSegmentId,

0 commit comments

Comments
 (0)