Skip to content

Commit 3c2f33c

Browse files
committed
Apply clang-tidy
1 parent 081225e commit 3c2f33c

File tree

4 files changed

+80
-32
lines changed

4 files changed

+80
-32
lines changed

.clang-tidy

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
Checks: "*,
3+
-abseil-*,
4+
-altera-*,
5+
-android-*,
6+
-fuchsia-*,
7+
-google-*,
8+
-llvm*,
9+
-modernize-use-trailing-return-type,
10+
-zircon-*,
11+
-readability-else-after-return,
12+
-readability-static-accessed-through-instance,
13+
-readability-avoid-const-params-in-decls,
14+
-cppcoreguidelines-non-private-member-variables-in-classes,
15+
-misc-non-private-member-variables-in-classes,
16+
"
17+
WarningsAsErrors: ''
18+
HeaderFilterRegex: ''
19+
FormatStyle: none

.vscode/settings.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
"lwevt_type.h": "c",
55
"lwevt.h": "c",
66
"string.h": "c",
7-
"lwevt_opt.h": "c"
7+
"lwevt_opt.h": "c",
8+
"streambuf": "c",
9+
"lwmem.h": "c",
10+
"lwmem_opt.h": "c",
11+
"array": "c",
12+
"string_view": "c",
13+
"initializer_list": "c"
814
},
9-
"esbonio.sphinx.confDir": ""
15+
"esbonio.sphinx.confDir": "",
16+
"C_Cpp.codeAnalysis.clangTidy.useBuildPath": true
1017
}

lwmem/src/include/lwmem/lwmem_opt.h

