diff --git a/include/rcutils/error_handling.h b/include/rcutils/error_handling.h index 381e0a26..1cfed3d5 100644 --- a/include/rcutils/error_handling.h +++ b/include/rcutils/error_handling.h @@ -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. /** @@ -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; \ } diff --git a/include/rcutils/logging.h b/include/rcutils/logging.h index 9b4ed43b..29184db8 100644 --- a/include/rcutils/logging.h +++ b/include/rcutils/logging.h @@ -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. /** @@ -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 diff --git a/src/allocator.c b/src/allocator.c index 6028d5b7..5741289b 100644 --- a/src/allocator.c +++ b/src/allocator.c @@ -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; } @@ -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; diff --git a/src/concat.c b/src/concat.c index f630cacc..167db127 100644 --- a/src/concat.c +++ b/src/concat.c @@ -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; } @@ -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; } diff --git a/src/error_handling.c b/src/error_handling.c index dedb2c03..efdf8f65 100644 --- a/src/error_handling.c +++ b/src/error_handling.c @@ -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; @@ -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( @@ -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( @@ -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); @@ -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 = @@ -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( @@ -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; @@ -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 = @@ -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"; @@ -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; } @@ -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; @@ -289,11 +289,11 @@ __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__) "]: " @@ -301,7 +301,7 @@ __rcutils_reset_error(rcutils_error_state_t ** error_state_ptr_ptr) #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); } @@ -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); diff --git a/src/filesystem.c b/src/filesystem.c index 1e3d1925..03af3e77 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -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 @@ -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; } diff --git a/src/find.c b/src/find.c index 595d9f29..7df2cf1d 100644 --- a/src/find.c +++ b/src/find.c @@ -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)); @@ -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; } @@ -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)); @@ -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; } diff --git a/src/format_string.c b/src/format_string.c index 8994283f..1c6c4eb1 100644 --- a/src/format_string.c +++ b/src/format_string.c @@ -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); @@ -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); diff --git a/src/get_env.c b/src/get_env.c index 3e21b033..f37fbb61 100644 --- a/src/get_env.c +++ b/src/get_env.c @@ -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; diff --git a/src/logging.c b/src/logging.c index 84498f30..c001e120 100644 --- a/src/logging.c +++ b/src/logging.c @@ -56,7 +56,7 @@ bool g_rcutils_logging_severities_map_valid = false; int g_rcutils_logging_default_logger_level = 0; -rcutils_ret_t rcutils_logging_initialize() +rcutils_ret_t rcutils_logging_initialize(void) { return rcutils_logging_initialize_with_allocator(rcutils_get_default_allocator()); } @@ -117,7 +117,7 @@ rcutils_ret_t rcutils_logging_initialize_with_allocator(rcutils_allocator_t allo return ret; } -rcutils_ret_t rcutils_logging_shutdown() +rcutils_ret_t rcutils_logging_shutdown(void) { if (!g_rcutils_logging_initialized) { return RCUTILS_RET_OK; @@ -138,7 +138,7 @@ rcutils_ret_t rcutils_logging_shutdown() return ret; } -rcutils_logging_output_handler_t rcutils_logging_get_output_handler() +rcutils_logging_output_handler_t rcutils_logging_get_output_handler(void) { RCUTILS_LOGGING_AUTOINIT return g_rcutils_logging_output_handler; @@ -152,7 +152,7 @@ void rcutils_logging_set_output_handler(rcutils_logging_output_handler_t functio // *INDENT-ON* } -int rcutils_logging_get_default_logger_level() +int rcutils_logging_get_default_logger_level(void) { RCUTILS_LOGGING_AUTOINIT return g_rcutils_logging_default_logger_level; @@ -175,7 +175,7 @@ int rcutils_logging_get_logger_level(const char * name) int rcutils_logging_get_logger_leveln(const char * name, size_t name_length) { RCUTILS_LOGGING_AUTOINIT - if (!name) { + if (NULL == name) { return -1; } @@ -191,7 +191,7 @@ int rcutils_logging_get_logger_leveln(const char * name, size_t name_length) // TODO(dhood): replace string map with int map. const char * severity_string = rcutils_string_map_getn( &g_rcutils_logging_severities_map, name, name_length); - if (!severity_string) { + if (NULL == severity_string) { if (rcutils_string_map_key_existsn(&g_rcutils_logging_severities_map, name, name_length)) { // The level has been specified but couldn't be retrieved. return -1; @@ -224,7 +224,7 @@ int rcutils_logging_get_logger_leveln(const char * name, size_t name_length) int rcutils_logging_get_logger_effective_level(const char * name) { RCUTILS_LOGGING_AUTOINIT - if (!name) { + if (NULL == name) { return -1; } size_t substring_length = strlen(name); @@ -256,7 +256,7 @@ int rcutils_logging_get_logger_effective_level(const char * name) rcutils_ret_t rcutils_logging_set_logger_level(const char * name, int level) { RCUTILS_LOGGING_AUTOINIT - if (!name) { + if (NULL == name) { RCUTILS_SET_ERROR_MSG( "Invalid logger name", g_rcutils_logging_allocator); return RCUTILS_RET_INVALID_ARGUMENT; @@ -282,7 +282,7 @@ rcutils_ret_t rcutils_logging_set_logger_level(const char * name, int level) return RCUTILS_RET_INVALID_ARGUMENT; } const char * severity_string = g_rcutils_log_severity_names[level]; - if (!severity_string) { + if (NULL == severity_string) { RCUTILS_SET_ERROR_MSG( "Unable to determine severity_string for severity", g_rcutils_logging_allocator); return RCUTILS_RET_INVALID_ARGUMENT; @@ -323,7 +323,7 @@ void rcutils_log( return; } rcutils_logging_output_handler_t output_handler = g_rcutils_logging_output_handler; - if (output_handler) { + if (output_handler != NULL) { va_list args; va_start(args, format); (*output_handler)(location, severity, name ? name : "", format, &args); @@ -359,7 +359,7 @@ void rcutils_log( if (output_buffer == static_output_buffer) { \ void * dynamic_output_buffer = g_rcutils_logging_allocator.allocate( \ output_buffer_size, g_rcutils_logging_allocator.state); \ - if (!dynamic_output_buffer) { \ + if (NULL == dynamic_output_buffer) { \ fprintf(stderr, "failed to allocate buffer for logging output\n"); \ goto cleanup; \ } \ @@ -368,7 +368,7 @@ void rcutils_log( } else { \ void * new_dynamic_output_buffer = g_rcutils_logging_allocator.reallocate( \ output_buffer, output_buffer_size, g_rcutils_logging_allocator.state); \ - if (!new_dynamic_output_buffer) { \ + if (NULL == new_dynamic_output_buffer) { \ fprintf(stderr, "failed to reallocate buffer for logging output\n"); \ goto cleanup; \ } \ @@ -411,7 +411,7 @@ void rcutils_logging_console_output_handler( return; } severity_string = g_rcutils_log_severity_names[severity]; - if (!severity_string) { + if (NULL == severity_string) { fprintf(stderr, "couldn't determine name for severity level: %d\n", severity); return; } @@ -442,7 +442,7 @@ void rcutils_logging_console_output_handler( size_t message_buffer_size = written + 1; void * dynamic_message_buffer = g_rcutils_logging_allocator.allocate( message_buffer_size, g_rcutils_logging_allocator.state); - if (!dynamic_message_buffer) { + if (NULL == dynamic_message_buffer) { fprintf(stderr, "failed to allocate buffer for message\n"); return; } diff --git a/src/split.c b/src/split.c index 14bed1ec..0daa2d3c 100644 --- a/src/split.c +++ b/src/split.c @@ -34,11 +34,11 @@ rcutils_split( rcutils_allocator_t allocator, rcutils_string_array_t * string_array) { - if (!string_array) { + if (NULL == string_array) { RCUTILS_SET_ERROR_MSG("string_array is null", allocator) return RCUTILS_RET_INVALID_ARGUMENT; } - if (!str || strlen(str) == 0) { + if (NULL == str || strlen(str) == 0) { *string_array = rcutils_get_zero_initialized_string_array(); return RCUTILS_RET_OK; } @@ -66,7 +66,7 @@ rcutils_split( } // TODO(wjwwood): refactor this function so it can use rcutils_string_array_init() instead string_array->data = allocator.allocate(string_array->size * sizeof(char *), allocator.state); - if (!string_array->data) { + if (NULL == string_array->data) { goto fail; } @@ -85,7 +85,7 @@ rcutils_split( // and nullterminating string_array->data[token_counter] = allocator.allocate((rhs - lhs + 2) * sizeof(char), allocator.state); - if (!string_array->data[token_counter]) { + if (NULL == string_array->data[token_counter]) { string_array->size = token_counter; goto fail; } @@ -129,7 +129,7 @@ rcutils_split_last( rcutils_allocator_t allocator, rcutils_string_array_t * string_array) { - if (!str || strlen(str) == 0) { + if (NULL == str || strlen(str) == 0) { *string_array = rcutils_get_zero_initialized_string_array(); return RCUTILS_RET_OK; } @@ -164,7 +164,7 @@ rcutils_split_last( } string_array->data[0] = allocator.allocate((found_last - lhs_offset + 2) * sizeof(char), allocator.state); - if (!string_array->data) { + if (NULL == string_array->data) { result_error = RCUTILS_RET_BAD_ALLOC; goto fail; } @@ -185,7 +185,7 @@ rcutils_split_last( string_array->data[0] = allocator.allocate( (found_last + 1 - lhs_offset - inner_rhs_offset + 1) * sizeof(char), allocator.state); - if (!string_array->data[0]) { + if (NULL == string_array->data[0]) { result_error = RCUTILS_RET_BAD_ALLOC; goto fail; } @@ -195,7 +195,7 @@ rcutils_split_last( string_array->data[1] = allocator.allocate( (string_size - found_last - rhs_offset + 1) * sizeof(char), allocator.state); - if (!string_array->data[1]) { + if (NULL == string_array->data[1]) { result_error = RCUTILS_RET_BAD_ALLOC; goto fail; } diff --git a/src/strdup.c b/src/strdup.c index 4dfad349..9c5ea658 100644 --- a/src/strdup.c +++ b/src/strdup.c @@ -27,7 +27,7 @@ extern "C" char * rcutils_strdup(const char * str, rcutils_allocator_t allocator) { - if (!str) { + if (NULL == str) { return NULL; } return rcutils_strndup(str, strlen(str), allocator); @@ -36,11 +36,11 @@ rcutils_strdup(const char * str, rcutils_allocator_t allocator) char * rcutils_strndup(const char * str, size_t string_length, rcutils_allocator_t allocator) { - if (!str) { + if (NULL == str) { return NULL; } char * new_string = allocator.allocate(string_length + 1, allocator.state); - if (!new_string) { + if (NULL == new_string) { return NULL; } memcpy(new_string, str, string_length + 1); diff --git a/src/string_array.c b/src/string_array.c index 1a0197b5..360ce849 100644 --- a/src/string_array.c +++ b/src/string_array.c @@ -25,7 +25,7 @@ extern "C" #include "rcutils/types/rcutils_ret.h" rcutils_string_array_t -rcutils_get_zero_initialized_string_array() +rcutils_get_zero_initialized_string_array(void) { static rcutils_string_array_t array = { .size = 0, @@ -41,17 +41,17 @@ rcutils_string_array_init( size_t size, rcutils_allocator_t * allocator) { - if (!allocator) { + if (NULL == allocator) { RCUTILS_SET_ERROR_MSG("allocator is null", rcutils_get_default_allocator()) return RCUTILS_RET_INVALID_ARGUMENT; } - if (!string_array) { + if (NULL == string_array) { RCUTILS_SET_ERROR_MSG("string_array is null", *allocator) return RCUTILS_RET_INVALID_ARGUMENT; } string_array->size = size; string_array->data = allocator->zero_allocate(size, sizeof(char *), allocator->state); - if (!string_array->data) { + if (NULL == string_array->data) { RCUTILS_SET_ERROR_MSG("failed to allocator string array", *allocator) return RCUTILS_RET_BAD_ALLOC; } @@ -62,12 +62,12 @@ rcutils_string_array_init( rcutils_ret_t rcutils_string_array_fini(rcutils_string_array_t * string_array) { - if (!string_array) { + if (NULL == string_array) { RCUTILS_SET_ERROR_MSG("string_array is null", rcutils_get_default_allocator()) return RCUTILS_RET_INVALID_ARGUMENT; } - if (!string_array->data) { + if (NULL == string_array->data) { return RCUTILS_RET_OK; } diff --git a/src/string_map.c b/src/string_map.c index 14f6fbe5..16ebcadf 100644 --- a/src/string_map.c +++ b/src/string_map.c @@ -38,7 +38,7 @@ typedef struct rcutils_string_map_impl_t } rcutils_string_map_impl_t; rcutils_string_map_t -rcutils_get_zero_initialized_string_map() +rcutils_get_zero_initialized_string_map(void) { static rcutils_string_map_t zero_initialized_string_map; zero_initialized_string_map.impl = NULL; @@ -52,14 +52,14 @@ rcutils_string_map_init( rcutils_allocator_t allocator) { RCUTILS_CHECK_ARGUMENT_FOR_NULL(string_map, RCUTILS_RET_INVALID_ARGUMENT, allocator) - if (string_map->impl) { + if (string_map->impl != NULL) { RCUTILS_SET_ERROR_MSG("string_map already initialized", allocator) return RCUTILS_RET_STRING_MAP_ALREADY_INIT; } RCUTILS_CHECK_ALLOCATOR_WITH_MSG( &allocator, "invalid allocator", return RCUTILS_RET_INVALID_ARGUMENT) string_map->impl = allocator.allocate(sizeof(rcutils_string_map_impl_t), allocator.state); - if (!string_map->impl) { + if (NULL == string_map->impl) { RCUTILS_SET_ERROR_MSG( "failed to allocate memory for string map impl struct", // try default allocator, assuming given allocator is not able to allocate memory @@ -86,7 +86,7 @@ rcutils_string_map_fini(rcutils_string_map_t * string_map) { RCUTILS_CHECK_ARGUMENT_FOR_NULL( string_map, RCUTILS_RET_INVALID_ARGUMENT, rcutils_get_default_allocator()) - if (!string_map->impl) { + if (NULL == string_map->impl) { return RCUTILS_RET_OK; } rcutils_ret_t ret = rcutils_string_map_clear(string_map); @@ -169,7 +169,7 @@ rcutils_string_map_reserve(rcutils_string_map_t * string_map, size_t capacity) // resize the keys, assigning the result only if it succeeds char ** new_keys = allocator.reallocate(string_map->impl->keys, capacity * sizeof(char *), allocator.state); - if (!new_keys) { + if (NULL == new_keys) { RCUTILS_SET_ERROR_MSG("failed to allocate memory for string_map keys", allocator) return RCUTILS_RET_BAD_ALLOC; } @@ -178,7 +178,7 @@ rcutils_string_map_reserve(rcutils_string_map_t * string_map, size_t capacity) // resize the values, assigning the result only if it succeeds char ** new_values = allocator.reallocate(string_map->impl->values, capacity * sizeof(char *), allocator.state); - if (!new_values) { + if (NULL == new_values) { RCUTILS_SET_ERROR_MSG("failed to allocate memory for string_map values", allocator) return RCUTILS_RET_BAD_ALLOC; } @@ -219,7 +219,7 @@ rcutils_string_map_clear(rcutils_string_map_t * string_map) return RCUTILS_RET_STRING_MAP_INVALID, rcutils_get_default_allocator()) size_t i = 0; for (; i < string_map->impl->capacity; ++i) { - if (string_map->impl->keys[i]) { + if (string_map->impl->keys[i] != NULL) { __remove_key_and_value_at_index(string_map->impl, i); } } @@ -244,7 +244,7 @@ rcutils_string_map_set(rcutils_string_map_t * string_map, const char * key, cons rcutils_reset_error(); // default to doubling the size of the map's capacity size_t new_capacity = (string_map->impl->capacity) ? 2 * string_map->impl->capacity : 1; - rcutils_ret_t ret = rcutils_string_map_reserve(string_map, new_capacity); + ret = rcutils_string_map_reserve(string_map, new_capacity); if (ret != RCUTILS_RET_OK) { // error message is already set return ret; @@ -264,7 +264,7 @@ __get_index_of_key_if_exists( { size_t i = 0; for (; i < string_map_impl->capacity; ++i) { - if (!string_map_impl->keys[i]) { + if (NULL == string_map_impl->keys[i]) { continue; } size_t cmp_count = strlen(string_map_impl->keys[i]); @@ -305,13 +305,13 @@ rcutils_string_map_set_no_resize( return RCUTILS_RET_NOT_ENOUGH_SPACE; } for (key_index = 0; key_index < string_map->impl->capacity; ++key_index) { - if (!string_map->impl->keys[key_index]) { + if (NULL == string_map->impl->keys[key_index]) { break; } } assert(key_index < string_map->impl->capacity); // defensive, this should not happen string_map->impl->keys[key_index] = rcutils_strdup(key, allocator); - if (!string_map->impl->keys[key_index]) { + if (NULL == string_map->impl->keys[key_index]) { RCUTILS_SET_ERROR_MSG("failed to allocate memory for key", rcutils_get_default_allocator()) return RCUTILS_RET_BAD_ALLOC; } @@ -320,7 +320,7 @@ rcutils_string_map_set_no_resize( // at this point the key is in the map, waiting for the value to set/overwritten char * original_value = string_map->impl->values[key_index]; char * new_value = rcutils_strdup(value, allocator); - if (!new_value) { + if (NULL == new_value) { RCUTILS_SET_ERROR_MSG("failed to allocate memory for key", allocator) if (should_free_key_on_error) { allocator.deallocate(string_map->impl->keys[key_index], allocator.state); @@ -329,7 +329,7 @@ rcutils_string_map_set_no_resize( return RCUTILS_RET_BAD_ALLOC; } string_map->impl->values[key_index] = new_value; - if (original_value) { + if (original_value != NULL) { // clean up the old value if not NULL allocator.deallocate(original_value, allocator.state); } @@ -363,7 +363,7 @@ rcutils_string_map_unset(rcutils_string_map_t * string_map, const char * key) bool rcutils_string_map_key_exists(const rcutils_string_map_t * string_map, const char * key) { - if (!key) { + if (NULL == key) { return false; } return rcutils_string_map_key_existsn(string_map, key, strlen(key)); @@ -375,7 +375,7 @@ rcutils_string_map_key_existsn( const char * key, size_t key_length) { - if (!string_map || !string_map->impl || !key) { + if (NULL == string_map || NULL == string_map->impl || NULL == key) { return false; } size_t key_index; @@ -386,7 +386,7 @@ rcutils_string_map_key_existsn( const char * rcutils_string_map_get(const rcutils_string_map_t * string_map, const char * key) { - if (!key) { + if (NULL == key) { return NULL; } return rcutils_string_map_getn(string_map, key, strlen(key)); @@ -398,7 +398,7 @@ rcutils_string_map_getn( const char * key, size_t key_length) { - if (!string_map || !string_map->impl || !key) { + if (NULL == string_map || NULL == string_map->impl || NULL == key) { return NULL; } size_t key_index; @@ -413,14 +413,14 @@ rcutils_string_map_get_next_key( const rcutils_string_map_t * string_map, const char * key) { - if (!string_map || !string_map->impl) { + if (NULL == string_map || !string_map->impl) { return NULL; } if (string_map->impl->size == 0) { return NULL; } size_t start_index = 0; - if (key) { + if (key != NULL) { // if given a key, try to find it bool given_key_found = false; size_t i = 0; @@ -439,7 +439,7 @@ rcutils_string_map_get_next_key( // iterate through the storage and look for another non-NULL key to return size_t i = start_index; for (; i < string_map->impl->capacity; ++i) { - if (string_map->impl->keys[i]) { + if (string_map->impl->keys[i] != NULL) { // next key found, return it return string_map->impl->keys[i]; } @@ -464,9 +464,9 @@ rcutils_string_map_copy( dst_string_map->impl, "destination string map is invalid", return RCUTILS_RET_STRING_MAP_INVALID, rcutils_get_default_allocator()) const char * key = rcutils_string_map_get_next_key(src_string_map, NULL); - while (key) { + while (key != NULL) { const char * value = rcutils_string_map_get(src_string_map, key); - if (!value) { + if (NULL == value) { RCUTILS_SET_ERROR_MSG( "unable to get value for known key, should not happen", rcutils_get_default_allocator()); return RCUTILS_RET_ERROR; diff --git a/test/memory_tools/memory_tools_common.cpp b/test/memory_tools/memory_tools_common.cpp index 1639cebb..302bca0c 100644 --- a/test/memory_tools/memory_tools_common.cpp +++ b/test/memory_tools/memory_tools_common.cpp @@ -38,13 +38,13 @@ void set_on_unexpected_malloc_callback(UnexpectedCallbackType callback) free(unexpected_malloc_callback); unexpected_malloc_callback = nullptr; } - if (!callback) { + if (nullptr == callback) { return; } - if (!unexpected_malloc_callback) { + if (nullptr == unexpected_malloc_callback) { unexpected_malloc_callback = reinterpret_cast(malloc(sizeof(UnexpectedCallbackType))); - if (!unexpected_malloc_callback) { + if (NULL == unexpected_malloc_callback) { throw std::bad_alloc(); } new (unexpected_malloc_callback) UnexpectedCallbackType(); @@ -82,13 +82,13 @@ void set_on_unexpected_realloc_callback(UnexpectedCallbackType callback) free(unexpected_realloc_callback); unexpected_realloc_callback = nullptr; } - if (!callback) { + if (nullptr == callback) { return; } - if (!unexpected_realloc_callback) { + if (nullptr == unexpected_realloc_callback) { unexpected_realloc_callback = reinterpret_cast(malloc(sizeof(UnexpectedCallbackType))); - if (!unexpected_realloc_callback) { + if (nullptr == unexpected_realloc_callback) { throw std::bad_alloc(); } new (unexpected_realloc_callback) UnexpectedCallbackType(); @@ -126,7 +126,7 @@ void set_on_unexpected_free_callback(UnexpectedCallbackType callback) free(unexpected_free_callback); unexpected_free_callback = nullptr; } - if (!callback) { + if (nullptr == callback) { return; } if (!unexpected_free_callback) { diff --git a/test/test_logging_macros.c b/test/test_logging_macros.c index 010897bf..65293446 100644 --- a/test/test_logging_macros.c +++ b/test/test_logging_macros.c @@ -66,7 +66,7 @@ int main(int argc, char ** argv) if (g_log_calls != 1u) { return 3; } - if (!g_last_log_event.location) { + if (NULL == g_last_log_event.location) { return 4; } if (strcmp(g_last_log_event.location->function_name, "main")) { @@ -89,7 +89,7 @@ int main(int argc, char ** argv) if (g_log_calls != 2u) { return 10; } - if (!g_last_log_event.location) { + if (NULL == g_last_log_event.location) { return 11; } if (strcmp(g_last_log_event.location->function_name, "main")) {