From 4e39318c39c0eb131ef101eb7fe2d846f7e03ce9 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Wed, 3 Sep 2025 18:15:27 +0000 Subject: [PATCH] Address review feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove unnecessary @truncate for i32->i32 conversions - Remove unnecessary @as(usize) cast for result.items.len - Use @intCast where maxInt checks ensure safe conversion - Revert skip function change that didn't add value 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/sql/postgres/DataCell.zig | 8 ++++---- src/sql/postgres/PostgresRequest.zig | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sql/postgres/DataCell.zig b/src/sql/postgres/DataCell.zig index 0642707b19..bf6cafe352 100644 --- a/src/sql/postgres/DataCell.zig +++ b/src/sql/postgres/DataCell.zig @@ -418,7 +418,7 @@ fn parseArray(bytes: []const u8, bigint: bool, comptime arrayType: types.Tag, gl else => { const value = std.fmt.parseInt(i32, element, 0) catch return error.UnsupportedArrayFormat; - try array.append(bun.default_allocator, SQLDataCell{ .tag = .int4, .value = .{ .int4 = @truncate(value) } }); + try array.append(bun.default_allocator, SQLDataCell{ .tag = .int4, .value = .{ .int4 = value } }); slice = trySlice(slice, current_idx); continue; }, @@ -776,7 +776,7 @@ fn parseBinaryNumeric(input: []const u8, result: *std.ArrayList(u8)) !PGNummeric // negative scale means we need to add zeros before the decimal point // greater than ndigits means we need to add zeros after the decimal point var idx: isize = scale_start; - const end: usize = @as(usize, result.items.len) + @as(usize, @max(dscale, 0)); + const end: usize = result.items.len + @as(usize, @max(dscale, 0)); while (idx < dscale) : (idx += 4) { if (idx >= 0 and idx < ndigits) { const digit = reader.readInt(u16, .big) catch 0; @@ -911,7 +911,7 @@ pub const Putter = struct { if (is_raw) { cell.* = SQLDataCell.raw(optional_bytes); } else { - const tag = if (std.math.maxInt(short) < oid) .text else @as(types.Tag, @enumFromInt(@as(short, @truncate(oid)))); + const tag = if (std.math.maxInt(short) < oid) .text else @as(types.Tag, @enumFromInt(@as(short, @intCast(oid)))); cell.* = if (optional_bytes) |data| try fromBytes((field.binary or this.binary) and tag.isBinaryFormatSupported(), this.bigint, tag, data.slice(), this.globalObject) else @@ -927,7 +927,7 @@ pub const Putter = struct { // The indexed columns can be out of order. .index => |i| i, - else => @truncate(index), + else => index, }; // TODO: when duplicate and we know the result will be an object diff --git a/src/sql/postgres/PostgresRequest.zig b/src/sql/postgres/PostgresRequest.zig index ce0d2ca0e1..7f7800c49a 100644 --- a/src/sql/postgres/PostgresRequest.zig +++ b/src/sql/postgres/PostgresRequest.zig @@ -29,7 +29,7 @@ pub fn writeBind( for (0..len) |i| { const parameter_field = parameter_fields[i]; const is_custom_type = std.math.maxInt(short) < parameter_field; - const tag: types.Tag = if (is_custom_type) .text else @enumFromInt(@as(short, @truncate(parameter_field))); + const tag: types.Tag = if (is_custom_type) .text else @enumFromInt(@as(short, @intCast(parameter_field))); const force_text = is_custom_type or (tag.isBinaryFormatSupported() and brk: { iter.to(@truncate(i)); @@ -78,7 +78,7 @@ pub fn writeBind( } const parameter_field = parameter_fields[i]; const is_custom_type = std.math.maxInt(short) < parameter_field; - break :brk if (is_custom_type) .text else @enumFromInt(@as(short, @truncate(parameter_field))); + break :brk if (is_custom_type) .text else @enumFromInt(@as(short, @intCast(parameter_field))); }; if (value.isEmptyOrUndefinedOrNull()) { debug(" -> NULL", .{}); @@ -316,7 +316,7 @@ pub fn onData( debug("Unknown message: {c}", .{c}); const to_skip = try reader.length() -| 1; debug("to_skip: {d}", .{to_skip}); - try reader.skip(@as(usize, @max(to_skip, 0))); + try reader.skip(@intCast(@max(to_skip, 0))); }, } }