diff --git a/rttest/src/rttest.cpp b/rttest/src/rttest.cpp index f5a5849..af86d47 100644 --- a/rttest/src/rttest.cpp +++ b/rttest/src/rttest.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include // NOLINT(build/include_order) #include @@ -250,7 +251,8 @@ int Rttest::read_args(int argc, char ** argv) switch (c) { case 'i': { - int arg = atoi(optarg); + int arg = 0; + std::from_chars(optarg, optarg + strlen(optarg), arg); if (arg < 0) { iterations = 0; } else { @@ -280,8 +282,12 @@ int Rttest::read_args(int argc, char ** argv) } break; case 't': - sched_priority = atoi(optarg); - break; + { + int prio = 0; + std::from_chars(optarg, optarg + strlen(optarg), prio); + sched_priority = prio; + break; + } case 's': { std::string input(optarg); @@ -328,7 +334,7 @@ int Rttest::read_args(int argc, char ** argv) int rttest_get_params(struct rttest_params * params_in) { - if (params_in == NULL) { + if (params_in == nullptr) { return -1; } @@ -557,7 +563,7 @@ int Rttest::spin_once( struct timespec wakeup_time, current_time; multiply_timespec(update_period, i, &wakeup_time); add_timespecs(start_time, &wakeup_time, &wakeup_time); - clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &wakeup_time, NULL); + clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &wakeup_time, nullptr); clock_gettime(CLOCK_MONOTONIC, ¤t_time); this->record_jitter(&wakeup_time, ¤t_time, i); @@ -751,7 +757,7 @@ int Rttest::accumulate_statistics(size_t iteration) int Rttest::calculate_statistics(struct rttest_results * output) { - if (output == NULL) { + if (output == nullptr) { fprintf(stderr, "Need to allocate rttest_results struct\n"); return -1; } @@ -789,7 +795,7 @@ int rttest_calculate_statistics(struct rttest_results * results) int rttest_get_statistics(struct rttest_results * output) { - if (output == NULL) { + if (output == nullptr) { return -1; } @@ -826,7 +832,7 @@ int rttest_get_sample_at(const size_t iteration, int64_t * sample) if (!thread_rttest_instance) { return -1; } - if (sample == NULL) { + if (sample == nullptr) { return -1; } return thread_rttest_instance->get_sample_at(iteration, *sample); @@ -908,7 +914,7 @@ int Rttest::write_results_file(char * filename) fprintf(stderr, "No sample buffer was saved, not writing results\n"); return -1; } - if (filename == NULL) { + if (filename == nullptr) { fprintf(stderr, "No results filename given, not writing results\n"); return -1; } diff --git a/tlsf_cpp/include/tlsf_cpp/tlsf.hpp b/tlsf_cpp/include/tlsf_cpp/tlsf.hpp index e3140e9..1ef0071 100644 --- a/tlsf_cpp/include/tlsf_cpp/tlsf.hpp +++ b/tlsf_cpp/include/tlsf_cpp/tlsf.hpp @@ -90,27 +90,29 @@ struct tlsf_heap_allocator rcl_allocator_t get_rcl_allocator() { - rcl_allocator_t allocator = rcl_get_default_allocator(); - allocator.allocate = [](size_t size, void * state) -> void * { - return malloc_ex(size, state); - }; - allocator.deallocate = [](void * ptr, void * state) { - free_ex(ptr, state); - }; - allocator.reallocate = [](void * ptr, size_t size, void * state) -> void * { - return realloc_ex(ptr, size, state); - }; - allocator.zero_allocate = [](size_t n, size_t size, void * state) -> void * { - return calloc_ex(n, size, state); - }; - allocator.state = memory_pool; - return allocator; + // Designated initializers must follow rcl_allocator_t's declaration order: + // allocate, deallocate, reallocate, zero_allocate, state. + return rcl_allocator_t{ + .allocate = [](size_t size, void * state) -> void * { + return malloc_ex(size, state); + }, + .deallocate = [](void * ptr, void * state) { + free_ex(ptr, state); + }, + .reallocate = [](void * ptr, size_t size, void * state) -> void * { + return realloc_ex(ptr, size, state); + }, + .zero_allocate = [](size_t n, size_t size, void * state) -> void * { + return calloc_ex(n, size, state); + }, + .state = memory_pool, + }; } template struct rebind { - typedef tlsf_heap_allocator other; + using other = tlsf_heap_allocator; }; char * memory_pool;