diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d3b2028..343283b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,7 @@ jobs: wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh $LLVM_VERSION + sudo apt update -y && sudo apt upgrade -y sudo apt-get -y install gcc-multilib g++-multilib clang-tidy-$LLVM_VERSION sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-$LLVM_VERSION 50 clang-tidy --version @@ -57,7 +58,9 @@ jobs: cxx-compiler: clang++ steps: - uses: actions/checkout@v2 - - run: sudo apt install gcc-multilib g++-multilib + - run: | + sudo apt update -y && sudo apt upgrade -y + sudo apt install gcc-multilib g++-multilib - run: > cmake -B ${{ github.workspace }}/build @@ -85,6 +88,7 @@ jobs: steps: - uses: actions/checkout@v2 - run: | + sudo apt update -y && sudo apt upgrade -y sudo apt install gcc-avr avr-libc avr-gcc --version - run: avr-gcc libcanard/*.c -c -std=c99 -mmcu=${{ env.mcu }} ${{ env.flags }} @@ -117,7 +121,9 @@ jobs: fetch-depth: 0 - name: Install Dependencies - run: sudo apt install gcc-multilib g++-multilib + run: | + sudo apt update -y && sudo apt upgrade -y + sudo apt install -y gcc-multilib g++-multilib - name: Set up JDK uses: actions/setup-java@v1 diff --git a/libcanard/canard.c b/libcanard/canard.c index 685e8fc..e2ab4ae 100644 --- a/libcanard/canard.c +++ b/libcanard/canard.c @@ -151,12 +151,7 @@ CANARD_PRIVATE TransferCRC crcAdd(const TransferCRC crc, const size_t size, cons typedef struct TxItem { CanardTxQueueItem base; - - // Intentional violation of MISRA: this flex array is the lesser of three evils. The other two are: - // - Make the payload pointer point to the remainder of the allocated memory following this structure. - // The pointer is bad because it requires us to use pointer arithmetics. - // - Use a separate memory allocation for data. This is terribly wasteful (both time & memory). - uint8_t payload_buffer[]; // NOSONAR + uint8_t payload_buffer[CANARD_MTU_MAX]; } TxItem; /// Chain of TX frames prepared for insertion into a TX queue. @@ -304,7 +299,7 @@ CANARD_PRIVATE TxItem* txAllocateQueueItem(CanardInstance* const ins, { CANARD_ASSERT(ins != NULL); CANARD_ASSERT(payload_size > 0U); - TxItem* const out = (TxItem*) ins->memory_allocate(ins, sizeof(TxItem) + payload_size); + TxItem* const out = (TxItem*) ins->memory_allocate(ins, sizeof(TxItem) - CANARD_MTU_MAX + payload_size); if (out != NULL) { out->base.base.up = NULL; diff --git a/libcanard/canard.h b/libcanard/canard.h index c2737a8..47f06f4 100644 --- a/libcanard/canard.h +++ b/libcanard/canard.h @@ -114,6 +114,7 @@ extern "C" { /// Per the recommendations given in the UAVCAN/CAN Specification, other MTU values should not be used. #define CANARD_MTU_CAN_CLASSIC 8U #define CANARD_MTU_CAN_FD 64U +#define CANARD_MTU_MAX CANARD_MTU_CAN_FD /// Parameter ranges are inclusive; the lower bound is zero for all. See UAVCAN/CAN Specification for background. #define CANARD_SUBJECT_ID_MAX 8191U diff --git a/tools/Dockerfile b/tools/Dockerfile index 3f71063..769145a 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -11,10 +11,13 @@ ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get -y upgrade RUN apt-get -y --no-install-recommends install \ build-essential cmake gcc-multilib g++-multilib \ - clang-tidy-13 clang-format-13 \ + clang-tidy-12 clang-format-12 \ gcc-avr avr-libc \ sudo curl git ca-certificates +RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-12 10 +RUN update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-12 10 + # borrowed from MAVSDK https://github.com/mavlink/MAVSDK/blob/main/docker/Dockerfile-Ubuntu-20.04 RUN curl -L https://github.com/ncopa/su-exec/archive/dddd1567b7c76365e1e0aac561287975020a8fad.tar.gz | tar xvz && \ cd su-exec-* && make && mv su-exec /usr/local/bin && cd .. && rm -rf su-exec-*