summaryrefslogtreecommitdiff
path: root/core/Query.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 16:13:35 -0300
committerGabriel Schneider <[email protected]>2026-11-23 16:46:30 -0300
commit5a7716d32de84255e792c5f4bf0fa7b8261b9139 (patch)
treee51b81c3e40e65f1a320ae89a858aa1fc2c461c8 /core/Query.zig
parent60c428d74f8aad24d002a674d95a95de9c5ee76b (diff)
downloadpardes-5a7716d32de84255e792c5f4bf0fa7b8261b9139.tar.gz
pardes-5a7716d32de84255e792c5f4bf0fa7b8261b9139.zip
Grep: a row whose numbers a Found cannot hold is passed over: a row is a line's text with the file's name in it, and core/Query.zig take narrowed its line, column, end and path length by `@intCast`: a row `b:7:4294967297 hit` (a column past u32: a long line's hit, or a name made of such numbers) panicked every process (`integer does not fit` at Query.zig:1267 on main, the test of the tests change); now `std.math.cast` each, the row passed over; the survey's example, a file named `a:5000000000:b`, is no fault: the name parses whole; not fixed: the name unescaped (a newline in a name injects a row)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Query.zig')
-rw-r--r--core/Query.zig24
1 files changed, 13 insertions, 11 deletions
diff --git a/core/Query.zig b/core/Query.zig
index fe25d5fd..7bc30c9d 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -1257,19 +1257,21 @@ pub fn take(p: *Pardes, q: *Query, kind: Stream.Kind, rows: []const u8) void {
const t = look.parsePathLine(ln);
if (t.at.line == 0 or t.path.len == 0) continue;
const code = if (t.end < ln.len) ln[t.end + 1 ..] else "";
- const path_at: u32 = @intCast(q.found_bytes.items.len);
+ // A row is a line's text, a file's name in it unescaped (one
+ // named `a:5000000000:b` reads as `a` at line 5000000000): one
+ // whose numbers a Found cannot hold is passed over.
+ const found: Found = .{
+ .path = std.math.cast(u32, q.found_bytes.items.len) orelse return,
+ .path_len = std.math.cast(u16, t.path.len) orelse continue,
+ .line = std.math.cast(u32, t.at.line) orelse continue,
+ .col = std.math.cast(u32, t.at.col -| 1) orelse continue,
+ .end = std.math.cast(u32, if (t.at.end_col > 0) t.at.end_col else t.at.col) orelse continue,
+ .code = std.math.cast(u32, q.found_bytes.items.len + t.path.len) orelse return,
+ .code_len = std.math.cast(u32, code.len) orelse continue,
+ };
q.found_bytes.appendSlice(p.gpa, t.path) catch return;
- const code_at: u32 = @intCast(q.found_bytes.items.len);
q.found_bytes.appendSlice(p.gpa, code) catch return;
- q.found.append(p.gpa, .{
- .path = path_at,
- .path_len = @intCast(t.path.len),
- .line = @intCast(t.at.line),
- .col = @intCast(t.at.col -| 1),
- .end = @intCast(if (t.at.end_col > 0) t.at.end_col else t.at.col),
- .code = code_at,
- .code_len = @intCast(code.len),
- }) catch return;
+ q.found.append(p.gpa, found) catch return;
},
}
}