+27
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,33 @@ extern "C" {
103103
#define LWMEM_CFG_ENABLE_STATS 0
104104
#endif
105105

106+
/**
107+
* \brief Memory set function
108+
*
109+
* \note Function footprint is the same as \ref memset
110+
*/
111+
#ifndef LWMEM_MEMSET
112+
#define LWMEM_MEMSET(dst, val, len) memset((dst), (val), (len))
113+
#endif
114+
115+
/**
116+
* \brief Memory copy function
117+
*
118+
* \note Function footprint is the same as \ref memcpy
119+
*/
120+
#ifndef LWMEM_MEMCPY
121+
#define LWMEM_MEMCPY(dst, src, len) memcpy((dst), (src), (len))
122+
#endif
123+
124+
/**
125+
* \brief Memory move function
126+
*
127+
* \note Function footprint is the same as \ref memmove
128+
*/
129+
#ifndef LWMEM_MEMMOVE
130+
#define LWMEM_MEMMOVE(dst, src, len) memmove((dst), (src), (len))
131+
#endif
132+
106133
/**
107134
* \}
108135
*/

lwmem/src/lwmem/lwmem.c

+25-30
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
#include "system/lwmem_sys.h"
4040
#endif /* LWMEM_CFG_OS */
4141

42-
#define LWMEM_MEMSET memset
43-
#define LWMEM_MEMCPY memcpy
44-
#define LWMEM_MEMMOVE memmove
45-
4642
/**
4743
* \brief Transform alignment number (power of `2`) to bits
4844
*/
@@ -176,19 +172,19 @@ static lwmem_t lwmem_default;
176172
* \brief Get region aligned start address and aligned size
177173
* \param[in] region: Region to check for size and address
178174
* \param[out] msa: Memory start address output variable
179-
* \param[out] ms: Memory size output variable
175+
* \param[out] msz: Memory size output variable
180176
* \return `1` if region valid, `0` otherwise
181177
*/
182178
static uint8_t
183-
prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* ms) {
179+
prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* msz) {
184180
size_t mem_size;
185181
uint8_t* mem_start_addr;
186182

187-
if (region == NULL || msa == NULL || ms == NULL) {
183+
if (region == NULL || msa == NULL || msz == NULL) {
188184
return 0;
189185
}
190186
*msa = NULL;
191-
*ms = 0;
187+
*msz = 0;
192188

193189
/* Check region size and align it to config bits */
194190
mem_size = region->size & ~LWMEM_ALIGN_BITS; /* Size does not include lower bits */
@@ -209,7 +205,7 @@ prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* ms
209205
/* Check final memory size */
210206
if (mem_size >= (2 * LWMEM_BLOCK_MIN_SIZE)) {
211207
*msa = mem_start_addr;
212-
*ms = mem_size;
208+
*msz = mem_size;
213209

214210
return 1;
215211
}
@@ -219,22 +215,22 @@ prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* ms
219215
/**
220216
* \brief Insert free block to linked list of free blocks
221217
* \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance
222-
* \param[in] nb: New free block to insert into linked list
218+
* \param[in] nblk: New free block to insert into linked list
223219
*/
224220
static void
225-
prv_insert_free_block(lwmem_t* const lwobj, lwmem_block_t* nb) {
221+
prv_insert_free_block(lwmem_t* const lwobj, lwmem_block_t* nblk) {
226222
lwmem_block_t* prev;
227223

228224
/* Check valid inputs */
229-
if (nb == NULL) {
225+
if (nblk == NULL) {
230226
return;
231227
}
232228

233229
/*
234230
* Try to find position to put new block in-between
235231
* Search until all free block addresses are lower than entry block
236232
*/
237-
for (prev = &(lwobj->start_block); prev != NULL && prev->next < nb; prev = prev->next) {}
233+
for (prev = &(lwobj->start_block); prev != NULL && prev->next < nblk; prev = prev->next) {}
238234

239235
/* This is hard error with wrong memory usage */
240236
if (prev == NULL) {
@@ -254,10 +250,10 @@ prv_insert_free_block(lwmem_t* const lwobj, lwmem_block_t* nb) {
254250
* By doing this, we protect data left by app
255251
* and we make sure new allocations cannot see old information
256252
*/
257-
if (nb != NULL) {
258-
void* p = LWMEM_GET_PTR_FROM_BLOCK(nb);
259-
if (p != NULL) {
260-
LWMEM_MEMSET(p, 0x00, nb->size - LWMEM_BLOCK_META_SIZE);
253+
if (nblk != NULL) {
254+
void* ptr = LWMEM_GET_PTR_FROM_BLOCK(nblk);
255+
if (ptr != NULL) {
256+
LWMEM_MEMSET(ptr, 0x00, nblk->size - LWMEM_BLOCK_META_SIZE);
261257
}
262258
}
263259
#endif /* LWMEM_CFG_RESET_MEMORY */
@@ -266,10 +262,10 @@ prv_insert_free_block(lwmem_t* const lwobj, lwmem_block_t* nb) {
266262
* Check if previous block and input block together create one big contiguous block
267263
* If this is the case, merge blocks together and increase previous block by input block size
268264
*/
269-
if ((LWMEM_TO_BYTE_PTR(prev) + prev->size) == LWMEM_TO_BYTE_PTR(nb)) {
270-
prev->size += nb->size; /* Increase current block by size of new block */
271-
nb = prev; /* New block and current are now the same thing */
272-
/*
265+
if ((LWMEM_TO_BYTE_PTR(prev) + prev->size) == LWMEM_TO_BYTE_PTR(nblk)) {
266+
prev->size += nblk->size; /* Increase current block by size of new block */
267+
nblk = prev; /* New block and current are now the same thing */
268+
/*
273269
* It is important to set new block as current one
274270
* as this allows merging previous and next blocks together with new block
275271
* at the same time; follow next steps
@@ -281,25 +277,24 @@ prv_insert_free_block(lwmem_t* const lwobj, lwmem_block_t* nb) {
281277
* Do not merge with "end of region" indication (commented part of if statement)
282278
*/
283279
if (prev->next != NULL && prev->next->size > 0 /* Do not remove "end of region" indicator in each region */
284-
&& (LWMEM_TO_BYTE_PTR(nb) + nb->size) == LWMEM_TO_BYTE_PTR(prev->next)) {
280+
&& (LWMEM_TO_BYTE_PTR(nblk) + nblk->size) == LWMEM_TO_BYTE_PTR(prev->next)) {
285281
if (prev->next == lwobj->end_block) { /* Does it points to the end? */
286-
nb->next = lwobj->end_block; /* Set end block pointer */
282+
nblk->next = lwobj->end_block; /* Set end block pointer */
287283
} else {
288-
nb->size +=
289-
prev->next
290-
->size; /* Expand of current block for size of next free block which is right behind new block */
291-
nb->next = prev->next->next; /* Next free is pointed to the next one of previous next */
284+
/* Expand of current block for size of next free block which is right behind new block */
285+
nblk->size += prev->next->size;
286+
nblk->next = prev->next->next; /* Next free is pointed to the next one of previous next */
292287
}
293288
} else {
294-
nb->next = prev->next; /* Set next of input block as next of current one */
289+
nblk->next = prev->next; /* Set next of input block as next of current one */
295290
}
296291

297292
/*
298293
* If new block has not been set as current (and expanded),
299294
* then link them together, otherwise ignore as it would point to itself
300295
*/
301-
if (prev != nb) {
302-
prev->next = nb;
296+
if (prev != nblk) {
297+
prev->next = nblk;
303298
}
304299
}
305300

0 commit comments

Comments
 (0)