Skip to content

Commit ccee2a3

Browse files
committed
[treeplayer] Replace a char array with a string.
Many delete[] and strlcpy could be replaced by changing one type.
1 parent a79ea41 commit ccee2a3

1 file changed

Lines changed: 8 additions & 20 deletions

File tree

tree/treeplayer/src/TSelectorDraw.cxx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ A specialized TSelector for TTree::Draw.
3535
#include "TStyle.h"
3636
#include "TClass.h"
3737
#include "TColor.h"
38-
#include "strlcpy.h"
38+
39+
#include <string>
3940

4041

4142
const Int_t kCustomHistogram = BIT(17);
@@ -119,7 +120,7 @@ void TSelectorDraw::Begin(TTree *tree)
119120

120121
TString opt, abrt;
121122
char *hdefault = (char *)"htemp";
122-
char *varexp = nullptr;
123+
std::string varexp;
123124
Int_t i, j, hkeep;
124125
opt = option;
125126
opt.ToLower();
@@ -214,8 +215,6 @@ void TSelectorDraw::Begin(TTree *tree)
214215
// char *hname = (char*)strstr(varexp0,">>");
215216
if (hname) {
216217
hkeep = 1;
217-
varexp = new char[i+1];
218-
varexp[0] = 0; //necessary if i=0
219218
bool hnameplus = false;
220219
while (*hname == ' ') hname++;
221220
if (*hname == '+') {
@@ -231,7 +230,7 @@ void TSelectorDraw::Begin(TTree *tree)
231230
}
232231

233232
if (i) {
234-
strlcpy(varexp,varexp0,i+1);
233+
varexp = std::string(varexp0,i); // everything before ">>"
235234

236235
Int_t mustdelete = 0;
237236
SetBit(kCustomHistogram);
@@ -378,7 +377,6 @@ void TSelectorDraw::Begin(TTree *tree)
378377
if (!fOldHistogram && oldObject && !oldObject->InheritsFrom(TH1::Class())) {
379378
abrt.Form("An object of type '%s' has the same name as the requested histo (%s)", oldObject->IsA()->GetName(), hname);
380379
Abort(abrt);
381-
delete[] varexp;
382380
return;
383381
}
384382
if (fOldHistogram && !hnameplus) fOldHistogram->Reset(); // reset unless adding is wanted
@@ -401,7 +399,6 @@ void TSelectorDraw::Begin(TTree *tree)
401399
abrt.Form("An object of type '%s' has the same name as the requested event list (%s)",
402400
oldObject->IsA()->GetName(), hname);
403401
Abort(abrt);
404-
delete[] varexp;
405402
return;
406403
}
407404
if (!enlist) {
@@ -446,7 +443,6 @@ void TSelectorDraw::Begin(TTree *tree)
446443
abrt.Form("An object of type '%s' has the same name as the requested event list (%s)",
447444
oldObject->IsA()->GetName(), hname);
448445
Abort(abrt);
449-
delete[] varexp;
450446
return;
451447
}
452448
if (!evlist) {
@@ -463,7 +459,6 @@ void TSelectorDraw::Begin(TTree *tree)
463459
// We have been asked to reset the input list!!
464460
// Let's set it aside for now ...
465461
Abort("Input and output lists are the same!");
466-
delete[] varexp;
467462
return;
468463
}
469464
evlist->Reset();
@@ -480,37 +475,32 @@ void TSelectorDraw::Begin(TTree *tree)
480475
} else { // if (hname)
481476
hname = hdefault;
482477
hkeep = 0;
483-
const size_t varexpLen = strlen(varexp0) + 1;
484-
varexp = new char[varexpLen];
485-
strlcpy(varexp, varexp0, varexpLen);
478+
varexp = varexp0;
486479
if (gDirectory) {
487480
fOldHistogram = (TH1*)gDirectory->Get(hname);
488481
if (fOldHistogram) { fOldHistogram->Delete(); fOldHistogram = nullptr;}
489482
}
490483
}
491484

492485
// Decode varexp and selection
493-
if (!CompileVariables(varexp, realSelection.GetTitle())) {
494-
abrt.Form("Variable compilation failed: {%s,%s}", varexp, realSelection.GetTitle());
486+
if (!CompileVariables(varexp.data(), realSelection.GetTitle())) {
487+
abrt.Form("Variable compilation failed: {%s,%s}", varexp.data(), realSelection.GetTitle());
495488
Abort(abrt);
496-
delete[] varexp;
497489
return;
498490
}
499491
if (fDimension > 4 && !(optpara || optcandle || opt5d || opt.Contains("goff"))) {
500492
Abort("Too many variables. Use the option \"para\", \"gl5d\" or \"candle\" to display more than 4 variables.");
501-
delete[] varexp;
502493
return;
503494
}
504495
if (fDimension < 2 && (optpara || optcandle)) {
505496
Abort("The options \"para\" and \"candle\" require at least 2 variables.");
506-
delete[] varexp;
507497
return;
508498
}
509499

510500
// In case fOldHistogram exists, check dimensionality
511501
Int_t nsel = strlen(selection);
512502
if (nsel > 1) {
513-
htitle.Form("%s {%s}", varexp, selection);
503+
htitle.Form("%s {%s}", varexp.data(), selection);
514504
} else {
515505
htitle = varexp;
516506
}
@@ -546,7 +536,6 @@ void TSelectorDraw::Begin(TTree *tree)
546536
gROOT->MakeDefCanvas();
547537
if (!gPad) {
548538
Abort("Creation of default canvas failed");
549-
delete[] varexp;
550539
return;
551540
}
552541
}
@@ -926,7 +915,6 @@ void TSelectorDraw::Begin(TTree *tree)
926915
else if (opt5d) fAction = 8;
927916
else fAction = 6;
928917
}
929-
if (varexp) delete[] varexp;
930918
for (i = 0; i < fValSize; ++i)
931919
fVarMultiple[i] = false;
932920
fSelectMultiple = false;

0 commit comments

Comments
 (0)