Skip to content

Commit

Permalink
Refactor: handle in-output errors for string functions (Part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
anandamideShakyan committed Dec 13, 2024
1 parent 67a0c04 commit 24335f4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion velox/common/process/TraceContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "velox/common/process/TraceHistory.h"

#include <iostream>
#include <sstream>

namespace facebook::velox::process {
Expand All @@ -41,7 +42,16 @@ TraceContext::TraceContext(std::string label, bool isTemporary)
entry.time = enterTime_;
entry.file = __FILE__;
entry.line = __LINE__;
snprintf(entry.label, entry.kLabelCapacity, "%s", label_.c_str());
int result = snprintf(entry.label, entry.kLabelCapacity, "%s", label_.c_str());

if (result < 0) {
throw std::runtime_error("Encoding error in snprintf");
}

if (result >= entry.kLabelCapacity) {
std::cerr << "Warning: label truncated in snprintf" << std::endl;
entry.label[entry.kLabelCapacity - 1] = '\0';
}
});
traceData_->withValue([&](auto& counts) {
auto& data = counts[label_];
Expand Down

0 comments on commit 24335f4

Please sign in to comment.