From 8a89d3d1c54cca6eefcdbc8bcea0ce8ac3663bfb Mon Sep 17 00:00:00 2001 From: Federico Montesino Pouzols <federico.montesino-pouzols@stfc.ac.uk> Date: Wed, 14 Oct 2015 09:52:31 +0100 Subject: [PATCH] clang-format + softer error handling in CheckMantidVersion, re #13951 --- .../DataHandling/src/CheckMantidVersion.cpp | 32 ++++++++++++++----- Framework/ICat/src/GSoap/stdsoap2.cpp | 5 +-- Framework/Kernel/src/ANN/kd_dump.cpp | 8 +++-- .../LiveData/src/LoadDAE/isisds_command.cpp | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Framework/DataHandling/src/CheckMantidVersion.cpp b/Framework/DataHandling/src/CheckMantidVersion.cpp index 379744d6bfc..01776379510 100644 --- a/Framework/DataHandling/src/CheckMantidVersion.cpp +++ b/Framework/DataHandling/src/CheckMantidVersion.cpp @@ -109,17 +109,33 @@ void CheckMantidVersion::exec() { Json::Value root; bool parseOK = r.parse(json, root); if (!parseOK) { - g_log.error() << "Error trying to parse this JSON string from GitHub: " - << json << std::endl - << ". Error details: " << r.getFormattedErrorMessages() - << std::endl; - throw std::runtime_error("Error found when parsing version information " - "retrieved from GitHub as a JSON string."); + // just warning. The parser is able to get relevant info even if there are + // formatting issues like missing quotes or brackets. + g_log.warning() << "Error found when parsing version information " + "retrieved from GitHub as a JSON string. " + "Error trying to parse this JSON string: " << json + << std::endl + << ". Parsing error details: " + << r.getFormattedErrorMessages() << std::endl; } - std::string gitHubVersionTag = root["tag_name"].asString(); - mostRecentVersion = cleanVersionTag(gitHubVersionTag); + std::string gitHubVersionTag; + try { + gitHubVersionTag = root["tag_name"].asString(); + } catch (std::runtime_error &re) { + g_log.error() + << "Error while trying to get the field 'tag_name' from " + "the version information retrieved from GitHub. This " + "algorithm cannot continue and will stop now. Error details: " + << re.what() << std::endl; + + mostRecentVersion = "Could not get information from GitHub"; + setProperty("MostRecentVersion", mostRecentVersion); + setProperty("IsNewVersionAvailable", isNewVersionAvailable); + return; + } + mostRecentVersion = cleanVersionTag(gitHubVersionTag); isNewVersionAvailable = isVersionMoreRecent(currentVersion, mostRecentVersion); if (isNewVersionAvailable) { diff --git a/Framework/ICat/src/GSoap/stdsoap2.cpp b/Framework/ICat/src/GSoap/stdsoap2.cpp index 642794f1e67..20a01ac2c17 100644 --- a/Framework/ICat/src/GSoap/stdsoap2.cpp +++ b/Framework/ICat/src/GSoap/stdsoap2.cpp @@ -16062,12 +16062,13 @@ int SOAP_FMAC2 soap_puthttphdr(struct soap *soap, int status, size_t count) { if (soap->mime.start) { const char startStr[] = "\"; start=\""; strcat(soap->tmpbuf, startStr); - strncat(soap->tmpbuf, soap->mime.start, sizeof(soap->tmpbuf)-sizeof(startStr)); + strncat(soap->tmpbuf, soap->mime.start, + sizeof(soap->tmpbuf) - sizeof(startStr)); } strcat(soap->tmpbuf, "\""); if (r) { const char startInfoStr[] = "; start-info=\""; - size_t lenStart = sizeof(soap->tmpbuf)-sizeof(startInfoStr); + size_t lenStart = sizeof(soap->tmpbuf) - sizeof(startInfoStr); strncat(soap->tmpbuf, startInfoStr, lenStart); size_t lenR = lenStart - strnlen(r, lenStart); strncat(soap->tmpbuf, r, lenR); diff --git a/Framework/Kernel/src/ANN/kd_dump.cpp b/Framework/Kernel/src/ANN/kd_dump.cpp index 47230ad5a08..f01241a4dd6 100644 --- a/Framework/Kernel/src/ANN/kd_dump.cpp +++ b/Framework/Kernel/src/ANN/kd_dump.cpp @@ -335,7 +335,9 @@ annReadDump(istream &in, // input stream in >> the_bnd_box_hi[j]; } - if (std::numeric_limits<int>::max() <= the_n_pts / sizeof(ANNidx)) { + if (0 > the_n_pts || + static_cast<size_t>(std::numeric_limits<int>::max()) <= + static_cast<size_t>(the_n_pts / sizeof(ANNidx))) { annError("Too big number of elements for the point index array. This " "would cause an overflow when allocating memory", ANNabort); @@ -439,7 +441,9 @@ static ANNkd_ptr annReadTree(istream &in, // input stream in >> n_bnds; // number of bounding sides // allocate bounds array - if (std::numeric_limits<int>::max() <= n_bnds / sizeof(ANNorthHalfSpace)) { + if (0 < n_bnds || + static_cast<size_t>(std::numeric_limits<int>::max()) <= + static_cast<size_t>(n_bnds / sizeof(ANNorthHalfSpace))) { annError("Too big number of bounding sides, would cause overflow when " "allocating memory", ANNabort); diff --git a/Framework/LiveData/src/LoadDAE/isisds_command.cpp b/Framework/LiveData/src/LoadDAE/isisds_command.cpp index 201cc1f771a..b54ea2c9781 100644 --- a/Framework/LiveData/src/LoadDAE/isisds_command.cpp +++ b/Framework/LiveData/src/LoadDAE/isisds_command.cpp @@ -147,7 +147,7 @@ SOCKET isisds_send_open(const char *host, ISISDSAccessMode access_type, } int zero = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&setkeepalive, - sizeof(setkeepalive)); + sizeof(setkeepalive)); if (0 != zero) { closesocket(s); return INVALID_SOCKET; -- GitLab