fix kernel panic (vector out of range) in getReadoutRawString (#1250)

This commit is contained in:
Frank Haverland
2022-10-31 22:04:34 +01:00
committed by GitHub
parent b6b7587f0a
commit 1be49a75b1
4 changed files with 33 additions and 2 deletions

View File

@@ -972,7 +972,7 @@ string ClassFlowCNNGeneral::getReadoutRawString(int _analog)
{
string rt = "";
if (GENERAL[_analog]->ROI.size() == 0)
if (_analog >= GENERAL.size() || GENERAL[_analog]==NULL || GENERAL[_analog]->ROI.size() == 0)
return rt;
for (int i = 0; i < GENERAL[_analog]->ROI.size(); ++i)

View File

@@ -77,7 +77,7 @@ UnderTestPost* init_do_flow(std::vector<float> analog, std::vector<float> digits
for (int i = 0; i<analog.size(); i++) {
roi* anaROI = new roi();
string name = "ana_" + std::to_string(i);
string name = "ana_1" + std::to_string(i);
anaROI->name = name;
anaROI->result_float = analog[i];
gen_analog->ROI.push_back(anaROI);

View File

@@ -0,0 +1,27 @@
#include "test_flow_postrocess_helper.h"
void test_getReadoutRawString() {
// no ROIs setted up
UnderTestPost* _undertestPost = setUpClassFlowPostprocessing(Digital100, Analogue100);
string result = _undertestPost->flowAnalog->getReadoutRawString(0);
TEST_ASSERT_EQUAL_STRING("", result.c_str());
// setted value
general* gen_analog = _undertestPost->flowAnalog->GetGENERAL("default", true);
gen_analog->ROI.clear();
roi* anaROI = new roi();
string name = "ana_1";
anaROI->name = name;
anaROI->result_float = 5.5;
gen_analog->ROI.push_back(anaROI);
result = _undertestPost->flowAnalog->getReadoutRawString(0);
TEST_ASSERT_EQUAL_STRING("\t5.5", result.c_str());
}

View File

@@ -4,6 +4,7 @@
#include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp"
#include "components/jomjol-flowcontroll/test_flow_pp_negative.cpp"
#include "components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp"
#include "components/jomjol-flowcontroll/test_getReadoutRawString.cpp"
// SD-Card ////////////////////
#include "nvs_flash.h"
#include "esp_vfs_fat.h"
@@ -116,6 +117,9 @@ extern "C" void app_main()
RUN_TEST(test_doFlowPP1);
RUN_TEST(test_doFlowPP2);
RUN_TEST(test_doFlowPP3);
// getReadoutRawString test
RUN_TEST(test_getReadoutRawString);
UNITY_END();
}