Handle user input if first PMC line is empty
Change-Id: I456fd9360a4a8506fadcc975e71da112a26b07ae
此提交包含在:
+6
-4
@@ -36,14 +36,16 @@ class Exception : public std::runtime_error {
|
||||
Exception() = delete;
|
||||
|
||||
explicit Exception(rocprofiler_status_t status, const char* what_arg = "")
|
||||
: std::runtime_error(std::string(rocprofiler_error_str(status)) + " " +
|
||||
what_arg),
|
||||
: std::runtime_error(std::string(rocprofiler_error_str(status)) + " " + what_arg),
|
||||
status_(status) {}
|
||||
|
||||
rocprofiler_status_t status() const noexcept { return status_; }
|
||||
|
||||
explicit Exception(const std::string& message) : std::runtime_error(message) { message_ = message; }
|
||||
const char* what() const noexcept override { return message_.c_str(); }
|
||||
|
||||
protected:
|
||||
const rocprofiler_status_t status_;
|
||||
rocprofiler_status_t status_;
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
}; // namespace rocprofiler
|
||||
|
||||
+9
-2
@@ -144,7 +144,6 @@ std::string string_printf(const char* format, ...) {
|
||||
#endif /* defined (ENABLE_BACKTRACE) */
|
||||
|
||||
std::string errmsg("ROCProfiler: fatal error: " + message);
|
||||
fputs(errmsg.c_str(), stderr);
|
||||
|
||||
std::cerr << errmsg << std::endl;
|
||||
abort();
|
||||
@@ -251,7 +250,7 @@ void trim(std::string& str) {
|
||||
// replace unsuported specail chars with space
|
||||
static void handle_special_chars(std::string& str) {
|
||||
std::set<char> specialChars = {'!', '@', '#', '$', '%', '&', '(', ')', ',', '*', '+', '-', '.',
|
||||
'/', ';', '<', '=', '>', '?', '@', '{', '}', '^', '`', '~', '|'};
|
||||
'/', ';', '<', '=', '>', '?', '@', '{', '}', '^', '`', '~', '|', ':'};
|
||||
|
||||
// Iterate over the string and replace any special characters with a space.
|
||||
for (unsigned int i = 0; i < str.length(); i++) {
|
||||
@@ -277,6 +276,14 @@ void validate_counters_format(std::vector<std::string>& counters, std::string li
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// raise exception with correct usage if user still managed to corrupt input
|
||||
for(const auto &itr: counters)
|
||||
{
|
||||
if(!has_counter_format(itr)){
|
||||
rocprofiler::fatal("Bad input metric. usage --> pmc: <counter1> <counter2>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rocprofiler
|
||||
|
||||
新增問題並參考
封鎖使用者