Add static code analysis with cppcheck
This commit is contained in:
parent
707c75131c
commit
e5f7de6df1
17
.vscode/tasks.json
vendored
17
.vscode/tasks.json
vendored
@ -20,6 +20,23 @@
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "check",
|
||||
"type":"shell",
|
||||
"command": "make check -j4",
|
||||
"problemMatcher": {
|
||||
"base": "$gcc",
|
||||
"owner": "gcc",
|
||||
"fileLocation": [
|
||||
"relative",
|
||||
"${workspaceFolder}"
|
||||
]
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "clean",
|
||||
"type":"shell",
|
||||
|
6
Makefile
6
Makefile
@ -4,6 +4,7 @@ TARGET_FILE ?= test
|
||||
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
CPP = $(CROSS_COMPILE)cpp
|
||||
CHECK = cppcheck
|
||||
|
||||
SRC_DIR = src
|
||||
OBJ_DIR = obj
|
||||
@ -22,6 +23,7 @@ endif
|
||||
LD_FLAGS :=
|
||||
C_FLAGS := -O0 -g -Wall -Wextra -Werror
|
||||
CPP_FLAGS := $(addprefix -I, $(INCLUDES))
|
||||
CHECK_CLAGS := --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem
|
||||
|
||||
C_SRCS = $(wildcard $(SRC_DIR)/*.c)
|
||||
C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS)))
|
||||
@ -34,6 +36,10 @@ THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
||||
.PHONY: all
|
||||
all: $(TARGET)
|
||||
|
||||
.PHONY: check
|
||||
check: $(C_SRCS)
|
||||
$(CHECK) $(CPP_FLAGS) $(CHECK_CLAGS) $(C_SRCS)
|
||||
|
||||
$(TARGET): $(OBJS) $(THIS_MAKEFILE)
|
||||
@mkdir -p $(BIN_DIR)
|
||||
$(CC) $(C_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@
|
||||
|
@ -108,12 +108,14 @@ int gpio_read(const struct gpio *gpio, unsigned int *value)
|
||||
int gpio_write(const struct gpio *gpio, unsigned int value)
|
||||
{
|
||||
int res;
|
||||
unsigned char mask = gpio->ftdi_dev->status_mask;
|
||||
unsigned char mask;
|
||||
|
||||
if(NULL == gpio) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
mask = gpio->ftdi_dev->status_mask;
|
||||
|
||||
if(value == 0) {
|
||||
mask &= ~(unsigned char)(gpio->pin);
|
||||
}
|
||||
@ -135,13 +137,13 @@ int gpio_write(const struct gpio *gpio, unsigned int value)
|
||||
int gpio_toggle(const struct gpio *gpio)
|
||||
{
|
||||
int res;
|
||||
unsigned char mask = gpio->ftdi_dev->status_mask;
|
||||
unsigned char mask;
|
||||
|
||||
if(NULL == gpio) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
mask ^= (unsigned char)(gpio->pin);
|
||||
mask = (gpio->ftdi_dev->status_mask) ^ (unsigned char)(gpio->pin);
|
||||
|
||||
res = ftdi_write_data(gpio->ftdi_dev->ftdi, &mask, 1);
|
||||
if(res < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user