semantic bufo search find-bufo.com
bufo
1
fork

Configure Feed

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

fix: remove phrase from Match to fix dangling pointer panic

zzstoatzz 1ab45154 95017151

+2 -14
+2 -2
bot/src/main.zig
··· 74 74 // check for match 75 75 const match = state.matcher.findMatch(post.text) orelse return; 76 76 77 - std.debug.print("match: '{s}' -> {s}\n", .{ match.phrase, match.name }); 77 + std.debug.print("match: {s}\n", .{match.name}); 78 78 79 79 if (!state.config.posting_enabled) { 80 80 std.debug.print("posting disabled, skipping\n", .{}); ··· 148 148 std.debug.print("failed to create quote post: {}\n", .{err}); 149 149 return; 150 150 }; 151 - std.debug.print("posted bufo quote: {s} (phrase: {s})\n", .{ match.name, match.phrase }); 151 + std.debug.print("posted bufo quote: {s}\n", .{match.name}); 152 152 } else { 153 153 // post without quote 154 154 var text_buf: [256]u8 = undefined;
-12
bot/src/matcher.zig
··· 11 11 pub const Match = struct { 12 12 name: []const u8, 13 13 url: []const u8, 14 - phrase: []const u8, 15 14 }; 16 15 17 16 pub const Matcher = struct { ··· 74 73 75 74 for (self.bufos.items) |bufo| { 76 75 if (containsPhrase(words.items, bufo.phrase)) { 77 - var phrase_buf: [256]u8 = undefined; 78 - var phrase_len: usize = 0; 79 - for (bufo.phrase, 0..) |word, j| { 80 - if (j > 0) { 81 - phrase_buf[phrase_len] = ' '; 82 - phrase_len += 1; 83 - } 84 - @memcpy(phrase_buf[phrase_len .. phrase_len + word.len], word); 85 - phrase_len += word.len; 86 - } 87 76 return .{ 88 77 .name = bufo.name, 89 78 .url = bufo.url, 90 - .phrase = phrase_buf[0..phrase_len], 91 79 }; 92 80 } 93 81 }