Skip to content

Commit 6bd9a4e

Browse files
committed
misc:
- Explicit memset/memcpy ignored return value - One statement per line refactoring - MD files formatting
1 parent 4e773d3 commit 6bd9a4e

File tree

2 files changed

+81
-38
lines changed

2 files changed

+81
-38
lines changed

ReleaseNotes.md

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,70 @@
1-
Queue handling library (designed on Arduino)
1+
# Queue handling library (designed on Arduino)
2+
23
2017-2026 SMFSW
34

4-
Feel free to share your thoughts @ [email protected] about:
5-
- issues encountered
6-
- optimizations
7-
- improvements & new functionalities
5+
Feel free to share your thoughts @ <[email protected]> about:
6+
7+
- issues encountered
8+
- optimizations
9+
- improvements & new functionalities
810

911
------------
1012

1113
** Actual:
1214

13-
v2.1: 02 Jan 2026:
15+
v2.1: (02 Jan 2026):
16+
1417
- Internal functions name refactoring
1518
- Unused tags removal
1619
- always_inline attribute removal for index manipulation functions
1720
- c-cast updated to cpp static_cast
1821
- Legacy standard library headers replaced by their cpp equivalents
1922
- const qualifiers for getter functions
23+
- Explicit memset/memcpy ignored return value
24+
- One statement per line refactoring
25+
- MD files formatting
26+
27+
v2.0: (15 Apr 2024):
2028

21-
v2.0: 15 Apr 2024:
2229
- No more inlines in header file (to generate proper static library)
2330
- MISRA refactoring
2431

25-
v1.11: 18 Dec 2022:
32+
v1.11: (18 Dec 2022):
33+
2634
- Include missing stddef.h
2735

28-
v1.10: 15 Nov 2022:
36+
v1.10: (15 Nov 2022):
37+
2938
- SimpleQueueStatic.ino example added
3039
- Constructor parameters added to setup a queue from statically allocated data area
3140
- Constructor refactoring for consistency and robustness (when using queue functions regardless init performed with success)
3241
- Doxyfiles update
3342
- Outdated travisCI status in README.md removed
3443
- LICENSE years update
3544

36-
v1.9.1: 14 Jan 2021:
45+
v1.9.1: (14 Jan 2021):
46+
3747
- SerialQueue.ino example added
3848

39-
v1.9: 4 Nov 2020:
49+
v1.9: (4 Nov 2020):
50+
4051
- Queue class renamed to cppQueue
4152

42-
v1.8: 4 Nov 2019:
53+
v1.8: (4 Nov 2019):
54+
4355
- const qualifiers added where missing
4456
- Added peekIdx and peekPrevious methods
4557
- Added related examples
4658

