From 31f5f67df0dc91accf0f9ac66da2f987cd0949d6 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Thu, 4 Jun 2020 14:19:33 -0700 Subject: [PATCH] PR feedback --- rcl_logging_spdlog/test/fixtures.hpp | 7 ++++++- rcl_logging_spdlog/test/test_logging_interface.cpp | 13 ++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rcl_logging_spdlog/test/fixtures.hpp b/rcl_logging_spdlog/test/fixtures.hpp index fb885d3..51db959 100644 --- a/rcl_logging_spdlog/test/fixtures.hpp +++ b/rcl_logging_spdlog/test/fixtures.hpp @@ -22,6 +22,7 @@ #include #include +#include #include #include "gtest/gtest.h" @@ -89,7 +90,11 @@ class LoggingTest : public AllocatorTest throw std::runtime_error("Failed to glob for log files"); } - char raw_line[2048]; +#ifdef _WIN32 + char raw_line[MAX_PATH]; +#else + char raw_line[PATH_MAX]; +#endif char * ret = fgets(raw_line, sizeof(raw_line), fp); pclose(fp); if (nullptr == ret) { diff --git a/rcl_logging_spdlog/test/test_logging_interface.cpp b/rcl_logging_spdlog/test/test_logging_interface.cpp index c4f6816..e1e9b83 100644 --- a/rcl_logging_spdlog/test/test_logging_interface.cpp +++ b/rcl_logging_spdlog/test/test_logging_interface.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -64,24 +65,22 @@ class RestoreEnvVar // TODO(cottsay): Remove when ros2/rcpputils#63 is resolved static fs::path current_path() { - char * cwd; #ifdef _WIN32 #ifdef UNICODE #error "rcpputils::fs does not support Unicode paths" #endif - cwd = _getcwd(NULL, 0); + char cwd[MAX_PATH]; + if (nullptr == _getcwd(cwd, MAX_PATH)) { #else - cwd = getcwd(NULL, 0); + char cwd[PATH_MAX]; + if (nullptr == getcwd(cwd, PATH_MAX)) { #endif - if (nullptr == cwd) { std::error_code ec{errno, std::system_category()}; errno = 0; throw std::system_error{ec, "cannot get current working directory"}; } - std::string ret(cwd); - free(cwd); - return fs::path(ret); + return fs::path(cwd); } TEST_F(LoggingTest, init_invalid)