diff --git a/core/base/src/TApplication.cxx b/core/base/src/TApplication.cxx index 12937ef7c0e87424c5b25995882d1227bf5fdd27..6d1533d7d468ba657e1a77c977bb2316617dcb0b 100644 --- a/core/base/src/TApplication.cxx +++ b/core/base/src/TApplication.cxx @@ -947,7 +947,7 @@ Long_t TApplication::ProcessLine(const char *line, Bool_t sync, Int_t *err) if (!strncmp(line, ".which", 6)) { char *fn = Strip(line+7); - char *s = strtok(fn, "+("); + char *s = strtok(fn, "+("); // this method does not need to be reentrant char *mac = gSystem->Which(TROOT::GetMacroPath(), s, kReadPermission); if (!mac) Printf("No macro %s in path %s", s, TROOT::GetMacroPath()); diff --git a/core/base/src/TPluginManager.cxx b/core/base/src/TPluginManager.cxx index 93ca741a0e0763f1524e7c62213585c6ce91b316..1f743367895eab1e9e735adcd3b919c5980b1b68 100644 --- a/core/base/src/TPluginManager.cxx +++ b/core/base/src/TPluginManager.cxx @@ -367,7 +367,7 @@ void TPluginManager::LoadHandlersFromEnv(TEnv *env) char *v = StrDup(val); s += 7; while (1) { - TString regexp = strtok(!cnt ? v : 0, "; "); + TString regexp = strtok(!cnt ? v : 0, "; "); // this method does not need to be reentrant if (regexp.IsNull()) break; TString clss = strtok(0, "; "); if (clss.IsNull()) break; diff --git a/core/clingutils/src/TClingUtils.cxx b/core/clingutils/src/TClingUtils.cxx index a7d51a41c647d0c2ca0eaeb94801e655d1385486..1a9eb1ca5651cfb78a5d22914f769e8f4cf77903 100644 --- a/core/clingutils/src/TClingUtils.cxx +++ b/core/clingutils/src/TClingUtils.cxx @@ -3049,7 +3049,7 @@ llvm::StringRef ROOT::TMetaUtils::DataMemberInfo__ValidArrayIndex(const clang::D // Now we go through all indentifiers const char *tokenlist = "*+-"; char *current = const_cast<char*>(working.c_str()); - current = strtok(current,tokenlist); + current = strtok(current,tokenlist); // this method does not need to be reentrant while (current!=0) { // Check the token diff --git a/core/meta/src/TDataMember.cxx b/core/meta/src/TDataMember.cxx index 73323fc27d1b672cbb2e6dc229e3e16d86f97e3e..aca2d90ce3aeb44851be89b2555eee43ae8506fa 100644 --- a/core/meta/src/TDataMember.cxx +++ b/core/meta/src/TDataMember.cxx @@ -270,12 +270,13 @@ void TDataMember::Init(bool afterReading) // If we found it - parsing... //let's cut the part lying between {} - ptr1 = strtok(opt_ptr ,"{}"); //starts tokenizing:extracts "*OPTION={" + char *rest; + ptr1 = strtok_r(opt_ptr, "{}", &rest); // starts tokenizing:extracts "*OPTION={" if (ptr1 == 0) { Fatal("TDataMember","Internal error, found \"*OPTION={\" but not \"{}\" in %s.",GetTitle()); return; } - ptr1 = strtok((char*)0,"{}"); //And now we have what we need in ptr1!!! + ptr1 = strtok_r(nullptr, "{}", &rest); // And now we have what we need in ptr1!!! if (ptr1 == 0) { Fatal("TDataMember","Internal error, found \"*OPTION={\" but not \"{}\" in %s.",GetTitle()); return; @@ -286,14 +287,14 @@ void TDataMember::Init(bool afterReading) // Let's extract sub-tokens extracted by ';' sign. // We'll put'em in an array for convenience; - // You have to do it in this manner because you cannot use nested 'strtok' + // You have to do it in this manner because you cannot use nested tokenizing char *tokens[256]; // a storage for these sub-tokens. token_cnt = 0; cnt = 0; do { //tokenizing loop - ptr1=strtok((char*) (cnt++ ? 0:opt),";"); + ptr1 = strtok_r((char *)(cnt++ ? nullptr : opt), ";", &rest); if (ptr1){ Int_t nch = strlen(ptr1)+1; tok=new char[nch]; @@ -305,14 +306,13 @@ void TDataMember::Init(bool afterReading) // OK! Now let's check whether we have Get/Set methods encode in any string for (i=0;i<token_cnt;i++) { - if (strstr(tokens[i],"GetMethod")) { - ptr1 = strtok(tokens[i],"\""); //tokenizing-strip text "GetMethod" + ptr1 = strtok_r(tokens[i], "\"", &rest); // tokenizing-strip text "GetMethod" if (ptr1 == 0) { Fatal("TDataMember","Internal error, found \"GetMethod\" but not \"\\\"\" in %s.",GetTitle()); return; } - ptr1 = strtok(0,"\""); //tokenizing - name is in ptr1! + ptr1 = strtok_r(nullptr, "\"", &rest); // tokenizing - name is in ptr1! if (ptr1 == 0) { Fatal("TDataMember","Internal error, found \"GetMethod\" but not \"\\\"\" in %s.",GetTitle()); return; @@ -326,12 +326,12 @@ void TDataMember::Init(bool afterReading) } if (strstr(tokens[i],"SetMethod")) { - ptr1 = strtok(tokens[i],"\""); + ptr1 = strtok_r(tokens[i], "\"", &rest); if (ptr1 == 0) { Fatal("TDataMember","Internal error, found \"SetMethod\" but not \"\\\"\" in %s.",GetTitle()); return; } - ptr1 = strtok((char*)0,"\""); //name of Setter in ptr1 + ptr1 = strtok_r(nullptr, "\"", &rest); // name of Setter in ptr1 if (ptr1 == 0) { Fatal("TDataMember","Internal error, found \"SetMethod\" but not \"\\\"\" in %s.",GetTitle()); return; @@ -349,12 +349,12 @@ void TDataMember::Init(bool afterReading) for (i=0;i<token_cnt;i++) { if (strstr(tokens[i],"Items")) { - ptr1 = strtok(tokens[i],"()"); + ptr1 = strtok_r(tokens[i], "()", &rest); if (ptr1 == 0) { Fatal("TDataMember","Internal error, found \"Items\" but not \"()\" in %s.",GetTitle()); return; } - ptr1 = strtok((char*)0,"()"); + ptr1 = strtok_r(nullptr, "()", &rest); if (ptr1 == 0) { Fatal("TDataMember","Internal error, found \"Items\" but not \"()\" in %s.",GetTitle()); return; @@ -368,9 +368,8 @@ void TDataMember::Init(bool afterReading) //We'll store it in TOptionListItem objects, because they're derived //from TObject and thus can be stored in TList. //It's not elegant but works. - do { - ptr1 = strtok(opt_cnt++ ? (char*)0:opts,","); //options extraction + ptr1 = strtok_r(opt_cnt++ ? nullptr : opts, ",", &rest); // options extraction if (ptr1) { TOptionListItem *it = new TOptionListItem(this,1,0,0,ptr1,""); optionlist->Add(it); @@ -393,8 +392,8 @@ void TDataMember::Init(bool afterReading) ptr1 = it->fOptName; // We will change the value of OptName ... but it is fine since we delete the object at the end of the loop. Bool_t islabel = (ptr1[0]=='\"'); // value is label or numerical? - ptr2 = strtok((char*)ptr1,"=\""); //extract LeftHandeSide - ptr3 = strtok(0,"=\""); //extract RightHandedSize + ptr2 = strtok_r((char *)ptr1, "=\"", &rest); // extract LeftHandeSide + ptr3 = strtok_r(nullptr, "=\"", &rest); // extract RightHandedSize if (islabel) { it1=new TOptionListItem(this,-9999,0,0,ptr3,ptr2); diff --git a/core/meta/src/TMethod.cxx b/core/meta/src/TMethod.cxx index 16574573d73e757d249c75b0bd2a467b767f0829..196e75c50f987531edc4c37000ca09b3f52bbe07 100644 --- a/core/meta/src/TMethod.cxx +++ b/core/meta/src/TMethod.cxx @@ -152,21 +152,22 @@ TDataMember *TMethod::FindDataMember() Int_t i; strlcpy(argstr,argstring,nchs+1); //let's move it to "workspace" copy - ptr2 = strtok(argstr,"{}"); //extract the data! + char *rest; + ptr2 = strtok_r(argstr, "{}", &rest); // extract the data! if (ptr2 == 0) { Fatal("FindDataMember","Internal error found '*ARGS=\"' but not \"{}\" in %s",GetCommentString()); delete [] argstr; return 0; } - ptr2 = strtok((char*)0,"{}"); + ptr2 = strtok_r((char *)0, "{}", &rest); //extract argument tokens// char *tokens[20]; Int_t cnt = 0; Int_t token_cnt = 0; do { - ptr1 = strtok((char*) (cnt++ ? 0:ptr2),",;"); //extract tokens - // separated by , or ; + ptr1 = strtok_r((char *)(cnt++ ? 0 : ptr2), ",;", &rest); // extract tokens + // separated by , or ; if (ptr1) { Int_t nch = strlen(ptr1); tok = new char[nch+1]; @@ -184,8 +185,8 @@ TDataMember *TMethod::FindDataMember() for (i=0; i<token_cnt;i++) { cnt = 0; - ptr1 = strtok(tokens[i],"=>"); //LeftHandedSide=methodarg - ptr2 = strtok((char*)0,"=>"); //RightHandedSide-points to datamember + ptr1 = strtok_r(tokens[i], "=>", &rest); // LeftHandedSide=methodarg + ptr2 = strtok_r((char *)0, "=>", &rest); // RightHandedSide-points to datamember //find the MethodArg a = 0; diff --git a/hist/hist/src/TGraph.cxx b/hist/hist/src/TGraph.cxx index be2f30787cdb80e84943db471504dfd6acccda19..76fc33f7479ed3b6a6fb3722b71adccaa55e8a22 100644 --- a/hist/hist/src/TGraph.cxx +++ b/hist/hist/src/TGraph.cxx @@ -456,12 +456,14 @@ TGraph::TGraph(const char *filename, const char *format, Option_t *option) Int_t value_idx = 0 ; // Looping + char *rest; while (std::getline(infile, line, '\n')) { if (line != "") { if (line[line.size() - 1] == char(13)) { // removing DOS CR character line.erase(line.end() - 1, line.end()) ; } - token = strtok(const_cast<char*>(line.c_str()), option) ; + //token = strtok_r(const_cast<char *>(line.c_str()), option, rest); + token = strtok_r(const_cast<char *>(line.c_str()), option, &rest); while (token != NULL && value_idx < 2) { if (isTokenToBeSaved[token_idx]) { token_str = TString(token) ; @@ -474,7 +476,7 @@ TGraph::TGraph(const char *filename, const char *format, Option_t *option) value_idx++ ; } } - token = strtok(NULL, option) ; //next token + token = strtok_r(NULL, option, &rest); // next token token_idx++ ; } if (!isLineToBeSkipped && value_idx == 2) { diff --git a/hist/hist/src/TGraph2D.cxx b/hist/hist/src/TGraph2D.cxx index 7e6997f6ad34579004d85f40ddb5e5e35ba81c02..734d858488c7b951d173388583943e9df312df6b 100644 --- a/hist/hist/src/TGraph2D.cxx +++ b/hist/hist/src/TGraph2D.cxx @@ -447,12 +447,13 @@ TGraph2D::TGraph2D(const char *filename, const char *format, Option_t *option) Int_t value_idx = 0 ; // Looping + char *rest; while (std::getline(infile, line, '\n')) { if (line != "") { if (line[line.size() - 1] == char(13)) { // removing DOS CR character line.erase(line.end() - 1, line.end()) ; } - token = strtok(const_cast<char*>(line.c_str()), option) ; + token = strtok_r(const_cast<char*>(line.c_str()), option, &rest); while (token != NULL && value_idx < 3) { if (isTokenToBeSaved[token_idx]) { token_str = TString(token) ; @@ -465,7 +466,7 @@ TGraph2D::TGraph2D(const char *filename, const char *format, Option_t *option) value_idx++ ; } } - token = strtok(NULL, option) ; //next token + token = strtok_r(NULL, option, &rest); // next token token_idx++ ; } if (!isLineToBeSkipped && value_idx == 3) { diff --git a/hist/hist/src/TGraphAsymmErrors.cxx b/hist/hist/src/TGraphAsymmErrors.cxx index e6c19eb88bc23c3bb32907db122336b9a9f7ffd9..9428f090d8d8db1ab10a2414e8fd7866a2d13b0f 100644 --- a/hist/hist/src/TGraphAsymmErrors.cxx +++ b/hist/hist/src/TGraphAsymmErrors.cxx @@ -379,12 +379,13 @@ TGraphAsymmErrors::TGraphAsymmErrors(const char *filename, const char *format, O Int_t value_idx = 0 ; // Looping + char *rest; while (std::getline(infile, line, '\n')) { if (line != "") { if (line[line.size() - 1] == char(13)) { // removing DOS CR character line.erase(line.end() - 1, line.end()) ; } - token = strtok(const_cast<char*>(line.c_str()), option) ; + token = strtok_r(const_cast<char*>(line.c_str()), option, &rest) ; while (token != NULL && value_idx < ntokensToBeSaved) { if (isTokenToBeSaved[token_idx]) { token_str = TString(token) ; @@ -397,7 +398,7 @@ TGraphAsymmErrors::TGraphAsymmErrors(const char *filename, const char *format, O value_idx++ ; } } - token = strtok(NULL, option) ; //next token + token = strtok_r(NULL, option, &rest); // next token token_idx++ ; } if (!isLineToBeSkipped && value_idx > 1) { //i.e. 2,3 or 4 diff --git a/hist/hist/src/TGraphErrors.cxx b/hist/hist/src/TGraphErrors.cxx index af3a8d7578c6161cb358776af1ca3d4d56cd3946..01e4a62f421f15d764d723c853099f0ca0055cad 100644 --- a/hist/hist/src/TGraphErrors.cxx +++ b/hist/hist/src/TGraphErrors.cxx @@ -313,12 +313,13 @@ TGraphErrors::TGraphErrors(const char *filename, const char *format, Option_t *o Int_t value_idx = 0 ; // Looping + char *rest; while (std::getline(infile, line, '\n')) { if (line != "") { if (line[line.size() - 1] == char(13)) { // removing DOS CR character line.erase(line.end() - 1, line.end()) ; } - token = strtok(const_cast<char*>(line.c_str()), option) ; + token = strtok_r(const_cast<char *>(line.c_str()), option, &rest); while (token != NULL && value_idx < ntokensToBeSaved) { if (isTokenToBeSaved[token_idx]) { token_str = TString(token) ; @@ -331,7 +332,7 @@ TGraphErrors::TGraphErrors(const char *filename, const char *format, Option_t *o value_idx++ ; } } - token = strtok(NULL, option) ; //next token + token = strtok_r(NULL, option, &rest); // next token token_idx++ ; } if (!isLineToBeSkipped && value_idx > 1) { //i.e. 2,3 or 4