aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorRaiden1411 <67233402+Raiden1411@users.noreply.github.com>2025-08-21 10:38:08 +0100
committerAlex Rønne Petersen <alex@alexrp.com>2025-08-22 02:50:26 +0200
commit55daefdb108ea0bf0406dcc3e0569f7b72c639b3 (patch)
tree76388e614570ec73b2424b7ea799642d016750e0 /lib/std
parentba726ab65a1a6d33823d7bb8a155d8e379f58ba7 (diff)
downloadzig-55daefdb108ea0bf0406dcc3e0569f7b72c639b3.tar.gz
zig-55daefdb108ea0bf0406dcc3e0569f7b72c639b3.zip
std: remove lossy int to float coercion on json parse
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/json/static.zig6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/std/json/static.zig b/lib/std/json/static.zig
index 540f5338f9..ced6894027 100644
--- a/lib/std/json/static.zig
+++ b/lib/std/json/static.zig
@@ -567,8 +567,8 @@ pub fn innerParseFromValue(
switch (source) {
.float => |f| {
if (@round(f) != f) return error.InvalidNumber;
- if (f > std.math.maxInt(T)) return error.Overflow;
- if (f < std.math.minInt(T)) return error.Overflow;
+ if (f > @as(@TypeOf(f), @floatFromInt(std.math.maxInt(T)))) return error.Overflow;
+ if (f < @as(@TypeOf(f), @floatFromInt(std.math.minInt(T)))) return error.Overflow;
return @as(T, @intFromFloat(f));
},
.integer => |i| {
@@ -770,7 +770,7 @@ fn sliceToInt(comptime T: type, slice: []const u8) !T {
// Try to coerce a float to an integer.
const float = try std.fmt.parseFloat(f128, slice);
if (@round(float) != float) return error.InvalidNumber;
- if (float > std.math.maxInt(T) or float < std.math.minInt(T)) return error.Overflow;
+ if (float > @as(f128, @floatFromInt(std.math.maxInt(T))) or float < @as(f128, @floatFromInt(std.math.minInt(T)))) return error.Overflow;
return @as(T, @intCast(@as(i128, @intFromFloat(float))));
}