From de14053cb6048bb67e6e12e50f03d1b6456ee7ae Mon Sep 17 00:00:00 2001 From: Sean McBride <sean@rogue-research.com> Date: Tue, 7 Apr 2020 12:39:50 -0400 Subject: [PATCH] Fixed Address Sanitizer stack-use-after-scope error in test Error was: AddressSanitizer: stack-use-after-scope TestOrderStatistics.cxx:530 in TestOrderStatistics(int, char**) Fixed by sticking with std::string instead of raw char*. Interestingly, another part of the file was already doing this correctly. (cherry picked from commit e6890bbf25918a7e6fbce8c4ea2d2c84689273de) --- .../Statistics/Testing/Cxx/TestOrderStatistics.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Filters/Statistics/Testing/Cxx/TestOrderStatistics.cxx b/Filters/Statistics/Testing/Cxx/TestOrderStatistics.cxx index 3966430e115..8972d4c26f5 100644 --- a/Filters/Statistics/Testing/Cxx/TestOrderStatistics.cxx +++ b/Filters/Statistics/Testing/Cxx/TestOrderStatistics.cxx @@ -461,8 +461,8 @@ int TestOrderStatistics(int, char*[]) int frequVal = it->second; sum12 += frequVal; - std::string lowerVal = outputQuantiles2->GetValueByName(prevqIdx, "Text").ToString(); - std::string upperVal = outputQuantiles2->GetValueByName(quantIdx, "Text").ToString(); + const std::string& lowerVal = outputQuantiles2->GetValueByName(prevqIdx, "Text").ToString(); + const std::string& upperVal = outputQuantiles2->GetValueByName(quantIdx, "Text").ToString(); char midVal = (lowerVal[0] + upperVal[0] + 1) / 2; histo12Repr[quantIdx] = midVal; @@ -525,13 +525,13 @@ int TestOrderStatistics(int, char*[]) int frequVal = it->second; sum100 += frequVal; - const char* lowerVal = outputQuantiles2->GetValueByName(prevqIdx, "Text").ToString(); - const char* upperVal = outputQuantiles2->GetValueByName(quantIdx, "Text").ToString(); - char midVal = (*lowerVal + *upperVal + 1) / 2; + const std::string& lowerVal = outputQuantiles2->GetValueByName(prevqIdx, "Text").ToString(); + const std::string& upperVal = outputQuantiles2->GetValueByName(quantIdx, "Text").ToString(); + char midVal = (lowerVal[0] + upperVal[0] + 1) / 2; histo100Repr[quantIdx] = midVal; - cout << " interval " << quantIdx << (quantIdx > 1 ? ": ]" : ": [") << *lowerVal << " - " - << *upperVal << "] represented by " << midVal << " with frequency " << frequVal << "\n"; + cout << " interval " << quantIdx << (quantIdx > 1 ? ": ]" : ": [") << lowerVal[0] << " - " + << upperVal[0] << "] represented by " << midVal << " with frequency " << frequVal << "\n"; } // Verify that we retrieve the total count -- GitLab