UB fixed in parse_chat
This commit is contained in:
@@ -128,22 +128,34 @@ time_t extract_timestamp_utc(std::string_view filename,
|
||||
return Route::NONE;
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string>
|
||||
parse_chat(std::string_view line) {
|
||||
// [CHAT] <Steve> hello world
|
||||
std::pair<std::string, std::string>
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user