Skip to content

Commit

Permalink
Handle empty table when writing NanoAOD
Browse files Browse the repository at this point in the history
Avoid dereferencing a null pointer when writing an empty table.
This was uncovered by the UBSAN checks.
  • Loading branch information
Dr15Jones committed Apr 26, 2022
1 parent 5b56ea4 commit f726ecd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion PhysicsTools/NanoAOD/plugins/TableOutputBranches.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class TableOutputBranches {
int idx = tab.columnIndex(pair.name);
if (idx == -1)
throw cms::Exception("LogicError", "Missing column in input for " + m_baseName + "_" + pair.name);
pair.branch->SetAddress(const_cast<T *>(&tab.columnData<T>(idx).front())); // SetAddress should take a const * !
pair.branch->SetAddress(
tab.size() == 0 ? static_cast<T *>(nullptr)
: const_cast<T *>(&tab.columnData<T>(idx).front())); // SetAddress should take a const * !
}
};

Expand Down

0 comments on commit f726ecd

Please sign in to comment.