From f726ecd6ea29f9da8e67cc4b8441f1ff22a45610 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Tue, 26 Apr 2022 12:07:12 -0500 Subject: [PATCH] Handle empty table when writing NanoAOD Avoid dereferencing a null pointer when writing an empty table. This was uncovered by the UBSAN checks. --- PhysicsTools/NanoAOD/plugins/TableOutputBranches.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h index f5619e27a3b6c..f408e65759e38 100644 --- a/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h +++ b/PhysicsTools/NanoAOD/plugins/TableOutputBranches.h @@ -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(&tab.columnData(idx).front())); // SetAddress should take a const * ! + pair.branch->SetAddress( + tab.size() == 0 ? static_cast(nullptr) + : const_cast(&tab.columnData(idx).front())); // SetAddress should take a const * ! } };