From f43c24d2c0a2246de1ad63985825dcf7764395ee Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Mon, 28 Oct 2024 22:14:50 +0100 Subject: [PATCH 1/2] set _errbuf to the empty string before use --- cpp/include/kvikio/shim/libcurl.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/include/kvikio/shim/libcurl.hpp b/cpp/include/kvikio/shim/libcurl.hpp index cee50c5947..2d717a7caa 100644 --- a/cpp/include/kvikio/shim/libcurl.hpp +++ b/cpp/include/kvikio/shim/libcurl.hpp @@ -150,7 +150,7 @@ class CurlHandle { /** * @brief Construct a new curl handle. * - * Typically, do not use this directly instead use the `create_curl_handle()` macro. + * Typically, do not call this directly instead use the `create_curl_handle()` macro. * * @param handle An unused curl easy handle pointer, which is retained on destruction. * @param source_file Path of source file of the caller (for error messages). @@ -166,6 +166,7 @@ class CurlHandle { setopt(CURLOPT_NOSIGNAL, 1L); // We always set CURLOPT_ERRORBUFFER to get better error messages. + _errbuf[0] = 0; // Set the error buffer as empty. setopt(CURLOPT_ERRORBUFFER, _errbuf); // Make curl_easy_perform() fail when receiving HTTP code errors. @@ -216,7 +217,7 @@ class CurlHandle { // Perform the curl operation and check for errors. CURLcode err = curl_easy_perform(handle()); if (err != CURLE_OK) { - std::string msg(_errbuf); + std::string msg(_errbuf); // We can do this because we always initialize `_errbuf` as empty. std::stringstream ss; ss << "curl_easy_perform() error near " << _source_file << ":" << _source_line; if (msg.empty()) { From 23dc7622056522c7981caa507cf6a80eeed3f81a Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Mon, 28 Oct 2024 22:15:33 +0100 Subject: [PATCH 2/2] strip '\0' from __FILE__ --- cpp/include/kvikio/shim/libcurl.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpp/include/kvikio/shim/libcurl.hpp b/cpp/include/kvikio/shim/libcurl.hpp index 2d717a7caa..635ea4c7fd 100644 --- a/cpp/include/kvikio/shim/libcurl.hpp +++ b/cpp/include/kvikio/shim/libcurl.hpp @@ -20,6 +20,7 @@ "cannot include the remote IO API, please build KvikIO with libcurl (-DKvikIO_REMOTE_SUPPORT=ON)" #endif +#include #include #include #include @@ -161,6 +162,10 @@ class CurlHandle { _source_file(std::move(source_file)), _source_line(std::move(source_line)) { + // Removing all '\0' characters + _source_file.erase(std::remove(_source_file.begin(), _source_file.end(), '\0'), + _source_file.end()); + // Need CURLOPT_NOSIGNAL to support threading, see // setopt(CURLOPT_NOSIGNAL, 1L);