simpleperf: Fix a null check error
The null check should happen before using it.
Bug: none
Test: run simpleperf_unit_test
Change-Id: I3bcd4598becd48328b0c96cb3e9d93a0a53eee82
diff --git a/simpleperf/cmd_stat.cpp b/simpleperf/cmd_stat.cpp
index d7b2184..894d755 100644
--- a/simpleperf/cmd_stat.cpp
+++ b/simpleperf/cmd_stat.cpp
@@ -868,6 +868,9 @@
// It is not an error when some event types in the default list are not
// supported by the kernel.
const EventType* type = FindEventTypeByName(name);
+ if (type == nullptr) {
+ continue;
+ }
perf_event_attr attr = CreateDefaultPerfEventAttr(*type);
if (!IsKernelEventSupported()) {
attr.exclude_kernel = true;
@@ -876,7 +879,7 @@
}
name += ":u";
}
- if (type != nullptr && IsEventAttrSupported(attr, name)) {
+ if (IsEventAttrSupported(attr, name)) {
if (!event_selection_set_.AddEventType(name)) {
return false;
}