diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2021-03-07 11:57:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-07 11:57:55 +0100 |
| commit | 4cc4e038bc9ac868156884f58b02d89849962f08 (patch) | |
| tree | 6402b7c11f07f3cc1aa06680a98b5935cc96872b /src | |
| parent | 5b9d009293db4021b57a4949f467f2dd1081870a (diff) | |
| parent | e3b0dda249ad58ed6cf0f7ed44924659b9fee50f (diff) | |
| download | PROJ-4cc4e038bc9ac868156884f58b02d89849962f08.tar.gz PROJ-4cc4e038bc9ac868156884f58b02d89849962f08.zip | |
Merge pull request #2560 from rouault/coverityscan_fixes
Several fixes/improvements spotted by CoverityScan
Diffstat (limited to 'src')
| -rw-r--r-- | src/4D_api.cpp | 6 | ||||
| -rw-r--r-- | src/apps/cct.cpp | 2 | ||||
| -rw-r--r-- | src/apps/cs2cs.cpp | 8 | ||||
| -rw-r--r-- | src/apps/gie.cpp | 2 | ||||
| -rw-r--r-- | src/apps/projinfo.cpp | 8 | ||||
| -rw-r--r-- | src/initcache.cpp | 5 | ||||
| -rw-r--r-- | src/iso19111/common.cpp | 10 | ||||
| -rw-r--r-- | src/iso19111/crs.cpp | 15 | ||||
| -rw-r--r-- | src/iso19111/util.cpp | 11 | ||||
| -rw-r--r-- | src/networkfilemanager.cpp | 88 | ||||
| -rw-r--r-- | src/projections/igh.cpp | 5 |
11 files changed, 115 insertions, 45 deletions
diff --git a/src/4D_api.cpp b/src/4D_api.cpp index 909c3c32..9c5b45f5 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -1610,7 +1610,7 @@ PJ_INFO proj_info (void) { /* build search path string */ auto ctx = pj_get_default_ctx(); - if (!ctx || ctx->search_paths.empty()) { + if (ctx->search_paths.empty()) { const auto searchpaths = pj_get_default_searchpaths(ctx); for( const auto& path: searchpaths ) { buf = path_append(buf, path.c_str(), &buf_size); @@ -1624,8 +1624,8 @@ PJ_INFO proj_info (void) { free(const_cast<char*>(info.searchpath)); info.searchpath = buf ? buf : empty; - info.paths = ctx ? ctx->c_compat_paths : nullptr; - info.path_count = ctx ? static_cast<int>(ctx->search_paths.size()) : 0; + info.paths = ctx->c_compat_paths; + info.path_count = static_cast<int>(ctx->search_paths.size()); pj_release_lock (); return info; diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp index 4f21f10a..ca62c570 100644 --- a/src/apps/cct.cpp +++ b/src/apps/cct.cpp @@ -455,7 +455,7 @@ int main(int argc, char **argv) { size_t len = strlen(comment); if (len >= 1) comment[len - 1] = '\0'; - comment_delimiter = (comment && *comment) ? whitespace : blank_comment; + comment_delimiter = *comment ? whitespace : blank_comment; /* Time to print the result */ /* use same arguments to printf format string for both radians and diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp index 5542a282..19f924d4 100644 --- a/src/apps/cs2cs.cpp +++ b/src/apps/cs2cs.cpp @@ -422,7 +422,13 @@ int main(int argc, char **argv) { emess(1, "missing argument for --accuracy"); std::exit(1); } - accuracy = c_locale_stod(*argv); + try { + accuracy = c_locale_stod(*argv); + } catch (const std::exception &e) { + std::cerr << "Invalid value for option --accuracy: " + << e.what() << std::endl; + std::exit(1); + } } else if (strcmp(*argv, "--authority") == 0 ) { ++argv; diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index 95c7da34..07c06dd9 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -958,7 +958,7 @@ Tell GIE what to expect, when transforming the ACCEPTed input err_const_from_errno(proj_errno(T.P)), proj_errno (T.P), expect_failure_with_errno, - F->lineno + static_cast<int>(F->lineno) ); return another_failing_failure (); } diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 8c266e94..71830f00 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -942,7 +942,13 @@ int main(int argc, char **argv) { } } else if (arg == "--accuracy" && i + 1 < argc) { i++; - minimumAccuracy = c_locale_stod(argv[i]); + try { + minimumAccuracy = c_locale_stod(argv[i]); + } catch (const std::exception &e) { + std::cerr << "Invalid value for option --accuracy: " << e.what() + << std::endl; + usage(); + } } else if (arg == "--area" && i + 1 < argc) { i++; area = argv[i]; diff --git a/src/initcache.cpp b/src/initcache.cpp index cf9460ab..41605cc6 100644 --- a/src/initcache.cpp +++ b/src/initcache.cpp @@ -25,6 +25,7 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ +#include <assert.h> #include <string.h> #include "proj.h" @@ -49,6 +50,7 @@ paralist *pj_clone_paralist( const paralist *list) { paralist *newitem = (paralist *) malloc(sizeof(paralist) + strlen(list->param)); + assert(newitem); newitem->used = 0; newitem->next = nullptr; @@ -152,6 +154,7 @@ void pj_insert_initcache( const char *filekey, const paralist *list ) cache_alloc = cache_alloc * 2 + 15; cache_key_new = (char **) malloc(sizeof(char*) * cache_alloc); + assert(cache_key_new); if( cache_key && cache_count ) { memcpy( cache_key_new, cache_key, sizeof(char*) * cache_count); @@ -161,6 +164,7 @@ void pj_insert_initcache( const char *filekey, const paralist *list ) cache_paralist_new = (paralist **) malloc(sizeof(paralist*) * cache_alloc); + assert(cache_paralist_new); if( cache_paralist && cache_count ) { memcpy( cache_paralist_new, cache_paralist, @@ -174,6 +178,7 @@ void pj_insert_initcache( const char *filekey, const paralist *list ) ** Duplicate the filekey and paralist, and insert in cache. */ cache_key[cache_count] = (char *) malloc(strlen(filekey)+1); + assert(cache_key[cache_count]); strcpy( cache_key[cache_count], filekey ); cache_paralist[cache_count] = pj_clone_paralist( list ); diff --git a/src/iso19111/common.cpp b/src/iso19111/common.cpp index 0eb40f12..b70845ae 100644 --- a/src/iso19111/common.cpp +++ b/src/iso19111/common.cpp @@ -119,6 +119,16 @@ UnitOfMeasure &UnitOfMeasure::operator=(const UnitOfMeasure &other) { // --------------------------------------------------------------------------- //! @cond Doxygen_Suppress +UnitOfMeasure &UnitOfMeasure::operator=(UnitOfMeasure &&other) { + BaseObject::operator=(std::move(static_cast<BaseObject &&>(other))); + *d = std::move(*(other.d)); + return *this; +} +//! @endcond + +// --------------------------------------------------------------------------- + +//! @cond Doxygen_Suppress UnitOfMeasureNNPtr UnitOfMeasure::create(const UnitOfMeasure &other) { return util::nn_make_shared<UnitOfMeasure>(other); } diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index 9c4c04c3..6bf607fa 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -2517,10 +2517,17 @@ bool GeographicCRS::is2DPartOf3D(util::nn<const GeographicCRS *> other, util::IComparable::Criterion::EQUIVALENT))) { return false; } - const auto thisDatum = datumNonNull(dbContext); - const auto otherDatum = other->datumNonNull(dbContext); - return thisDatum->_isEquivalentTo(otherDatum.get(), - util::IComparable::Criterion::EQUIVALENT); + try { + const auto thisDatum = datumNonNull(dbContext); + const auto otherDatum = other->datumNonNull(dbContext); + return thisDatum->_isEquivalentTo( + otherDatum.get(), util::IComparable::Criterion::EQUIVALENT); + } catch (const util::InvalidValueTypeException &) { + // should not happen really, but potentially thrown by + // Identifier::Private::setProperties() + assert(false); + return false; + } } //! @endcond diff --git a/src/iso19111/util.cpp b/src/iso19111/util.cpp index 21d45e44..7b69f4aa 100644 --- a/src/iso19111/util.cpp +++ b/src/iso19111/util.cpp @@ -81,6 +81,17 @@ BaseObjectNNPtr::~BaseObjectNNPtr() = default; // --------------------------------------------------------------------------- +//! @cond Doxygen_Suppress +// cppcheck-suppress operatorEqVarError +BaseObject &BaseObject::operator=(BaseObject &&) { + d->self_.reset(); + return *this; +} + +//! @endcond + +// --------------------------------------------------------------------------- + /** Keep a reference to ourselves as an internal weak pointer. So that * extractGeographicBaseObject() can later return a shared pointer on itself. */ diff --git a/src/networkfilemanager.cpp b/src/networkfilemanager.cpp index b68a60a3..c22e77fa 100644 --- a/src/networkfilemanager.cpp +++ b/src/networkfilemanager.cpp @@ -1523,7 +1523,7 @@ struct CurlFileHandle { CurlFileHandle(const CurlFileHandle &) = delete; CurlFileHandle &operator=(const CurlFileHandle &) = delete; - explicit CurlFileHandle(const char *url, CURL *handle, + explicit CurlFileHandle(PJ_CONTEXT *ctx, const char *url, CURL *handle, const char *ca_bundle_path); ~CurlFileHandle(); @@ -1596,26 +1596,37 @@ static std::string GetExecutableName() { // --------------------------------------------------------------------------- -CurlFileHandle::CurlFileHandle(const char *url, CURL *handle, +static void checkRet(PJ_CONTEXT *ctx, CURLcode code, int line) { + if (code != CURLE_OK) { + pj_log(ctx, PJ_LOG_ERROR, "curl_easy_setopt at line %d failed", line); + } +} + +#define CHECK_RET(ctx, code) checkRet(ctx, code, __LINE__) + +// --------------------------------------------------------------------------- + +CurlFileHandle::CurlFileHandle(PJ_CONTEXT *ctx, const char *url, CURL *handle, const char *ca_bundle_path) : m_url(url), m_handle(handle) { - curl_easy_setopt(handle, CURLOPT_URL, m_url.c_str()); + CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_URL, m_url.c_str())); if (getenv("PROJ_CURL_VERBOSE")) - curl_easy_setopt(handle, CURLOPT_VERBOSE, 1); + CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_VERBOSE, 1)); // CURLOPT_SUPPRESS_CONNECT_HEADERS is defined in curl 7.54.0 or newer. #if LIBCURL_VERSION_NUM >= 0x073600 - curl_easy_setopt(handle, CURLOPT_SUPPRESS_CONNECT_HEADERS, 1L); + CHECK_RET(ctx, + curl_easy_setopt(handle, CURLOPT_SUPPRESS_CONNECT_HEADERS, 1L)); #endif // Enable following redirections. Requires libcurl 7.10.1 at least. - curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 10); + CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1)); + CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 10)); if (getenv("PROJ_UNSAFE_SSL")) { - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L); + CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L)); + CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L)); } // Custom path to SSL certificates. @@ -1632,10 +1643,12 @@ CurlFileHandle::CurlFileHandle(const char *url, CURL *handle, ca_bundle_path = getenv("SSL_CERT_FILE"); } if (ca_bundle_path != nullptr) { - curl_easy_setopt(handle, CURLOPT_CAINFO, ca_bundle_path); + CHECK_RET(ctx, + curl_easy_setopt(handle, CURLOPT_CAINFO, ca_bundle_path)); } - curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, m_szCurlErrBuf); + CHECK_RET(ctx, + curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, m_szCurlErrBuf)); if (getenv("PROJ_NO_USERAGENT") == nullptr) { m_useragent = "PROJ " STR(PROJ_VERSION_MAJOR) "." STR( @@ -1644,7 +1657,8 @@ CurlFileHandle::CurlFileHandle(const char *url, CURL *handle, if (!exeName.empty()) { m_useragent = exeName + " using " + m_useragent; } - curl_easy_setopt(handle, CURLOPT_USERAGENT, m_useragent.data()); + CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_USERAGENT, + m_useragent.data())); } } @@ -1703,7 +1717,7 @@ PROJ_NETWORK_HANDLE *CurlFileHandle::open(PJ_CONTEXT *ctx, const char *url, return nullptr; auto file = std::unique_ptr<CurlFileHandle>(new CurlFileHandle( - url, hCurlHandle, + ctx, url, hCurlHandle, ctx->ca_bundle_path.empty() ? nullptr : ctx->ca_bundle_path.c_str())); double oldDelay = MIN_RETRY_DELAY_MS; @@ -1715,19 +1729,20 @@ PROJ_NETWORK_HANDLE *CurlFileHandle::open(PJ_CONTEXT *ctx, const char *url, offset + size_to_read - 1); while (true) { - curl_easy_setopt(hCurlHandle, CURLOPT_RANGE, szBuffer); + CHECK_RET(ctx, curl_easy_setopt(hCurlHandle, CURLOPT_RANGE, szBuffer)); headers.clear(); headers.reserve(16 * 1024); - curl_easy_setopt(hCurlHandle, CURLOPT_HEADERDATA, &headers); - curl_easy_setopt(hCurlHandle, CURLOPT_HEADERFUNCTION, - pj_curl_write_func); + CHECK_RET(ctx, + curl_easy_setopt(hCurlHandle, CURLOPT_HEADERDATA, &headers)); + CHECK_RET(ctx, curl_easy_setopt(hCurlHandle, CURLOPT_HEADERFUNCTION, + pj_curl_write_func)); body.clear(); body.reserve(size_to_read); - curl_easy_setopt(hCurlHandle, CURLOPT_WRITEDATA, &body); - curl_easy_setopt(hCurlHandle, CURLOPT_WRITEFUNCTION, - pj_curl_write_func); + CHECK_RET(ctx, curl_easy_setopt(hCurlHandle, CURLOPT_WRITEDATA, &body)); + CHECK_RET(ctx, curl_easy_setopt(hCurlHandle, CURLOPT_WRITEFUNCTION, + pj_curl_write_func)); file->m_szCurlErrBuf[0] = '\0'; @@ -1736,11 +1751,15 @@ PROJ_NETWORK_HANDLE *CurlFileHandle::open(PJ_CONTEXT *ctx, const char *url, long response_code = 0; curl_easy_getinfo(hCurlHandle, CURLINFO_HTTP_CODE, &response_code); - curl_easy_setopt(hCurlHandle, CURLOPT_HEADERDATA, nullptr); - curl_easy_setopt(hCurlHandle, CURLOPT_HEADERFUNCTION, nullptr); + CHECK_RET(ctx, + curl_easy_setopt(hCurlHandle, CURLOPT_HEADERDATA, nullptr)); + CHECK_RET(ctx, curl_easy_setopt(hCurlHandle, CURLOPT_HEADERFUNCTION, + nullptr)); - curl_easy_setopt(hCurlHandle, CURLOPT_WRITEDATA, nullptr); - curl_easy_setopt(hCurlHandle, CURLOPT_WRITEFUNCTION, nullptr); + CHECK_RET(ctx, + curl_easy_setopt(hCurlHandle, CURLOPT_WRITEDATA, nullptr)); + CHECK_RET( + ctx, curl_easy_setopt(hCurlHandle, CURLOPT_WRITEFUNCTION, nullptr)); if (response_code == 0 || response_code >= 300) { const double delay = @@ -1809,19 +1828,20 @@ static size_t pj_curl_read_range(PJ_CONTEXT *ctx, offset + size_to_read - 1); while (true) { - curl_easy_setopt(hCurlHandle, CURLOPT_RANGE, szBuffer); + CHECK_RET(ctx, curl_easy_setopt(hCurlHandle, CURLOPT_RANGE, szBuffer)); headers.clear(); headers.reserve(16 * 1024); - curl_easy_setopt(hCurlHandle, CURLOPT_HEADERDATA, &headers); - curl_easy_setopt(hCurlHandle, CURLOPT_HEADERFUNCTION, - pj_curl_write_func); + CHECK_RET(ctx, + curl_easy_setopt(hCurlHandle, CURLOPT_HEADERDATA, &headers)); + CHECK_RET(ctx, curl_easy_setopt(hCurlHandle, CURLOPT_HEADERFUNCTION, + pj_curl_write_func)); body.clear(); body.reserve(size_to_read); - curl_easy_setopt(hCurlHandle, CURLOPT_WRITEDATA, &body); - curl_easy_setopt(hCurlHandle, CURLOPT_WRITEFUNCTION, - pj_curl_write_func); + CHECK_RET(ctx, curl_easy_setopt(hCurlHandle, CURLOPT_WRITEDATA, &body)); + CHECK_RET(ctx, curl_easy_setopt(hCurlHandle, CURLOPT_WRITEFUNCTION, + pj_curl_write_func)); handle->m_szCurlErrBuf[0] = '\0'; @@ -1830,8 +1850,10 @@ static size_t pj_curl_read_range(PJ_CONTEXT *ctx, long response_code = 0; curl_easy_getinfo(hCurlHandle, CURLINFO_HTTP_CODE, &response_code); - curl_easy_setopt(hCurlHandle, CURLOPT_WRITEDATA, nullptr); - curl_easy_setopt(hCurlHandle, CURLOPT_WRITEFUNCTION, nullptr); + CHECK_RET(ctx, + curl_easy_setopt(hCurlHandle, CURLOPT_WRITEDATA, nullptr)); + CHECK_RET( + ctx, curl_easy_setopt(hCurlHandle, CURLOPT_WRITEFUNCTION, nullptr)); if (response_code == 0 || response_code >= 300) { const double delay = diff --git a/src/projections/igh.cpp b/src/projections/igh.cpp index a6bac0c4..570a97a1 100644 --- a/src/projections/igh.cpp +++ b/src/projections/igh.cpp @@ -226,7 +226,10 @@ PJ *PROJECTION(igh) { } /* mollweide zones */ - setup_zone(P, Q, 1, pj_moll, -d100, 0, -d100); + if( !setup_zone(P, Q, 1, pj_moll, -d100, 0, -d100)) + { + return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); + } /* y0 ? */ xy1 = Q->pj[0]->fwd(lp, Q->pj[0]); /* zone 1 */ |
