search for standard sites pub-search.waow.tech
search zig blog atproto
11
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: memory leak in buildFtsQuery

zzstoatzz 5a36551a b9c3cccf

+8 -10
+8 -10
backend/src/db/mod.zig
··· 325 325 fn buildFtsQuery(alloc: Allocator, query: []const u8) ![]const u8 { 326 326 if (query.len == 0) return ""; 327 327 328 - // normalize dots to spaces and trim 329 - const normalized = try alloc.dupe(u8, query); 330 - for (normalized) |*c| { 331 - if (c.* == '.') c.* = ' '; 332 - } 333 - 334 328 // find actual content bounds (trim whitespace) 335 329 var start: usize = 0; 336 - var end: usize = normalized.len; 337 - while (start < end and normalized[start] == ' ') start += 1; 338 - while (end > start and normalized[end - 1] == ' ') end -= 1; 330 + var end: usize = query.len; 331 + while (start < end and query[start] == ' ') start += 1; 332 + while (end > start and query[end - 1] == ' ') end -= 1; 339 333 340 334 if (start >= end) return ""; 341 335 342 336 // allocate: trimmed length + 1 for '*' at end 343 337 const trimmed_len = end - start; 344 338 const buf = try alloc.alloc(u8, trimmed_len + 1); 345 - @memcpy(buf[0..trimmed_len], normalized[start..end]); 339 + 340 + // copy and normalize dots to spaces 341 + for (query[start..end], 0..) |c, i| { 342 + buf[i] = if (c == '.') ' ' else c; 343 + } 346 344 buf[trimmed_len] = '*'; 347 345 348 346 return buf[0 .. trimmed_len + 1];