Skip to content

Commit

Permalink
Fixing various issues reported by static code analysis and compiler w…
Browse files Browse the repository at this point in the history
…arnings
  • Loading branch information
jgaa committed Aug 17, 2024
1 parent e2020a5 commit a4249fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion include/restc-cpp/test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,28 @@ namespace restc_cpp {
// Substitute localhost with whatever is in the environment-variable
// RESTC_CPP_TEST_DOCKER_ADDRESS
inline std::string GetDockerUrl(std::string url) {
const char *docker_addr = std::getenv("RESTC_CPP_TEST_DOCKER_ADDRESS");
const char* docker_addr = nullptr;

#ifdef _WIN32
// On Windows, use _dupenv_s to safely retrieve the environment variable
size_t len = 0;
errno_t err = _dupenv_s(&docker_addr, &len, "RESTC_CPP_TEST_DOCKER_ADDRESS");
if (err != 0 || docker_addr == nullptr) {
docker_addr = nullptr; // Ensure docker_addr is nullptr if the variable isn't set
}
#else
// On Linux/macOS, use std::getenv
docker_addr = std::getenv("RESTC_CPP_TEST_DOCKER_ADDRESS");
#endif

if (docker_addr) {
boost::replace_all(url, "localhost", docker_addr);
#ifdef _WIN32
// Free the allocated memory on Windows
free(docker_addr);
#endif
}

return url;
}

Expand Down
2 changes: 1 addition & 1 deletion src/RequestBodyFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RequestBodyFileImpl : public RequestBody
if (read_this_time == 0) {
const auto err = errno;
throw IoException(string{"file read failed: "}
+ to_string(err) + " " + strerror(err));
+ to_string(err) + " " + std::system_category().message(err));
}

bytes_read_ += read_this_time;
Expand Down

0 comments on commit a4249fe

Please sign in to comment.