Skip to content

Commit 862210e

Browse files
authored
Merge pull request #74 from GregThain/static-analysis
Fix minor complaints found by static analysis
2 parents 8226e19 + 38e58fa commit 862210e

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/scitokens.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int scitoken_get_claim_string_list(const SciToken token, const char *key, char *
140140
if (err_msg) {*err_msg = strdup(exc.what());}
141141
return -1;
142142
}
143-
auto claim_list_c = static_cast<char **>(malloc(sizeof(char **) * (claim_list.size() + 1)));
143+
auto claim_list_c = static_cast<char **>(malloc(sizeof(char *) * (claim_list.size() + 1)));
144144
claim_list_c[claim_list.size()] = nullptr;
145145
int idx = 0;
146146
for (const auto &entry : claim_list) {

src/scitokens_cache.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,15 @@ get_cache_file() {
6969
return "";
7070
}
7171

72-
struct stat cache_dir_stat;
73-
if (-1 == stat(cache_dir.c_str(), &cache_dir_stat)) {
74-
if (errno == ENOENT) {
75-
if (-1 == mkdir(cache_dir.c_str(), 0700)) return "";
76-
}
72+
int r = mkdir(cache_dir.c_str(), 0700);
73+
if ((r < 0) && errno != EEXIST) {
74+
return "";
7775
}
7876

7977
std::string keycache_dir = cache_dir + "/scitokens";
80-
if (-1 == stat(keycache_dir.c_str(), &cache_dir_stat)) {
81-
if (errno == ENOENT) {
82-
if (-1 == mkdir(keycache_dir.c_str(), 0700)) return "";
83-
}
78+
r = mkdir(keycache_dir.c_str(), 0700);
79+
if ((r < 0) && errno != EEXIST) {
80+
return "";
8481
}
8582

8683
std::string keycache_file = keycache_dir + "/scitokens_cpp.sqllite";

src/scitokens_internal.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SimpleCurlGet {
4242

4343
auto curl = curl_easy_init();
4444
if (!curl) {
45-
CurlException("Failed to create a new curl handle.");
45+
throw CurlException("Failed to create a new curl handle.");
4646
}
4747

4848
if (m_maxbytes > 0) {
@@ -52,9 +52,18 @@ class SimpleCurlGet {
5252
}
5353
}
5454

55-
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
56-
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);
57-
curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
55+
CURLcode rv = curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
56+
if (rv != CURLE_OK) {
57+
throw CurlException("Failed to set CURLOPT_URL.");
58+
}
59+
rv = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);
60+
if (rv != CURLE_OK) {
61+
throw CurlException("Failed to set CURLOPT_WRITEFUNCTION.");
62+
}
63+
rv = curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
64+
if (rv != CURLE_OK) {
65+
throw CurlException("Failed to set CURLOPT_WRITEDATA.");
66+
}
5867

5968
auto res = curl_easy_perform(curl);
6069
if (res != CURLE_OK) {

0 commit comments

Comments
 (0)