Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor complaints found by static analysis #74

Merged
merged 4 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scitokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int scitoken_get_claim_string_list(const SciToken token, const char *key, char *
if (err_msg) {*err_msg = strdup(exc.what());}
return -1;
}
auto claim_list_c = static_cast<char **>(malloc(sizeof(char **) * (claim_list.size() + 1)));
auto claim_list_c = static_cast<char **>(malloc(sizeof(char *) * (claim_list.size() + 1)));
claim_list_c[claim_list.size()] = nullptr;
int idx = 0;
for (const auto &entry : claim_list) {
Expand Down
15 changes: 6 additions & 9 deletions src/scitokens_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,15 @@ get_cache_file() {
return "";
}

struct stat cache_dir_stat;
if (-1 == stat(cache_dir.c_str(), &cache_dir_stat)) {
if (errno == ENOENT) {
if (-1 == mkdir(cache_dir.c_str(), 0700)) return "";
}
int r = mkdir(cache_dir.c_str(), 0700);
if ((r < 0) && errno != EEXIST) {
return "";
}

std::string keycache_dir = cache_dir + "/scitokens";
if (-1 == stat(keycache_dir.c_str(), &cache_dir_stat)) {
if (errno == ENOENT) {
if (-1 == mkdir(keycache_dir.c_str(), 0700)) return "";
}
r = mkdir(keycache_dir.c_str(), 0700);
if ((r < 0) && errno != EEXIST) {
return "";
}

std::string keycache_file = keycache_dir + "/scitokens_cpp.sqllite";
Expand Down
17 changes: 13 additions & 4 deletions src/scitokens_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SimpleCurlGet {

auto curl = curl_easy_init();
if (!curl) {
CurlException("Failed to create a new curl handle.");
throw CurlException("Failed to create a new curl handle.");
}

if (m_maxbytes > 0) {
Expand All @@ -52,9 +52,18 @@ class SimpleCurlGet {
}
}

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
CURLcode rv = curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
if (rv != CURLE_OK) {
throw CurlException("Failed to set CURLOPT_URL.");
}
rv = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);
if (rv != CURLE_OK) {
throw CurlException("Failed to set CURLOPT_WRITEFUNCTION.");
}
rv = curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
if (rv != CURLE_OK) {
throw CurlException("Failed to set CURLOPT_WRITEDATA.");
}

auto res = curl_easy_perform(curl);
if (res != CURLE_OK) {
Expand Down