@@ -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
4142const 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) {
@@ -440,7 +437,6 @@ void TSelectorDraw::Begin(TTree *tree)
440437 abrt.Form (" An object of type '%s' has the same name as the requested event list (%s)" ,
441438 oldObject->IsA ()->GetName (), hname);
442439 Abort (abrt);
443- delete[] varexp;
444440 return ;
445441 }
446442 if (!evlist) {
@@ -452,7 +448,6 @@ void TSelectorDraw::Begin(TTree *tree)
452448 // We have been asked to reset the input list!!
453449 // Let's set it aside for now ...
454450 Abort (" Input and output lists are the same!" );
455- delete[] varexp;
456451 return ;
457452 }
458453 evlist->Reset ();
@@ -469,37 +464,32 @@ void TSelectorDraw::Begin(TTree *tree)
469464 } else { // if (hname)
470465 hname = hdefault;
471466 hkeep = 0 ;
472- const size_t varexpLen = strlen (varexp0) + 1 ;
473- varexp = new char [varexpLen];
474- strlcpy (varexp, varexp0, varexpLen);
467+ varexp = varexp0;
475468 if (gDirectory ) {
476469 fOldHistogram = (TH1 *)gDirectory ->Get (hname);
477470 if (fOldHistogram ) { fOldHistogram ->Delete (); fOldHistogram = nullptr ;}
478471 }
479472 }
480473
481474 // Decode varexp and selection
482- if (!CompileVariables (varexp, realSelection.GetTitle ())) {
483- abrt.Form (" Variable compilation failed: {%s,%s}" , varexp, realSelection.GetTitle ());
475+ if (!CompileVariables (varexp. data () , realSelection.GetTitle ())) {
476+ abrt.Form (" Variable compilation failed: {%s,%s}" , varexp. data () , realSelection.GetTitle ());
484477 Abort (abrt);
485- delete[] varexp;
486478 return ;
487479 }
488480 if (fDimension > 4 && !(optpara || optcandle || opt5d || opt.Contains (" goff" ))) {
489481 Abort (" Too many variables. Use the option \" para\" , \" gl5d\" or \" candle\" to display more than 4 variables." );
490- delete[] varexp;
491482 return ;
492483 }
493484 if (fDimension < 2 && (optpara || optcandle)) {
494485 Abort (" The options \" para\" and \" candle\" require at least 2 variables." );
495- delete[] varexp;
496486 return ;
497487 }
498488
499489 // In case fOldHistogram exists, check dimensionality
500490 Int_t nsel = strlen (selection);
501491 if (nsel > 1 ) {
502- htitle.Form (" %s {%s}" , varexp, selection);
492+ htitle.Form (" %s {%s}" , varexp. data () , selection);
503493 } else {
504494 htitle = varexp;
505495 }
@@ -535,7 +525,6 @@ void TSelectorDraw::Begin(TTree *tree)
535525 gROOT ->MakeDefCanvas ();
536526 if (!gPad ) {
537527 Abort (" Creation of default canvas failed" );
538- delete[] varexp;
539528 return ;
540529 }
541530 }
@@ -915,7 +904,6 @@ void TSelectorDraw::Begin(TTree *tree)
915904 else if (opt5d) fAction = 8 ;
916905 else fAction = 6 ;
917906 }
918- if (varexp) delete[] varexp;
919907 for (i = 0 ; i < fValSize ; ++i)
920908 fVarMultiple [i] = false ;
921909 fSelectMultiple = false ;
0 commit comments