From f2bd7b16c28abfd6b171b01cffaa770057aa523f Mon Sep 17 00:00:00 2001 From: Olivier Couet Date: Tue, 24 Feb 2026 14:43:10 +0100 Subject: [PATCH 1/2] Allow to create a TGraph2D with 0 points --- hist/hist/src/TGraph2D.cxx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/hist/hist/src/TGraph2D.cxx b/hist/hist/src/TGraph2D.cxx index 43dd758ce9bc8..6fd4198beb2e4 100644 --- a/hist/hist/src/TGraph2D.cxx +++ b/hist/hist/src/TGraph2D.cxx @@ -598,7 +598,7 @@ TGraph2D& TGraph2D::operator=(const TGraph2D &g) void TGraph2D::Build(Int_t n) { - if (n <= 0) { + if (n < 0) { Error("TGraph2D", "Invalid number of points (%d)", n); return; } @@ -609,12 +609,18 @@ void TGraph2D::Build(Int_t n) fNpy = 40; fDirectory = nullptr; fHistogram = nullptr; - fDelaunay = nullptr; + fDelaunay = nullptr; fMaximum = -1111; fMinimum = -1111; - fX = new Double_t[fSize]; - fY = new Double_t[fSize]; - fZ = new Double_t[fSize]; + if (n>0) { + fX = new Double_t[fSize]; + fY = new Double_t[fSize]; + fZ = new Double_t[fSize]; + } else { + fX = nullptr; + fY = nullptr; + fZ = nullptr; + } fZout = 0; fMaxIter = 100000; fFunctions = new TList; From dd045915b2b535304e9ce64637e77f11cf9acc49 Mon Sep 17 00:00:00 2001 From: Olivier Couet Date: Tue, 24 Feb 2026 16:16:21 +0100 Subject: [PATCH 2/2] Does the same for the others TGraph2D classes. --- hist/hist/src/TGraph2DAsymmErrors.cxx | 46 +++++++++++++++++++-------- hist/hist/src/TGraph2DErrors.cxx | 28 +++++++++++----- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/hist/hist/src/TGraph2DAsymmErrors.cxx b/hist/hist/src/TGraph2DAsymmErrors.cxx index 6c659ac775773..965b4ad82e4ec 100644 --- a/hist/hist/src/TGraph2DAsymmErrors.cxx +++ b/hist/hist/src/TGraph2DAsymmErrors.cxx @@ -82,17 +82,26 @@ TGraph2DAsymmErrors::TGraph2DAsymmErrors() {} TGraph2DAsymmErrors::TGraph2DAsymmErrors(Int_t n) : TGraph2D(n) { - if (n <= 0) { + if (n < 0) { Error("TGraph2DAsymmErrors", "Invalid number of points (%d)", n); return; } - fEXlow = new Double_t[n]; - fEXhigh = new Double_t[n]; - fEYlow = new Double_t[n]; - fEYhigh = new Double_t[n]; - fEZlow = new Double_t[n]; - fEZhigh = new Double_t[n]; + if (n>0) { + fEXlow = new Double_t[n]; + fEXhigh = new Double_t[n]; + fEYlow = new Double_t[n]; + fEYhigh = new Double_t[n]; + fEZlow = new Double_t[n]; + fEZhigh = new Double_t[n]; + } else { + fEXlow = nullptr; + fEXhigh = nullptr; + fEYlow = nullptr; + fEYhigh = nullptr; + fEZlow = nullptr; + fEZhigh = nullptr; + } for (Int_t i=0;i0) { + fEXlow = new Double_t[n]; + fEXhigh = new Double_t[n]; + fEYlow = new Double_t[n]; + fEYhigh = new Double_t[n]; + fEZlow = new Double_t[n]; + fEZhigh = new Double_t[n]; + } else { + fEXlow = nullptr; + fEXhigh = nullptr; + fEYlow = nullptr; + fEYhigh = nullptr; + fEZlow = nullptr; + fEZhigh = nullptr; + } for (Int_t i=0;i0) { + fEX = new Double_t[n]; + fEY = new Double_t[n]; + fEZ = new Double_t[n]; + } else { + fEX = nullptr; + fEY = nullptr; + fEZ = nullptr; + } for (Int_t i=0;i0) { + fEX = new Double_t[n]; + fEY = new Double_t[n]; + fEZ = new Double_t[n]; + } else { + fEX = nullptr; + fEY = nullptr; + fEZ = nullptr; + } for (Int_t i=0;i