Skip to content

Commit b058ccb

Browse files
committed
Suppress Cppcheck and spelling errors
The newly introduced 'fmtscan' tool does not handle the getopt(3) string correctly, which leads to additional false spelling errors. To mitigate the issue, add the affected sub-strings to a user-defined dictionary as a workaround. Tested with Cppcheck v2.17 Close #255 Change-Id: Ife2b8c6088f2e5c3a20cf5dd0149098443fa4e46
1 parent 5d61cfd commit b058ccb

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ qtest: $(OBJS)
5555

5656
fmtscan: tools/fmtscan.c
5757
$(VECHO) " CC+LD\t$@\n"
58-
$(Q)$(CC) -o $@ $(CFLAGS) $<
58+
$(Q)$(CC) -o $@ $(CFLAGS) $< -lrt -lpthread
5959

6060
check: qtest
6161
./$< -v 3 -f traces/trace-eg.cmd

scripts/aspell-pws

+19
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ sigaltstack
230230
utime
231231
mknod
232232
ustat
233+
stat
234+
getopt
233235
statfs
234236
fstatfs
235237
sysfs
@@ -430,3 +432,20 @@ pws
430432
el
431433
fd
432434
hv
435+
col
436+
dA
437+
dC
438+
dD
439+
lu
440+
pC
441+
pE
442+
pGp
443+
pM
444+
pS
445+
pg
446+
phD
447+
pm
448+
pr
449+
ps
450+
newline
451+
abbrev

scripts/pre-commit.hook

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare -F set_colors >/dev/null 2>&1 || { echo "[!] '$common_script' does not d
1111
# Build unmatched suppressions for each *.c file.
1212
cppcheck_build_unmatched() {
1313
local file suppression=""
14-
for file in *.c; do
14+
for file in *.c tools/*.c; do
1515
suppression+=" --suppress=unmatchedSuppression:$file"
1616
done
1717
echo "$suppression"
@@ -46,11 +46,12 @@ cppcheck_suppressions() {
4646
"staticFunction:linenoise.c"
4747
"nullPointerOutOfMemory:web.c"
4848
"staticFunction:web.c"
49+
"constParameterCallback:tools/fmtscan.c"
4950
)
5051

5152
# Array for additional cppcheck options (non-suppressions)
5253
local -a other_flags=(
53-
"--inline-suppr harness.c"
54+
"--inline-suppr harness.c --inline-suppr tools/fmtscan.c"
5455
)
5556

5657
local out=""

tools/fmtscan.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ static inline bool find_word(const char *restrict word,
359359

360360
static inline int read_dictionary(const char *dictfile)
361361
{
362-
char *ptr, *dict;
363362
struct stat buf;
364363
char buffer[4096];
365364
const char *buffer_end = buffer + (sizeof(buffer)) - 1;
@@ -372,6 +371,7 @@ static inline int read_dictionary(const char *dictfile)
372371
return -1;
373372
}
374373

374+
const char *ptr, *dict;
375375
ptr = dict =
376376
mmap(NULL, buf.st_size, PROT_READ, MAP_SHARED | MAP_POPULATE, fd, 0);
377377
if (dict == MAP_FAILED) {
@@ -393,7 +393,7 @@ static inline int read_dictionary(const char *dictfile)
393393
add_word(buffer, word_nodes, word_node_heap, &word_node_heap_next,
394394
WORD_NODES_HEAP_SIZE);
395395
}
396-
munmap(dict, buf.st_size);
396+
munmap((void *) dict, buf.st_size);
397397
close(fd);
398398

399399
return 0;
@@ -656,19 +656,17 @@ static get_char_t parse_number(parser_t *restrict p,
656656

657657
/* Determine the integer format based on its prefix. */
658658
if (LIKELY(ch == '0')) {
659-
get_char_t nextch1, nextch2;
660-
661659
token_append(t, ch);
662660

663-
nextch1 = get_char(p);
661+
get_char_t nextch1 = get_char(p);
664662

665663
if (nextch1 >= '0' && nextch1 <= '8') {
666664
/* Treat as an octal value */
667665
ch = nextch1;
668666
isoct = true;
669667
} else if (nextch1 == 'x' || nextch1 == 'X') {
670668
/* Check for hexadecimal notation */
671-
nextch2 = get_char(p);
669+
get_char_t nextch2 = get_char(p);
672670

673671
if (LIKELY(nextch2 != PARSER_EOF)) {
674672
/* If not EOF, revert state and finish token */

0 commit comments

Comments
 (0)