From 2934782d3c726d1ead444f7968c629b7747b9350 Mon Sep 17 00:00:00 2001 From: Marco Scholl Date: Sun, 6 Aug 2023 18:03:09 +0200 Subject: [PATCH] fix: check initalize AssociationTableData --- src/knx/association_table_object.cpp | 60 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/knx/association_table_object.cpp b/src/knx/association_table_object.cpp index 0517085..ad1761c 100644 --- a/src/knx/association_table_object.cpp +++ b/src/knx/association_table_object.cpp @@ -53,42 +53,44 @@ void AssociationTableObject::prepareBinarySearch() // we iterate through all ASAP // the first n ASAP are sorted (strictly increasing number), these are assigning sending TSAP // the remaining ASAP have to be all repetitions, otherwise we set sortedEntryCount to 0, which forces linear search - for (uint16_t idx = 0; idx < entryCount(); idx++) - { - currentASAP = getASAP(idx); - if (sortedEntryCount) + if(_tableData != nullptr) { + for (uint16_t idx = 0; idx < entryCount(); idx++) { - // look if the remaining ASAP exist in the previously sorted list. - while (lookupIdx < sortedEntryCount) + currentASAP = getASAP(idx); + if (sortedEntryCount) { - lookupASAP = getASAP(lookupIdx); - if (currentASAP <= lookupASAP) - break; // while - else - lookupIdx++; + // look if the remaining ASAP exist in the previously sorted list. + while (lookupIdx < sortedEntryCount) + { + lookupASAP = getASAP(lookupIdx); + if (currentASAP <= lookupASAP) + break; // while + else + lookupIdx++; + } + if (currentASAP < lookupASAP || lookupIdx >= sortedEntryCount) + { + // a new ASAP found, we force linear search + sortedEntryCount = 0; + break; // for + } } - if (currentASAP < lookupASAP || lookupIdx >= sortedEntryCount) - { - // a new ASAP found, we force linear search - sortedEntryCount = 0; - break; // for - } - } - else - { - // check for strictly increasing ASAP - if (currentASAP > lastASAP) - lastASAP = currentASAP; else { - sortedEntryCount = idx; // last found index indicates end of sorted list - idx--; // current item has to be handled as remaining ASAP + // check for strictly increasing ASAP + if (currentASAP > lastASAP) + lastASAP = currentASAP; + else + { + sortedEntryCount = idx; // last found index indicates end of sorted list + idx--; // current item has to be handled as remaining ASAP + } } } - } - // in case complete table is strictly increasing - if (lookupIdx == 0 && sortedEntryCount == 0) - sortedEntryCount = entryCount(); + // in case complete table is strictly increasing + if (lookupIdx == 0 && sortedEntryCount == 0) + sortedEntryCount = entryCount(); + } #endif }