Skip to content

Commit d128f4e

Browse files
MISRA/AUTOSAR: remove flexible array (#192)
* MISRA/AUTOSAR: remove flexible array * CI: add apt update * docker: update clang alternatives Fixes #183 Co-authored-by: Pavel Kirienko <[email protected]>
1 parent 224adff commit d128f4e

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
wget https://apt.llvm.org/llvm.sh
2222
chmod +x llvm.sh
2323
sudo ./llvm.sh $LLVM_VERSION
24+
sudo apt update -y && sudo apt upgrade -y
2425
sudo apt-get -y install gcc-multilib g++-multilib clang-tidy-$LLVM_VERSION
2526
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-$LLVM_VERSION 50
2627
clang-tidy --version
@@ -57,7 +58,9 @@ jobs:
5758
cxx-compiler: clang++
5859
steps:
5960
- uses: actions/checkout@v2
60-
- run: sudo apt install gcc-multilib g++-multilib
61+
- run: |
62+
sudo apt update -y && sudo apt upgrade -y
63+
sudo apt install gcc-multilib g++-multilib
6164
- run: >
6265
cmake
6366
-B ${{ github.workspace }}/build
@@ -85,6 +88,7 @@ jobs:
8588
steps:
8689
- uses: actions/checkout@v2
8790
- run: |
91+
sudo apt update -y && sudo apt upgrade -y
8892
sudo apt install gcc-avr avr-libc
8993
avr-gcc --version
9094
- run: avr-gcc libcanard/*.c -c -std=c99 -mmcu=${{ env.mcu }} ${{ env.flags }}
@@ -117,7 +121,9 @@ jobs:
117121
fetch-depth: 0
118122

119123
- name: Install Dependencies
120-
run: sudo apt install gcc-multilib g++-multilib
124+
run: |
125+
sudo apt update -y && sudo apt upgrade -y
126+
sudo apt install -y gcc-multilib g++-multilib
121127
122128
- name: Set up JDK
123129
uses: actions/setup-java@v1

libcanard/canard.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,7 @@ CANARD_PRIVATE TransferCRC crcAdd(const TransferCRC crc, const size_t size, cons
151151
typedef struct TxItem
152152
{
153153
CanardTxQueueItem base;
154-
155-
// Intentional violation of MISRA: this flex array is the lesser of three evils. The other two are:
156-
// - Make the payload pointer point to the remainder of the allocated memory following this structure.
157-
// The pointer is bad because it requires us to use pointer arithmetics.
158-
// - Use a separate memory allocation for data. This is terribly wasteful (both time & memory).
159-
uint8_t payload_buffer[]; // NOSONAR
154+
uint8_t payload_buffer[CANARD_MTU_MAX];
160155
} TxItem;
161156

162157
/// Chain of TX frames prepared for insertion into a TX queue.
@@ -304,7 +299,7 @@ CANARD_PRIVATE TxItem* txAllocateQueueItem(CanardInstance* const ins,
304299
{
305300
CANARD_ASSERT(ins != NULL);
306301
CANARD_ASSERT(payload_size > 0U);
307-
TxItem* const out = (TxItem*) ins->memory_allocate(ins, sizeof(TxItem) + payload_size);
302+
TxItem* const out = (TxItem*) ins->memory_allocate(ins, sizeof(TxItem) - CANARD_MTU_MAX + payload_size);
308303
if (out != NULL)
309304
{
310305
out->base.base.up = NULL;

libcanard/canard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ extern "C" {
114114
/// Per the recommendations given in the UAVCAN/CAN Specification, other MTU values should not be used.
115115
#define CANARD_MTU_CAN_CLASSIC 8U
116116
#define CANARD_MTU_CAN_FD 64U
117+
#define CANARD_MTU_MAX CANARD_MTU_CAN_FD
117118

118119
/// Parameter ranges are inclusive; the lower bound is zero for all. See UAVCAN/CAN Specification for background.
119120
#define CANARD_SUBJECT_ID_MAX 8191U

tools/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ ENV DEBIAN_FRONTEND noninteractive
1111
RUN apt-get update && apt-get -y upgrade
1212
RUN apt-get -y --no-install-recommends install \
1313
build-essential cmake gcc-multilib g++-multilib \
14-
clang-tidy-13 clang-format-13 \
14+
clang-tidy-12 clang-format-12 \
1515
gcc-avr avr-libc \
1616
sudo curl git ca-certificates
1717

18+
RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-12 10
19+
RUN update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-12 10
20+
1821
# borrowed from MAVSDK https://github.com/mavlink/MAVSDK/blob/main/docker/Dockerfile-Ubuntu-20.04
1922
RUN curl -L https://github.com/ncopa/su-exec/archive/dddd1567b7c76365e1e0aac561287975020a8fad.tar.gz | tar xvz && \
2023
cd su-exec-* && make && mv su-exec /usr/local/bin && cd .. && rm -rf su-exec-*

0 commit comments

Comments
 (0)