Skip to content

Commit 816001b

Browse files
ferdymercurypcanal
andauthored
[RDF] prevent nullptr access in HasColumn when no datasource defined (#19835)
* [RDF] prevent nullptr access in HasColumn when no datasource defined Fixes #19834 Co-authored-by: Philippe Canal <[email protected]>
1 parent 725d1e8 commit 816001b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tree/dataframe/src/RInterfaceBase.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ bool ROOT::RDF::RInterfaceBase::HasColumn(std::string_view columnName)
274274
if (fColRegister.IsDefineOrAlias(columnName))
275275
return true;
276276

277-
if (auto ds = GetDataSource(); ds->HasColumn(columnName))
277+
if (auto ds = GetDataSource(); ds && ds->HasColumn(columnName))
278278
return true;
279279

280280
return false;

tree/dataframe/test/dataframe_colnames.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ TEST(ColNames, ContainedNames)
4545
EXPECT_EQ(1U, *c);
4646
}
4747

48+
// Test for https://github.com/root-project/root/issues/19834
49+
TEST(ColNames, NoSource)
50+
{
51+
auto df = ROOT::RDataFrame(1);
52+
auto df_def = df.Define("x", "int(1)");
53+
EXPECT_TRUE(df_def.HasColumn("x"));
54+
EXPECT_FALSE(df_def.HasColumn("y"));
55+
}
56+
4857
TEST(Aliases, DefineOnAlias)
4958
{
5059
ROOT::RDataFrame tdf(2);

0 commit comments

Comments
 (0)