UB fixed in parse_chat

This commit is contained in:
2025-12-24 20:00:30 -06:00
parent 7a70c0d6a9
commit a4749501f4

View File

@@ -129,21 +129,33 @@ time_t extract_timestamp_utc(std::string_view filename,
}
std::pair<std::string, std::string>
parse_chat(std::string_view line) {
// [CHAT] <Steve> hello world
parse_chat(std::string_view line)
{
constexpr std::string_view tag = "[CHAT]";
auto start = line.find("[CHAT] <");
start += 8;
auto tag_pos = line.find(tag);
if (tag_pos == std::string_view::npos)
return {"", ""};
auto end = line.find('>', start);
auto msg = end + 2;
std::size_t pos = tag_pos + tag.size();
if (pos >= line.size())
return {"", ""};
// Skip whitespace after [CHAT]
while (pos < line.size() && line[pos] == ' ')
++pos;
if (pos >= line.size())
return {"", ""};
// Entire remainder is "message"
return {
std::string(line.substr(start, end - start)),
std::string(line.substr(msg))
"", // sender unknown / system / to be inferred elsewhere
std::string(line.substr(pos))
};
}
void process_to_eof(std::string path, std::shared_ptr<clickhouse::Client>client, std::string target_user_id){
spdlog::info("Processing file {} ", path);
gzFile gz_file_log = gzopen(path.c_str(), "rb");