Exchange NULL pointer checks with assert

This commit is contained in:
Thomas Klaehn 2019-07-18 12:08:25 +02:00
parent f4cc51669b
commit 07775772a7
8 changed files with 25 additions and 41 deletions

17
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/libftdi1"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}

2
.vscode/launch.json vendored
View File

@ -8,7 +8,7 @@
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/test",
"program": "${workspaceFolder}/bin/test/unit/gpio_ftdi",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>
#include <syslog.h>
#include <stdbool.h>
@ -38,11 +39,7 @@ int gpio_open(const struct gpio *gpio)
int res;
unsigned char init_value = 0;
if(NULL == gpio) {
syslog(LOG_ERR, "No valid gpio object given.\n");
return EXIT_FAILURE;
}
assert(NULL != gpio);
if(!gpio->ftdi_dev->is_open) {
res = ftdi_open(gpio);
if(res != EXIT_SUCCESS) {
@ -76,9 +73,7 @@ int gpio_open(const struct gpio *gpio)
// cppcheck-suppress unusedFunction
int gpio_close(const struct gpio *gpio)
{
if(NULL == gpio) {
return EXIT_FAILURE;
}
assert(NULL != gpio);
gpio_write(gpio, 0);
@ -95,9 +90,8 @@ int gpio_close(const struct gpio *gpio)
// cppcheck-suppress unusedFunction
int gpio_read(const struct gpio *gpio, unsigned int *value)
{
if(NULL == gpio || NULL == value) {
return EXIT_FAILURE;
}
assert(NULL != gpio);
assert(NULL != value);
if(gpio->ftdi_dev->status_mask & (unsigned char)(gpio->pin)) {
*value = 1;
@ -113,9 +107,7 @@ int gpio_write(const struct gpio *gpio, unsigned int value)
int res;
unsigned char mask;
if(NULL == gpio) {
return EXIT_FAILURE;
}
assert(NULL != gpio);
mask = gpio->ftdi_dev->status_mask;
@ -143,9 +135,7 @@ int gpio_toggle(const struct gpio *gpio)
int res;
unsigned char mask;
if(NULL == gpio) {
return EXIT_FAILURE;
}
assert(NULL != gpio);
mask = (gpio->ftdi_dev->status_mask) ^ (unsigned char)(gpio->pin);

View File

@ -9,10 +9,6 @@
#include <ftdi_dev.h>
#include <gpio.h>
UTEST(gpio_close, invalid_gpio_obj) {
ASSERT_EQ(gpio_close(NULL), EXIT_FAILURE);
}
UTEST(gpio_close, empty_bitmask) {
struct gpio gpio_1;
struct ftdi_dev ftdi_obj;

View File

@ -89,10 +89,6 @@ UTEST(gpio_open, ftdi_open_success) {
ASSERT_EQ(gpio_open(&gpio_1), EXIT_SUCCESS);
}
UTEST(gpio_open, invalid_gpio_obj) {
ASSERT_EQ(gpio_open(NULL), EXIT_FAILURE);
}
UTEST(gpio_open, ftdi_set_bitmode_failed) {
struct gpio gpio_1;
struct ftdi_dev ftdi_obj;

View File

@ -11,11 +11,6 @@
#include <stdio.h>
UTEST(gpio_read, invalid_params) {
ASSERT_EQ(gpio_read(NULL, NULL), EXIT_FAILURE);
}
UTEST(gpio_read, value_0) {
unsigned int result;
struct gpio gpio_1;

View File

@ -11,11 +11,6 @@
#include <stdio.h>
UTEST(gpio_toggle, invalid_params) {
ASSERT_EQ(gpio_toggle(NULL), EXIT_FAILURE);
}
UTEST(gpio_toggle, ftdi_write_data_fails) {
struct gpio gpio_1;
struct ftdi_dev ftdi_obj;

View File

@ -9,11 +9,6 @@
#include <ftdi_dev.h>
#include <gpio.h>
UTEST(gpio_write, invalid_params) {
ASSERT_EQ(gpio_write(NULL, 0), EXIT_FAILURE);
}
UTEST(gpio_write, value_0) {
unsigned int result;
struct gpio gpio_1;