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

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);