Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misra c round1 #91

Merged
merged 5 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/rcutils/error_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ rcutils_error_state_fini(rcutils_error_state_t * error_state);
RCUTILS_PUBLIC
void
rcutils_set_error_state(
const char * error_msg, const char * file, size_t line_number, rcutils_allocator_t allocator);
const char * error_string, const char * file, size_t line_number, rcutils_allocator_t allocator);

/// Check an argument for a null value.
/**
Expand All @@ -125,7 +125,7 @@ rcutils_set_error_state(
* \param[in] allocator The allocator to use if an error message needs to be allocated.
*/
#define RCUTILS_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement, allocator) \
if (!(value)) { \
if (NULL == value) { \
RCUTILS_SET_ERROR_MSG(msg, allocator); \
error_statement; \
}
Expand Down
4 changes: 2 additions & 2 deletions include/rcutils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ rcutils_ret_t rcutils_logging_initialize_with_allocator(rcutils_allocator_t allo
*/
RCUTILS_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t rcutils_logging_initialize();
rcutils_ret_t rcutils_logging_initialize(void);

/// Shutdown the logging system.
/**
Expand All @@ -128,7 +128,7 @@ rcutils_ret_t rcutils_logging_initialize();
*/
RCUTILS_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t rcutils_logging_shutdown();
rcutils_ret_t rcutils_logging_shutdown(void);

/// The structure identifying the caller location in the source code.
typedef struct rcutils_log_location_t
Expand Down
12 changes: 6 additions & 6 deletions src/allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ bool
rcutils_allocator_is_valid(const rcutils_allocator_t * allocator)
{
if (
!allocator ||
!allocator->allocate ||
!allocator->deallocate ||
!allocator->zero_allocate ||
!allocator->reallocate)
NULL == allocator ||
NULL == allocator->allocate ||
NULL == allocator->deallocate ||
NULL == allocator->zero_allocate ||
NULL == allocator->reallocate)
{
return false;
}
Expand All @@ -110,7 +110,7 @@ rcutils_reallocf(void * pointer, size_t size, rcutils_allocator_t * allocator)
return NULL;
}
void * new_pointer = allocator->reallocate(pointer, size, allocator->state);
if (!new_pointer) {
if (NULL == new_pointer) {
allocator->deallocate(pointer, allocator->state);
}
return new_pointer;
Expand Down
6 changes: 3 additions & 3 deletions src/concat.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ extern "C"
char *
rcutils_concat(const char * lhs, const char * rhs, const char * delimiter)
{
if (!lhs) {
if (NULL == lhs) {
return NULL;
}
if (!rhs) {
if (NULL == rhs) {
return NULL;
}

Expand All @@ -38,7 +38,7 @@ rcutils_concat(const char * lhs, const char * rhs, const char * delimiter)
size_t del_len = (delimiter) ? strlen(delimiter) : 0;

char * concat = (char *) malloc((lhs_len + rhs_len + del_len + 1) * sizeof(char));
if (!concat) {
if (NULL == concat) {
return NULL;
}

Expand Down
38 changes: 19 additions & 19 deletions src/error_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ rcutils_error_state_copy(const rcutils_error_state_t * src, rcutils_error_state_
{
dst->allocator = src->allocator;
dst->message = rcutils_strdup(src->message, dst->allocator);
if (!dst->message) {
if (NULL == dst->message) {
return RCUTILS_RET_BAD_ALLOC;
}
dst->file = rcutils_strdup(src->file, dst->allocator);
if (!dst->file) {
if (NULL == dst->file) {
return RCUTILS_RET_BAD_ALLOC;
}
dst->line_number = src->line_number;
Expand Down Expand Up @@ -101,7 +101,7 @@ rcutils_set_error_state(
#endif
__rcutils_error_state = (rcutils_error_state_t *)allocator.allocate(
sizeof(rcutils_error_state_t), allocator.state);
if (!__rcutils_error_state) {
if (NULL == __rcutils_error_state) {
#if RCUTILS_REPORT_ERROR_HANDLING_ERRORS
// rcutils_allocate failed, but fwrite might work?
RCUTILS_SAFE_FWRITE_TO_STDERR(
Expand All @@ -119,7 +119,7 @@ rcutils_set_error_state(
// the memory must be one byte bigger to store the NULL character
__rcutils_error_state->message =
(char *)allocator.allocate(error_string_length + 1, allocator.state);
if (!__rcutils_error_state->message) {
if (NULL == __rcutils_error_state->message) {
#if RCUTILS_REPORT_ERROR_HANDLING_ERRORS
// malloc failed, but fwrite might work?
RCUTILS_SAFE_FWRITE_TO_STDERR(
Expand Down Expand Up @@ -175,7 +175,7 @@ rcutils_set_error_state(
}

const rcutils_error_state_t *
rcutils_get_error_state()
rcutils_get_error_state(void)
{
#ifdef RCUTILS_THREAD_LOCAL_PTHREAD
return (rcutils_error_state_t *)pthread_getspecific(__rcutils_error_state_key);
Expand All @@ -185,7 +185,7 @@ rcutils_get_error_state()
}

static void
format_error_string()
format_error_string(void)
{
#ifdef RCUTILS_THREAD_LOCAL_PTHREAD
rcutils_error_state_t * __rcutils_error_state =
Expand All @@ -207,7 +207,7 @@ format_error_string()
#ifdef RCUTILS_THREAD_LOCAL_PTHREAD
pthread_setspecific(__rcutils_error_string_key, __rcutils_error_string);
#endif
if (!__rcutils_error_string) {
if (NULL == __rcutils_error_string) {
#if RCUTILS_REPORT_ERROR_HANDLING_ERRORS
// rcutils_allocate failed, but fwrite might work?
RCUTILS_SAFE_FWRITE_TO_STDERR(
Expand All @@ -227,12 +227,12 @@ format_error_string()
}

const char *
rcutils_get_error_string()
rcutils_get_error_string(void)
{
#ifdef RCUTILS_THREAD_LOCAL_PTHREAD
char * __rcutils_error_string = (char *)pthread_getspecific(__rcutils_error_string_key);
#endif
if (!__rcutils_error_string) {
if (NULL == __rcutils_error_string) {
format_error_string();
}
return __rcutils_error_string;
Expand All @@ -245,7 +245,7 @@ __rcutils_error_is_set(rcutils_error_state_t * error_state)
}

bool
rcutils_error_is_set()
rcutils_error_is_set(void)
{
#ifdef RCUTILS_THREAD_LOCAL_PTHREAD
rcutils_error_state_t * __rcutils_error_state =
Expand All @@ -255,7 +255,7 @@ rcutils_error_is_set()
}

const char *
rcutils_get_error_string_safe()
rcutils_get_error_string_safe(void)
{
if (!rcutils_error_is_set()) {
return "error not set";
Expand All @@ -266,7 +266,7 @@ rcutils_get_error_string_safe()
void
__rcutils_reset_error_string(char ** error_string_ptr, rcutils_allocator_t allocator)
{
if (!error_string_ptr) {
if (NULL == error_string_ptr) {
return;
}

Expand All @@ -280,7 +280,7 @@ __rcutils_reset_error_string(char ** error_string_ptr, rcutils_allocator_t alloc
local_allocator = rcutils_get_default_allocator();
}
char * error_string = *error_string_ptr;
if (error_string) {
if (error_string != NULL) {
local_allocator.deallocate(error_string, local_allocator.state);
}
*error_string_ptr = NULL;
Expand All @@ -289,19 +289,19 @@ __rcutils_reset_error_string(char ** error_string_ptr, rcutils_allocator_t alloc
void
__rcutils_reset_error(rcutils_error_state_t ** error_state_ptr_ptr)
{
if (error_state_ptr_ptr) {
if (error_state_ptr_ptr != NULL) {
rcutils_error_state_t * error_state_ptr = *error_state_ptr_ptr;
if (error_state_ptr) {
if (error_state_ptr != NULL) {
rcutils_allocator_t allocator = error_state_ptr->allocator;
if (!allocator.deallocate) {
if (NULL == allocator.deallocate) {
#if RCUTILS_REPORT_ERROR_HANDLING_ERRORS
RCUTILS_SAFE_FWRITE_TO_STDERR(
"[rcutils|error_handling.c:" RCUTILS_STRINGIFY(__LINE__) "]: "
"invalid allocator, deallocate function pointer is null\n");
#endif
allocator = rcutils_get_default_allocator();
}
if (error_state_ptr->message) {
if (error_state_ptr->message != NULL) {
// Cast const away to delete previously allocated memory.
allocator.deallocate((char *)error_state_ptr->message, allocator.state);
}
Expand All @@ -312,14 +312,14 @@ __rcutils_reset_error(rcutils_error_state_t ** error_state_ptr_ptr)
}

void
rcutils_reset_error()
rcutils_reset_error(void)
{
#ifdef RCUTILS_THREAD_LOCAL_PTHREAD
rcutils_error_state_t * __rcutils_error_state =
(rcutils_error_state_t *)pthread_getspecific(__rcutils_error_state_key);
char * __rcutils_error_string = (char *)pthread_getspecific(__rcutils_error_string_key);
#endif
if (__rcutils_error_state) {
if (__rcutils_error_state != NULL) {
__rcutils_reset_error_string(&__rcutils_error_string, __rcutils_error_state->allocator);
}
__rcutils_reset_error(&__rcutils_error_state);
Expand Down
10 changes: 5 additions & 5 deletions src/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ extern "C"
bool
rcutils_get_cwd(char * buffer, size_t max_length)
{
if (!buffer) {
if (NULL == buffer) {
return false;
}
#ifdef _WIN32
if (!_getcwd(buffer, (int)max_length)) {
if (NULL == _getcwd(buffer, (int)max_length)) {
return false;
}
#else
if (!getcwd(buffer, max_length)) {
if (NULL == getcwd(buffer, max_length)) {
return false;
}
#endif // _WIN32
Expand Down Expand Up @@ -144,10 +144,10 @@ rcutils_is_readable_and_writable(const char * abs_path)
char *
rcutils_join_path(const char * left_hand_path, const char * right_hand_path)
{
if (!left_hand_path) {
if (NULL == left_hand_path) {
return NULL;
}
if (!right_hand_path) {
if (NULL == right_hand_path) {
return NULL;
}

Expand Down
8 changes: 4 additions & 4 deletions src/find.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C"
size_t
rcutils_find(const char * str, char delimiter)
{
if (!str || 0 == strlen(str)) {
if (NULL == str || 0 == strlen(str)) {
return SIZE_MAX;
}
return rcutils_findn(str, delimiter, strlen(str));
Expand All @@ -37,7 +37,7 @@ rcutils_find(const char * str, char delimiter)
size_t
rcutils_findn(const char * str, char delimiter, size_t string_length)
{
if (!str || 0 == string_length) {
if (NULL == str || 0 == string_length) {
return SIZE_MAX;
}

Expand All @@ -52,7 +52,7 @@ rcutils_findn(const char * str, char delimiter, size_t string_length)
size_t
rcutils_find_last(const char * str, char delimiter)
{
if (!str || 0 == strlen(str)) {
if (NULL == str || 0 == strlen(str)) {
return SIZE_MAX;
}
return rcutils_find_lastn(str, delimiter, strlen(str));
Expand All @@ -61,7 +61,7 @@ rcutils_find_last(const char * str, char delimiter)
size_t
rcutils_find_lastn(const char * str, char delimiter, size_t string_length)
{
if (!str || 0 == string_length) {
if (NULL == str || 0 == string_length) {
return SIZE_MAX;
}

Expand Down
6 changes: 3 additions & 3 deletions src/format_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rcutils_format_string_limit(
const char * format_string,
...)
{
if (!format_string) {
if (NULL == format_string) {
return NULL;
}
RCUTILS_CHECK_ALLOCATOR(&allocator, return NULL);
Expand All @@ -56,11 +56,11 @@ rcutils_format_string_limit(
bytes_to_be_written = limit - 1;
}
char * output_string = allocator.allocate(bytes_to_be_written + 1, allocator.state);
if (!output_string) {
if (NULL == output_string) {
va_end(args2);
return NULL;
}
// formate the string
// format the string
rcutils_vsnprintf(output_string, bytes_to_be_written + 1, format_string, args2);
output_string[bytes_to_be_written] = '\0';
va_end(args2);
Expand Down
4 changes: 2 additions & 2 deletions src/get_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ static char __env_buffer[WINDOWS_ENV_BUFFER_SIZE];
const char *
rcutils_get_env(const char * env_name, const char ** env_value)
{
if (!env_name) {
if (NULL == env_name) {
return "argument env_name is null";
}
if (!env_value) {
if (NULL == env_value) {
return "argument env_value is null";
}
*env_value = NULL;
Expand Down
Loading