diff --git a/.github/workflows/static-analyzers.yml b/.github/workflows/static-analyzers.yml new file mode 100644 index 0000000..1069ea5 --- /dev/null +++ b/.github/workflows/static-analyzers.yml @@ -0,0 +1,27 @@ +name: Static Analyzers + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + cpplint: + runs-on: ubuntu-latest + container: helics/buildenv:cpplint + + steps: + - uses: actions/checkout@v2 + - name: Run cpplint + run: cpplint --counting=detailed --recursive gmlc/utilities tests + cppcheck: + runs-on: ubuntu-latest + container: helics/buildenv:cppcheck2 + + steps: + - uses: actions/checkout@v2 + - name: Run cppcheck + run: cppcheck --enable=performance,portability --language=c++ --suppressions-list=config/cppcheck_suppressions.txt --error-exitcode=-4 -i gmlc/extra -i orig_code -i scripts -i config . \ No newline at end of file diff --git a/config/cppcheck_suppressions.txt b/config/cppcheck_suppressions.txt new file mode 100644 index 0000000..1b98ea6 --- /dev/null +++ b/config/cppcheck_suppressions.txt @@ -0,0 +1,2 @@ +#unusedFunction:units/x12_conv.cpp:1024 +arrayIndexOutOfBounds:gmlc/utilities/dpcomp.cpp diff --git a/gmlc/utilities/main.c b/gmlc/utilities/main.c deleted file mode 100644 index 22d3230..0000000 --- a/gmlc/utilities/main.c +++ /dev/null @@ -1,43 +0,0 @@ -/* -Copyright (c) 2017-2019, -Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance -for Sustainable Energy, LLC. See the top-level NOTICE for additional details. -All rights reserved. SPDX-License-Identifier: BSD-3-Clause -*/ - -/* Created by Anjuta version 1.2.4 */ -/* This file will not be overwritten */ - -#include -#include -#include - -#include "namecmp.h" - -int main() -{ - FILE *fp; - char n1[100]; - char n2[100]; - float score; - gencharcomp(); - if ((fp = fopen("testfile.txt", "r")) == NULL) - { - fprintf(stderr, "Unable to open name file\n"); - exit(-1); - } - fgets(n1, 99, fp); - fgets(n2, 99, fp); - n1[strlen(n1) - 1] = '\0'; - n2[strlen(n2) - 1] = '\0'; - printf("name 1 = \"%s\", name 2 = \"%s\"\n\n", n1, n2); - // score=dp_comp(n1,n2); - // printf("\nscore=%f\n",score); - - score = jaro_winkler_comp(n1, n2); - printf("Jaro-Winkler score= %f\n", score); - printf("edit distance=%d\n", edit_distace(n1, n2)); - score = SW_comp(n1, n2); - printf("\nscore=%f\n", score); - return 0; -} diff --git a/gmlc/utilities/string_viewConversion.h b/gmlc/utilities/string_viewConversion.h index a533b72..14e0355 100644 --- a/gmlc/utilities/string_viewConversion.h +++ b/gmlc/utilities/string_viewConversion.h @@ -27,6 +27,7 @@ #endif #include +#include #include namespace gmlc { @@ -140,7 +141,7 @@ namespace utilities { template<> inline long double numConv(string_view V) { - return std::stold(std::string(V.data(),V.length())); + return std::stold(std::string(V.data(), V.length())); } // template for numeric conversion returning the position @@ -191,7 +192,7 @@ namespace utilities { try { return numConv(V); } - catch (std::invalid_argument) { + catch (const std::invalid_argument&) { return defValue; } } @@ -216,7 +217,7 @@ namespace utilities { } return res; } - catch (std::invalid_argument) { + catch (const std::invalid_argument&) { return defValue; } } diff --git a/gmlc/utilities/string_viewDef.h b/gmlc/utilities/string_viewDef.h index 87a7f75..ffdcd46 100644 --- a/gmlc/utilities/string_viewDef.h +++ b/gmlc/utilities/string_viewDef.h @@ -26,14 +26,14 @@ All rights reserved. SPDX-License-Identifier: BSD-3-Clause namespace gmlc { namespace utilities { using string_view = std::string_view; -} +} // namespace utilities } // namespace gmlc #elif defined(USE_BOOST_STRING_VIEW) #include "boost/utility/string_view.hpp" namespace gmlc { namespace utilities { using string_view = boost::string_view; -} +} // namespace utilities } // namespace gmlc #else #include diff --git a/gmlc/utilities/timeStringOps.hpp b/gmlc/utilities/timeStringOps.hpp index 9f66c03..093b0a6 100644 --- a/gmlc/utilities/timeStringOps.hpp +++ b/gmlc/utilities/timeStringOps.hpp @@ -49,7 +49,7 @@ for example "1.234" or "1032ms" @throws invalid_argument if the string is not a valid time */ template - timeX loadTimeFromString(std::string timeString, time_units defUnit) + timeX loadTimeFromString(const std::string& timeString, time_units defUnit) { return timeX(getTimeValue(timeString, defUnit)); }