Merge branch 'thelsing:master' into master

This commit is contained in:
OnlineCaveman 2022-10-27 14:29:49 +02:00 committed by GitHub
commit eb0d62666d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 21 deletions

View File

@ -18,32 +18,27 @@ jobs:
analyze: analyze:
name: Analyze name: Analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
# Override automatic language detection by changing the below list # Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['cpp'] language: ['cpp', 'python']
# Learn more... # Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v2
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file. # If you wish to specify custom queries, you can do so here or in a config file.
@ -54,7 +49,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@v1 uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl # 📚 https://git.io/JvXDl
@ -68,4 +63,4 @@ jobs:
# make release # make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1 uses: github/codeql-action/analyze@v2

View File

@ -37,9 +37,28 @@ uint16_t AddressTableObject::getGroupAddress(uint16_t tsap)
uint16_t AddressTableObject::getTsap(uint16_t addr) uint16_t AddressTableObject::getTsap(uint16_t addr)
{ {
uint16_t size = entryCount(); uint16_t size = entryCount();
#ifdef USE_BINSEARCH
uint16_t low,high,i;
low = 1;
high = size;
while(low <= high)
{
i = (low+high)/2;
uint16_t ga = ntohs(_groupAddresses[i]);
if (ga == addr)
return i;
if(addr < ga)
high = i - 1;
else
low = i + 1 ;
}
#else
for (uint16_t i = 1; i <= size; i++) for (uint16_t i = 1; i <= size; i++)
if (ntohs(_groupAddresses[i]) == addr) if (ntohs(_groupAddresses[i]) == addr)
return i; return i;
#endif
return 0; return 0;
} }
@ -58,12 +77,7 @@ const uint8_t* AddressTableObject::restore(const uint8_t* buffer)
bool AddressTableObject::contains(uint16_t addr) bool AddressTableObject::contains(uint16_t addr)
{ {
uint16_t size = entryCount(); return (getTsap(addr) > 0);
for (uint16_t i = 1; i <= size; i++)
if (ntohs(_groupAddresses[i]) == addr)
return true;
return false;
} }
void AddressTableObject::beforeStateChange(LoadState& newState) void AddressTableObject::beforeStateChange(LoadState& newState)

View File

@ -50,11 +50,35 @@ const uint8_t* AssociationTableObject::restore(const uint8_t* buffer)
int32_t AssociationTableObject::translateAsap(uint16_t asap) int32_t AssociationTableObject::translateAsap(uint16_t asap)
{ {
uint16_t entries = entryCount(); uint16_t entries = entryCount();
#ifdef USE_BINSEARCH
uint16_t low,high,i;
low = 0;
high = entries-1;
while(low <= high)
{
i = (low+high)/2;
uint16_t asap_i = getASAP(i);
if (asap_i == asap)
{
// as the binary search does not hit the first element in a list with identical items,
// search downwards to return the first occurence in the table
while(getASAP(--i) == asap)
;
return getTSAP(i+1);
}
if(asap_i > asap)
high = i - 1;
else
low = i + 1 ;
}
#else
for (uint16_t i = 0; i < entries; i++) for (uint16_t i = 0; i < entries; i++)
{ {
if (getASAP(i) == asap) if (getASAP(i) == asap)
return getTSAP(i); return getTSAP(i);
} }
#endif
return -1; return -1;
} }