@@ -35,8 +35,8 @@ A specialized TSelector for TTree::Draw.
3535#include " TStyle.h"
3636#include " TClass.h"
3737#include " TColor.h"
38- #include " strlcpy.h"
3938
39+ #include < string>
4040
4141const Int_t kCustomHistogram = BIT (17 );
4242
@@ -119,7 +119,7 @@ void TSelectorDraw::Begin(TTree *tree)
119119
120120 TString opt, abrt;
121121 char *hdefault = (char *)" htemp" ;
122- char * varexp = nullptr ;
122+ std::string varexp;
123123 Int_t i, j, hkeep;
124124 opt = option;
125125 opt.ToLower ();
@@ -213,9 +213,7 @@ void TSelectorDraw::Begin(TTree *tree)
213213 }
214214 // char *hname = (char*)strstr(varexp0,">>");
215215 if (hname) {
216- hkeep = 1 ;
217- varexp = new char [i+1 ];
218- varexp[0 ] = 0 ; // necessary if i=0
216+ hkeep = 1 ;
219217 bool hnameplus = false ;
220218 while (*hname == ' ' ) hname++;
221219 if (*hname == ' +' ) {
@@ -231,7 +229,7 @@ void TSelectorDraw::Begin(TTree *tree)
231229 }
232230
233231 if (i) {
234- strlcpy ( varexp, varexp0,i+ 1 );
232+ varexp = std::string ( varexp0, i); // everything before ">>"
235233
236234 Int_t mustdelete = 0 ;
237235 SetBit (kCustomHistogram );
@@ -378,7 +376,6 @@ void TSelectorDraw::Begin(TTree *tree)
378376 if (!fOldHistogram && oldObject && !oldObject->InheritsFrom (TH1::Class ())) {
379377 abrt.Form (" An object of type '%s' has the same name as the requested histo (%s)" , oldObject->IsA ()->GetName (), hname);
380378 Abort (abrt);
381- delete[] varexp;
382379 return ;
383380 }
384381 if (fOldHistogram && !hnameplus) fOldHistogram ->Reset (); // reset unless adding is wanted
@@ -401,7 +398,6 @@ void TSelectorDraw::Begin(TTree *tree)
401398 abrt.Form (" An object of type '%s' has the same name as the requested event list (%s)" ,
402399 oldObject->IsA ()->GetName (), hname);
403400 Abort (abrt);
404- delete[] varexp;
405401 return ;
406402 }
407403 if (!enlist) {
@@ -440,7 +436,6 @@ void TSelectorDraw::Begin(TTree *tree)
440436 abrt.Form (" An object of type '%s' has the same name as the requested event list (%s)" ,
441437 oldObject->IsA ()->GetName (), hname);
442438 Abort (abrt);
443- delete[] varexp;
444439 return ;
445440 }
446441 if (!evlist) {
@@ -452,7 +447,6 @@ void TSelectorDraw::Begin(TTree *tree)
452447 // We have been asked to reset the input list!!
453448 // Let's set it aside for now ...
454449 Abort (" Input and output lists are the same!" );
455- delete[] varexp;
456450 return ;
457451 }
458452 evlist->Reset ();
@@ -469,37 +463,32 @@ void TSelectorDraw::Begin(TTree *tree)
469463 } else { // if (hname)
470464 hname = hdefault;
471465 hkeep = 0 ;
472- const size_t varexpLen = strlen (varexp0) + 1 ;
473- varexp = new char [varexpLen];
474- strlcpy (varexp, varexp0, varexpLen);
466+ varexp = varexp0;
475467 if (gDirectory ) {
476468 fOldHistogram = (TH1 *)gDirectory ->Get (hname);
477469 if (fOldHistogram ) { fOldHistogram ->Delete (); fOldHistogram = nullptr ;}
478470 }
479471 }
480472
481473 // Decode varexp and selection
482- if (!CompileVariables (varexp, realSelection.GetTitle ())) {
483- abrt.Form (" Variable compilation failed: {%s,%s}" , varexp, realSelection.GetTitle ());
474+ if (!CompileVariables (varexp. c_str () , realSelection.GetTitle ())) {
475+ abrt.Form (" Variable compilation failed: {%s,%s}" , varexp. c_str () , realSelection.GetTitle ());
484476 Abort (abrt);
485- delete[] varexp;
486477 return ;
487478 }
488479 if (fDimension > 4 && !(optpara || optcandle || opt5d || opt.Contains (" goff" ))) {
489480 Abort (" Too many variables. Use the option \" para\" , \" gl5d\" or \" candle\" to display more than 4 variables." );
490- delete[] varexp;
491481 return ;
492482 }
493483 if (fDimension < 2 && (optpara || optcandle)) {
494484 Abort (" The options \" para\" and \" candle\" require at least 2 variables." );
495- delete[] varexp;
496485 return ;
497486 }
498487
499488 // In case fOldHistogram exists, check dimensionality
500489 Int_t nsel = strlen (selection);
501490 if (nsel > 1 ) {
502- htitle.Form (" %s {%s}" , varexp, selection);
491+ htitle.Form (" %s {%s}" , varexp. c_str () , selection);
503492 } else {
504493 htitle = varexp;
505494 }
@@ -535,7 +524,6 @@ void TSelectorDraw::Begin(TTree *tree)
535524 gROOT ->MakeDefCanvas ();
536525 if (!gPad ) {
537526 Abort (" Creation of default canvas failed" );
538- delete[] varexp;
539527 return ;
540528 }
541529 }
@@ -915,7 +903,6 @@ void TSelectorDraw::Begin(TTree *tree)
915903 else if (opt5d) fAction = 8 ;
916904 else fAction = 6 ;
917905 }
918- if (varexp) delete[] varexp;
919906 for (i = 0 ; i < fValSize ; ++i)
920907 fVarMultiple [i] = false ;
921908 fSelectMultiple = false ;
0 commit comments