diff --git a/include/aws/common/allocator.h b/include/aws/common/allocator.h index a9ba14fdc..79297f2c0 100644 --- a/include/aws/common/allocator.h +++ b/include/aws/common/allocator.h @@ -34,7 +34,7 @@ struct aws_allocator *aws_default_allocator(void); #ifdef __MACH__ /* Avoid pulling in CoreFoundation headers in a header file. */ -struct __CFAllocator; +struct __CFAllocator; /* NOLINT */ typedef const struct __CFAllocator *CFAllocatorRef; /** diff --git a/include/aws/common/array_list.h b/include/aws/common/array_list.h index 493d3eaa3..4ef924456 100644 --- a/include/aws/common/array_list.h +++ b/include/aws/common/array_list.h @@ -12,7 +12,7 @@ AWS_PUSH_SANE_WARNING_LEVEL -#define AWS_ARRAY_LIST_DEBUG_FILL 0xDD +enum { AWS_ARRAY_LIST_DEBUG_FILL = 0xDD }; struct aws_array_list { struct aws_allocator *alloc; diff --git a/include/aws/common/date_time.h b/include/aws/common/date_time.h index 1e38fa7d5..34a2a0da4 100644 --- a/include/aws/common/date_time.h +++ b/include/aws/common/date_time.h @@ -10,8 +10,7 @@ AWS_PUSH_SANE_WARNING_LEVEL -#define AWS_DATE_TIME_STR_MAX_LEN 100 -#define AWS_DATE_TIME_STR_MAX_BASIC_LEN 20 +enum { AWS_DATE_TIME_STR_MAX_LEN = 100, AWS_DATE_TIME_STR_MAX_BASIC_LEN = 20 }; struct aws_byte_buf; struct aws_byte_cursor; diff --git a/include/aws/common/hash_table.h b/include/aws/common/hash_table.h index 370b1c38d..f773dcf23 100644 --- a/include/aws/common/hash_table.h +++ b/include/aws/common/hash_table.h @@ -12,9 +12,11 @@ AWS_PUSH_SANE_WARNING_LEVEL -#define AWS_COMMON_HASH_TABLE_ITER_CONTINUE (1 << 0) -#define AWS_COMMON_HASH_TABLE_ITER_DELETE (1 << 1) -#define AWS_COMMON_HASH_TABLE_ITER_ERROR (1 << 2) +enum { + AWS_COMMON_HASH_TABLE_ITER_CONTINUE = (1 << 0), + AWS_COMMON_HASH_TABLE_ITER_DELETE = (1 << 1), + AWS_COMMON_HASH_TABLE_ITER_ERROR = (1 << 2), +}; /** * Hash table data structure. This module provides an automatically resizing diff --git a/include/aws/common/logging.h b/include/aws/common/logging.h index 87b956811..b4893a580 100644 --- a/include/aws/common/logging.h +++ b/include/aws/common/logging.h @@ -58,8 +58,10 @@ enum aws_log_level { typedef uint32_t aws_log_subject_t; /* Each library gets space for 2^^10 log subject entries */ -#define AWS_LOG_SUBJECT_STRIDE_BITS 10 -#define AWS_LOG_SUBJECT_STRIDE (1U << AWS_LOG_SUBJECT_STRIDE_BITS) +enum { + AWS_LOG_SUBJECT_STRIDE_BITS = 10, + AWS_LOG_SUBJECT_STRIDE = (1U << AWS_LOG_SUBJECT_STRIDE_BITS), +}; #define AWS_LOG_SUBJECT_BEGIN_RANGE(x) ((x)*AWS_LOG_SUBJECT_STRIDE) #define AWS_LOG_SUBJECT_END_RANGE(x) (((x) + 1) * AWS_LOG_SUBJECT_STRIDE - 1) diff --git a/include/aws/common/macros.h b/include/aws/common/macros.h index 648e39022..da3298544 100644 --- a/include/aws/common/macros.h +++ b/include/aws/common/macros.h @@ -61,7 +61,7 @@ AWS_STATIC_ASSERT(CALL_OVERLOAD_TEST(1) == 1); AWS_STATIC_ASSERT(CALL_OVERLOAD_TEST(1, 2) == 2); AWS_STATIC_ASSERT(CALL_OVERLOAD_TEST(1, 2, 3) == 3); -#define AWS_CACHE_LINE 64 +enum { AWS_CACHE_LINE = 64 }; /** * Format macro for strings of a specified length. * Allows non null-terminated strings to be used with the printf family of functions. diff --git a/include/aws/common/statistics.h b/include/aws/common/statistics.h index 3ad06a429..bc24e9e81 100644 --- a/include/aws/common/statistics.h +++ b/include/aws/common/statistics.h @@ -18,8 +18,10 @@ struct aws_array_list; typedef uint32_t aws_crt_statistics_category_t; /* Each library gets space for 2^^8 category entries */ -#define AWS_CRT_STATISTICS_CATEGORY_STRIDE_BITS 8 -#define AWS_CRT_STATISTICS_CATEGORY_STRIDE (1U << AWS_CRT_STATISTICS_CATEGORY_STRIDE_BITS) +enum { + AWS_CRT_STATISTICS_CATEGORY_STRIDE_BITS = 8, + AWS_CRT_STATISTICS_CATEGORY_STRIDE = (1U << AWS_CRT_STATISTICS_CATEGORY_STRIDE_BITS) +}; #define AWS_CRT_STATISTICS_CATEGORY_BEGIN_RANGE(x) ((x)*AWS_CRT_STATISTICS_CATEGORY_STRIDE) #define AWS_CRT_STATISTICS_CATEGORY_END_RANGE(x) (((x) + 1) * AWS_CRT_STATISTICS_CATEGORY_STRIDE - 1) diff --git a/include/aws/common/uuid.h b/include/aws/common/uuid.h index 4bd92c832..e3d9b1ade 100644 --- a/include/aws/common/uuid.h +++ b/include/aws/common/uuid.h @@ -17,7 +17,7 @@ struct aws_uuid { }; /* 36 bytes for the UUID plus one more for the null terminator. */ -#define AWS_UUID_STR_LEN 37 +enum { AWS_UUID_STR_LEN = 37 }; AWS_EXTERN_C_BEGIN diff --git a/source/allocator.c b/source/allocator.c index fc314693a..3551daf78 100644 --- a/source/allocator.c +++ b/source/allocator.c @@ -291,7 +291,7 @@ static void *s_cf_allocator_reallocate(void *ptr, CFIndex new_size, CFOptionFlag aws_mem_realloc(allocator, &original_allocation, original_size, (size_t)new_size); size_t new_allocation_size = (size_t)new_size; - memcpy(original_allocation, &new_allocation_size, sizeof(size_t)); + memcpy(original_allocation, &new_allocation_size, sizeof(size_t)); /* NOLINT */ return (void *)((uint8_t *)original_allocation + sizeof(size_t)); } diff --git a/source/allocator_sba.c b/source/allocator_sba.c index 095cfb9ca..ab1e833f0 100644 --- a/source/allocator_sba.c +++ b/source/allocator_sba.c @@ -44,7 +44,7 @@ #define AWS_SBA_TAG_VALUE 0x736f6d6570736575ULL /* list of sizes of bins, must be powers of 2, and less than AWS_SBA_PAGE_SIZE * 0.5 */ -#define AWS_SBA_BIN_COUNT 5 +enum { AWS_SBA_BIN_COUNT = 5 }; static const size_t s_bin_sizes[AWS_SBA_BIN_COUNT] = {32, 64, 128, 256, 512}; static const size_t s_max_bin_size = 512; diff --git a/source/hash_table.c b/source/hash_table.c index 88926e48f..21f989a84 100644 --- a/source/hash_table.c +++ b/source/hash_table.c @@ -973,7 +973,7 @@ uint64_t aws_hash_byte_cursor_ptr(const void *item) { /* first digits of pi in hex */ uint32_t b = 0x3243F6A8, c = 0x885A308D; hashlittle2(cur->ptr, cur->len, &c, &b); - AWS_RETURN_WITH_POSTCONDITION(((uint64_t)b << 32) | c, aws_byte_cursor_is_valid(cur)); + AWS_RETURN_WITH_POSTCONDITION(((uint64_t)b << 32) | c, aws_byte_cursor_is_valid(cur)); /* NOLINT */ } uint64_t aws_hash_ptr(const void *item) { diff --git a/source/log_formatter.c b/source/log_formatter.c index d4be0c0c6..321312981 100644 --- a/source/log_formatter.c +++ b/source/log_formatter.c @@ -20,15 +20,17 @@ # pragma warning(disable : 4204) /* non-constant aggregate initializer */ #endif -/* (max) strlen of "[]" */ -#define LOG_LEVEL_PREFIX_PADDING 7 +enum { + /* (max) strlen of "[]" */ + LOG_LEVEL_PREFIX_PADDING = 7, -/* (max) strlen of "[]" */ -#define THREAD_ID_PREFIX_PADDING 22 + /* (max) strlen of "[]" */ + THREAD_ID_PREFIX_PADDING = 22, -/* strlen of (user-content separator) " - " + "\n" + spaces between prefix fields + brackets around timestamp + 1 + - subject_name padding */ -#define MISC_PADDING 15 + /* strlen of (user-content separator) " - " + "\n" + spaces between prefix fields + brackets around timestamp + 1 + + subject_name padding */ + MISC_PADDING = 15, +}; #define MAX_LOG_LINE_PREFIX_SIZE \ (LOG_LEVEL_PREFIX_PADDING + THREAD_ID_PREFIX_PADDING + MISC_PADDING + AWS_DATE_TIME_STR_MAX_LEN) diff --git a/source/logging.c b/source/logging.c index fdc29576d..d0e96c0b9 100644 --- a/source/logging.c +++ b/source/logging.c @@ -454,7 +454,7 @@ static enum aws_log_level s_noalloc_stderr_logger_get_log_level(struct aws_logge return (enum aws_log_level)aws_atomic_load_int(&impl->level); } -#define MAXIMUM_NO_ALLOC_LOG_LINE_SIZE 8192 +enum { MAXIMUM_NO_ALLOC_LOG_LINE_SIZE = 8192 }; static int s_noalloc_stderr_logger_log( struct aws_logger *logger, diff --git a/source/memtrace.c b/source/memtrace.c index 651fd9361..eea342ad1 100644 --- a/source/memtrace.c +++ b/source/memtrace.c @@ -57,7 +57,7 @@ struct alloc_tracer { }; /* number of frames to skip in call stacks (s_alloc_tracer_track, and the vtable function) */ -#define FRAMES_TO_SKIP 2 +enum { FRAMES_TO_SKIP = 2 }; static void *s_trace_mem_acquire(struct aws_allocator *allocator, size_t size); static void s_trace_mem_release(struct aws_allocator *allocator, void *ptr); diff --git a/source/posix/clock.c b/source/posix/clock.c index 90e213ea7..b2c3bc3f0 100644 --- a/source/posix/clock.c +++ b/source/posix/clock.c @@ -43,11 +43,11 @@ static int s_legacy_get_time(uint64_t *timestamp) { # if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 static aws_thread_once s_thread_once_flag = AWS_THREAD_ONCE_STATIC_INIT; -static int (*s_gettime_fn)(clockid_t __clock_id, struct timespec *__tp) = NULL; +static int (*s_gettime_fn)(clockid_t clock_id, struct timespec *tp) = NULL; static void s_do_osx_loads(void *user_data) { (void)user_data; - s_gettime_fn = (int (*)(clockid_t __clock_id, struct timespec * __tp)) dlsym(RTLD_DEFAULT, "clock_gettime"); + s_gettime_fn = (int (*)(clockid_t clock_id, struct timespec * tp)) dlsym(RTLD_DEFAULT, "clock_gettime"); } int aws_high_res_clock_get_ticks(uint64_t *timestamp) { diff --git a/source/posix/device_random.c b/source/posix/device_random.c index 23ab1cd7b..53f063ddf 100644 --- a/source/posix/device_random.c +++ b/source/posix/device_random.c @@ -51,7 +51,8 @@ int aws_device_random_buffer_append(struct aws_byte_buf *output, size_t n) { /* read() can fail if N is too large (e.g. x64 macos fails if N > INT32_MAX), * so work in reasonably sized chunks. */ while (n > 0) { - size_t capped_n = aws_min_size(n, 1024 * 1024 * 1024 * 1 /* 1GiB */); + size_t capped_n = aws_min_size( + n, 1024 * 1024 * 1024 * 1 /* 1GiB */); /* NOLINT(bugprone-implicit-widening-of-multiplication-result) */ ssize_t amount_read = read(s_rand_fd, output->buffer + output->len, capped_n); diff --git a/source/posix/mutex.c b/source/posix/mutex.c index 2cbf2db66..b5c865700 100644 --- a/source/posix/mutex.c +++ b/source/posix/mutex.c @@ -23,9 +23,11 @@ int aws_mutex_init(struct aws_mutex *mutex) { int return_code = AWS_OP_SUCCESS; if (!err_code) { - if ((err_code = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL)) || - (err_code = pthread_mutex_init(&mutex->mutex_handle, &attr))) { - + err_code = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); + if (!err_code) { + err_code = pthread_mutex_init(&mutex->mutex_handle, &attr); + } + if (err_code) { return_code = aws_private_convert_and_raise_error_code(err_code); } pthread_mutexattr_destroy(&attr); diff --git a/source/posix/system_info.c b/source/posix/system_info.c index 98d05f7c2..b8ebc1cc0 100644 --- a/source/posix/system_info.c +++ b/source/posix/system_info.c @@ -242,7 +242,7 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info * if (function_len >= (sizeof(frame->function) - 1)) { function_len = sizeof(frame->function) - 1; } - strncpy(frame->function, function_start, function_end - function_start); + strncpy(frame->function, function_start, function_len); /* find base addr for library/exe */ Dl_info addr_info; diff --git a/source/process_common.c b/source/process_common.c index ef432374b..24a25094b 100644 --- a/source/process_common.c +++ b/source/process_common.c @@ -9,7 +9,7 @@ #include #include -#define MAX_BUFFER_SIZE (2048) +enum { MAX_BUFFER_SIZE = 2048 }; int aws_run_command_result_init(struct aws_allocator *allocator, struct aws_run_command_result *result) { if (!allocator || !result) {