47-
v1.7: 2 Jun 2019:
48-
- Fixed README.md thanks to @reydelleon
59+
v1.7: (2 Jun 2019):
60+
61+
- Fixed README.md thanks to [\@reydelleon](https://github.com/reydelleon)
4962
- INC_IDX & DEC_IDX macros changed to inlines
5063
- Added nonnull function attribute where needed
5164
- Updated Doxyfile
5265

53-
v1.6 26 May 2018:
66+
v1.6 (26 May 2018):
67+
5468
- Constructor does not check anymore if class instance is already allocated (as it supposedly isn't)
5569
- Added getRemainingCount inline returning how much records are left in the queue
5670
- Added sizeOf inline to check full queue size in byte (may also be used to check if queue has been allocated properly)
@@ -60,28 +74,34 @@ v1.6 26 May 2018:
6074
- Updated README.md
6175
- Added more example sketches & updated LibTst example using latest inlines additions
6276

63-
v1.5 14 March 2018:
77+
v1.5 (14 March 2018):
78+
6479
- Added isInitialized inline to be able to check after init if queue has been properly allocated
6580
- Added flush inline (to have the same functions as in cQueue library)
6681
- LIFO peek temporary variable is uint16_t (same type as in variable)
6782
- Comments fixes
6883

69-
v1.4 21 November 2017:
84+
v1.4 (21 November 2017):
85+
7086
- Added const qualifier for function parameters
7187

72-
v1.3 12 July 2017:
88+
v1.3 (12 July 2017):
89+
7390
- #2 fix for esp8266: renamed cpp/h files : header name already used in compiler sys includes
7491
- examples updated with new header file name (cppQueue.h)
7592
- comply with Arduino v1.5+ IDE source located in src subfolder
7693

77-
v1.2 07 July 2017:
94+
v1.2 (07 July 2017):
95+
7896
- #1 added pull inline for compatibility with older versions (v1.0)
7997
- #2 surrounded c libs with extern C
8098

81-
v1.1 06 July 2017:
99+
v1.1 (06 July 2017):
100+
82101
- pop keyword used (instead of pull)
83102
- peek & drop functions added
84103
- examples updated to reflect latest changes
85104

86-
v1.0 22 March 2017:
105+
v1.0 (22 March 2017):
106+
87107
- First release

src/cppQueue.cpp

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727
**/
2828
static inline void __attribute__((nonnull)) cppq_inc_idx(uint16_t * const pIdx, const uint16_t end, const uint16_t start)
2929
{
30-
if (*pIdx < (end - 1U)) { (*pIdx)++; }
31-
else { *pIdx = start; }
30+
if (*pIdx < (end - 1U))
31+
{
32+
(*pIdx)++;
33+
}
34+
else
35+
{
36+
*pIdx = start;
37+
}
3238
}
3339

3440
/*! \brief Decrement index
@@ -39,8 +45,14 @@ static inline void __attribute__((nonnull)) cppq_inc_idx(uint16_t * const pIdx,
3945
**/
4046
static inline void __attribute__((nonnull)) cppq_dec_idx(uint16_t * const pIdx, const uint16_t end, const uint16_t start)
4147
{
42-
if (*pIdx > start) { (*pIdx)--; }
43-
else { *pIdx = end - 1U; }
48+
if (*pIdx > start)
49+
{
50+
(*pIdx)--;
51+
}
52+
else
53+
{
54+
*pIdx = end - 1U;
55+
}
4456
}
4557

4658

@@ -81,18 +93,26 @@ inline uint16_t __attribute__((always_inline)) cppQueue::_getCount(void) const {
8193
/************************/
8294
cppQueue::cppQueue(const size_t size_rec, const uint16_t nb_recs, const cppQueueType type, const bool overwrite, void * const pQDat, const size_t lenQDat)
8395
{
96+
flush(); // variables needs to be 0 to ensure proper functions behavior when queue is not allocated
8497
init = 0;
85-
rec_nb = 0; // rec_nb needs to be 0 to ensure proper push behavior when queue is not allocated
86-
ovw = false; // ovw needs to be false to ensure proper push behavior when queue is not allocated
87-
flush(); // other variables needs to be 0 to ensure proper functions behavior when queue is not allocated
98+
rec_nb = 0; // rec_nb needs to be 0 to ensure proper push behavior when queue is not allocated
99+
ovw = false; // ovw needs to be false to ensure proper push behavior when queue is not allocated
100+
dynamic = (pQDat == NULL);
88101

89102
const size_t size = nb_recs * size_rec;
90103

91-
dynamic = (pQDat == NULL);
92-
93-
if (dynamic) { queue = static_cast<uint8_t *>(malloc(size)); }
94-
else if (lenQDat >= size) { queue = static_cast<uint8_t *>(pQDat); }
95-
else { queue = NULL; }
104+
if (dynamic)
105+
{
106+
queue = static_cast<uint8_t *>(malloc(size));
107+
}
108+
else if (lenQDat >= size)
109+
{
110+
queue = static_cast<uint8_t *>(pQDat);
111+
}
112+
else
113+
{
114+
queue = NULL;
115+
}
96116

97117
if (queue != NULL)
98118
{
@@ -108,7 +128,10 @@ cppQueue::cppQueue(const size_t size_rec, const uint16_t nb_recs, const cppQueue
108128

109129
cppQueue::~cppQueue()
110130
{
111-
if (_isInitialized() && dynamic && (queue != NULL)) { free(queue); }
131+
if (_isInitialized() && dynamic && (queue != NULL))
132+
{
133+
free(queue);
134+
}
112135
}
113136

114137

@@ -147,7 +170,7 @@ bool __attribute__((nonnull)) cppQueue::push(const void * const record)
147170
if (ret)
148171
{
149172
uint8_t * const pStart = queue + (rec_sz * in);
150-
memcpy(pStart, record, rec_sz);
173+
(void) memcpy(pStart, record, rec_sz);
151174
cppq_inc_idx(&in, rec_nb, 0);
152175
}
153176

@@ -177,7 +200,7 @@ bool __attribute__((nonnull)) cppQueue::pop(void * const record)
177200
pStart = queue + (rec_sz * in);
178201
}
179202

180-
memcpy(record, pStart, rec_sz);
203+
(void) memcpy(record, pStart, rec_sz);
181204
cnt--; // Decrease records count
182205
}
183206

@@ -209,7 +232,7 @@ bool __attribute__((nonnull)) cppQueue::peek(void * const record)
209232
pStart = queue + (rec_sz * rec);
210233
}
211234

212-
memcpy(record, pStart, rec_sz);
235+
(void) memcpy(record, pStart, rec_sz);
213236
}
214237

215238
return ret;
@@ -263,7 +286,7 @@ bool __attribute__((nonnull)) cppQueue::peekIdx(void * const record, const uint1
263286
pStart = queue + (rec_sz * idx);
264287
}
265288

266-
memcpy(record, pStart, rec_sz);
289+
(void) memcpy(record, pStart, rec_sz);
267290
}
268291

269292
return ret;

0 commit comments

Comments
 (0)