UB fixed in parse_chat

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

View File

@@ -128,22 +128,34 @@ time_t extract_timestamp_utc(std::string_view filename,
return Route::NONE; return Route::NONE;
} }
std::pair<std::string, std::string> std::pair<std::string, std::string>
parse_chat(std::string_view line) { parse_chat(std::string_view line)
// [CHAT] <Steve> hello world {
constexpr std::string_view tag = "[CHAT]";
auto start = line.find("[CHAT] <"); auto tag_pos = line.find(tag);
start += 8; if (tag_pos == std::string_view::npos)
return {"", ""};
auto end = line.find('>', start); std::size_t pos = tag_pos + tag.size();
auto msg = end + 2; 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 { return {
std::string(line.substr(start, end - start)), "", // sender unknown / system / to be inferred elsewhere
std::string(line.substr(msg)) std::string(line.substr(pos))
}; };
} }
void process_to_eof(std::string path, std::shared_ptr<clickhouse::Client>client, std::string target_user_id){ void process_to_eof(std::string path, std::shared_ptr<clickhouse::Client>client, std::string target_user_id){
spdlog::info("Processing file {} ", path); spdlog::info("Processing file {} ", path);
gzFile gz_file_log = gzopen(path.c_str(), "rb"); gzFile gz_file_log = gzopen(path.c_str(), "rb");