Skip to content

Commit 8baea4c

Browse files
committed
Protect hist classes against calling strlen with nullptr argument
1 parent 1d20621 commit 8baea4c

File tree

8 files changed

+20
-14
lines changed

8 files changed

+20
-14
lines changed

hist/hist/src/TFormula.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ TFormula::TFormula()
453453
}
454454

455455
////////////////////////////////////////////////////////////////////////////////
456-
static bool IsReservedName(const char* name){
456+
static bool IsReservedName(const char* name)
457+
{
457458
if (strlen(name)!=1) return false;
458459
for (auto const & specialName : {"x","y","z","t"}){
459460
if (strcmp(name,specialName)==0) return true;

hist/hist/src/TFormula_v5.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ TFormula::TFormula(const char *name,const char *expression) :
191191

192192
//eliminate blanks in expression
193193
Int_t i,j,nch;
194-
nch = strlen(expression);
194+
nch = expression ? strlen(expression) : 0;
195195
char *expr = new char[nch+1];
196196
j = 0;
197197
for (i=0;i<nch;i++) {

hist/hist/src/TGraph.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ void TGraph::Draw(Option_t *option)
822822

823823
// If no option is specified, it is defined as "alp" in case there
824824
// no current pad or if the current pad as no axis defined.
825-
if (!strlen(option)) {
825+
if (!option || !strlen(option)) {
826826
if (gPad) {
827827
if (!gPad->GetListOfPrimitives()->FindObject("TFrame")) opt = "alp";
828828
} else {

hist/hist/src/TGraphTime.cxx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void TGraphTime::Paint(Option_t *option)
174174
void TGraphTime::SaveAnimatedGif(const char *filename) const
175175
{
176176
TObject *frame = gPad->GetPrimitive("frame");
177-
TList *list = 0;
177+
TList *list = nullptr;
178178
TObjLink *lnk;
179179

180180
for (Int_t s=0;s<fNsteps;s++) {
@@ -190,9 +190,12 @@ void TGraphTime::SaveAnimatedGif(const char *filename) const
190190
lnk = lnk->Next();
191191
}
192192
gPad->Update();
193-
if (strlen(filename) > 0) gPad->Print(Form("%s+",filename));
194-
else gPad->Print(Form("%s+",GetName()));
195-
if (fSleepTime > 0) gSystem->Sleep(fSleepTime);
193+
if (filename && strlen(filename) > 0)
194+
gPad->Print(Form("%s+", filename));
195+
else
196+
gPad->Print(Form("%s+", GetName()));
197+
if (fSleepTime > 0)
198+
gSystem->Sleep(fSleepTime);
196199
}
197200
}
198201
}

hist/hist/src/TH1.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6202,8 +6202,10 @@ void TH1::Paint(Option_t *option)
62026202
GetPainter(option);
62036203

62046204
if (fPainter) {
6205-
if (strlen(option) > 0) fPainter->Paint(option);
6206-
else fPainter->Paint(fOption.Data());
6205+
if (option && strlen(option) > 0)
6206+
fPainter->Paint(option);
6207+
else
6208+
fPainter->Paint(fOption.Data());
62076209
}
62086210
}
62096211

hist/hist/src/TMultiGraph.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ void TMultiGraph::Paint(Option_t *choptin)
11321132

11331133
char option[128];
11341134
strlcpy(option,choptin,128);
1135-
Int_t nch = strlen(choptin);
1135+
Int_t nch = choptin ? strlen(choptin) : 0;
11361136
for (Int_t i=0;i<nch;i++) option[i] = toupper(option[i]);
11371137

11381138
// Automatic color

hist/hist/src/TPrincipal.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ TPrincipal::TPrincipal(Int_t nVariables, Option_t *opt)
271271
fIsNormalised = kFALSE;
272272
fNumberOfDataPoints = 0;
273273
fNumberOfVariables = nVariables;
274-
while (strlen(opt) > 0) {
274+
while (opt && strlen(opt) > 0) {
275275
switch(*opt++) {
276276
case 'N':
277277
case 'n':
@@ -580,7 +580,7 @@ void TPrincipal::MakeHistograms(const char *name, Option_t *opt)
580580
Bool_t makeE = kFALSE;
581581
Bool_t makeS = kFALSE;
582582

583-
Int_t len = strlen(opt);
583+
Int_t len = opt ? strlen(opt) : 0;
584584
Int_t i,j,k;
585585
for (i = 0; i < len; i++) {
586586
switch (opt[i]) {
@@ -1090,7 +1090,7 @@ void TPrincipal::Print(Option_t *opt) const
10901090
Bool_t printS = kFALSE;
10911091
Bool_t printE = kFALSE;
10921092

1093-
Int_t len = strlen(opt);
1093+
Int_t len = opt ? strlen(opt) : 0;
10941094
for (Int_t i = 0; i < len; i++) {
10951095
switch (opt[i]) {
10961096
case 'V':

hist/hist/src/TProfile2D.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ TProfile2D * TProfile2D::Rebin2D(Int_t nxgroup ,Int_t nygroup,const char * newna
18201820
}
18211821
//nxgroup == nygroup == 1
18221822
else{
1823-
if((newname) && (strlen(newname) > 0))
1823+
if(newname && (strlen(newname) > 0))
18241824
return (TProfile2D*)Clone(newname);
18251825
else
18261826
return this;

0 commit comments

Comments
 (0)