Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misra: remove flexible array #192

Merged
merged 7 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions libcanard/canard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions libcanard/canard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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-*
Expand Down