Skip to content

Commit

Permalink
prevent overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-conway committed May 2, 2024
1 parent 94bf404 commit 39bd234
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sourcemap/sourcemap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,11 @@ pub fn encodeVLQ(value: i32) VLQ {

var vlq: u32 = if (value >= 0)
@as(u32, @bitCast(value << 1))
else if (value != std.math.minInt(i32))
@as(u32, @bitCast((-value << 1) | 1))
else
@as(u32, @bitCast((-value << 1) | 1));
// `-value` will overflow if it's a signed minInt(T)
return .{ .bytes = .{ 104, 103, 103, 103, 103, 103, 69, 0 }, .len = 7 };

// source mappings are limited to i32
comptime var i: usize = 0;
Expand Down

0 comments on commit 39bd234

Please sign in to comment.