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

Cppcheck 2.15 #5282

Merged
merged 11 commits into from
Oct 31, 2024
  •  
  •  
  •  
17 changes: 11 additions & 6 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
# That container is too old to work with the actions that are on node20 now...
#container:
# image: nrel/cppcheck:2.3
Expand Down Expand Up @@ -36,6 +36,11 @@ jobs:
--suppress=useStlAlgorithm \
--suppress=unmatchedSuppression \
--suppress=unusedPrivateFunction \
--suppress=missingIncludeSystem \
--suppress=normalCheckLevelMaxBranches \
--suppress=returnByReference \
--suppress=shadowFunction \
--suppress=checkersReport \
--suppress=functionStatic:src/utilities/core/EnumBase.hpp \
--suppress=functionStatic:src/utilities/core/StaticInitializer.hpp \
--suppress=functionStatic:src/utilities/units/QuantityFactory.hpp \
Expand All @@ -55,11 +60,11 @@ jobs:
--template='[{file}:{line}]:({severity}),[{id}],{message}' \
-j $(nproc) \
--max-configs=1 \
-i src/cli/test \
-i src/airflow/contam \
-i src/polypartition \
-i src/nano \
./src \
-i src/cli/test/ \
-i src/airflow/contam/ \
-i src/polypartition/ \
-i src/nano/ \
. \
Comment on lines +63 to +67
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This effectively adds the root directories "python" and "ruby" to cppcheck

3>&1 1>&2 2>&3 | tee cppcheck.txt

- name: Parse and colorize cppcheck
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ coverage.xml
.pytest_cache/
junit.xml

.cppcheck*/

CMakeUserPresets.json
6 changes: 6 additions & 0 deletions ci/colorize_cppcheck_results.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import re
from collections import Counter

EXCLUSIONS = {
'duplInheritedMember': ["defines member function with name 'iddObjectType' also defined in its parent class"]
}

def colorize(lines):
def bold(s):
Expand Down Expand Up @@ -64,6 +67,9 @@ def format_severity(txt, severity):
m = re_message.match(line)
if m:
d = m.groupdict()
if d['id'] in EXCLUSIONS:
if any([x in d['message'] for x in EXCLUSIONS[d['id']]]):
continue
matched_messages.append(d)
else:
colored_lines.append(red(line))
Expand Down
18 changes: 8 additions & 10 deletions embedded/CreateEmbeddedSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ int main(int argc, char* argv[]) {
return 1;
}

auto* infile = argv[1];
const auto* infile = argv[1];
auto* outfile = argv[2];
auto* filenum = argv[3];
auto* embeddedname = argv[4];
const auto* filenum = argv[3];
const auto* embeddedname = argv[4];

int ret, flush;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
Expand All @@ -41,7 +39,7 @@ int main(int argc, char* argv[]) {
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
int ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
if (ret != Z_OK) return 1;

FILE* source = fopen(infile, "rb");
Expand All @@ -52,11 +50,11 @@ int main(int argc, char* argv[]) {

std::fstream outstream(outfile, std::fstream::out | std::fstream::trunc);

// This is the compressed length in chars;
unsigned length = 0;

if (outstream.is_open()) {
outstream << "static const uint8_t embedded_file_" << filenum << "[] = {";
int flush = 0;
// This is the compressed length in chars;
unsigned length = 0;
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
Expand All @@ -73,7 +71,7 @@ int main(int argc, char* argv[]) {
strm.next_out = out;
ret = deflate(&strm, flush); /* no bad return value */
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
have = CHUNK - strm.avail_out;
unsigned have = CHUNK - strm.avail_out;

for (unsigned i = 0; i != have; ++i) {
if (length != 0) {
Expand Down
12 changes: 7 additions & 5 deletions python/engine/PythonEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,11 @@ spec.loader.exec_module(module)
return result;
}

int PythonEngine::numberOfArguments(ScriptObject& classInstanceObject, std::string_view methodName) {
int PythonEngine::numberOfArguments(ScriptObject& methodObject, std::string_view methodName) {

int numberOfArguments = -1;

auto val = std::any_cast<PythonObject>(classInstanceObject.object);
auto val = std::any_cast<PythonObject>(methodObject.object);
if (PyObject_HasAttrString(val.obj_, methodName.data()) == 0) {
// FAILED
return numberOfArguments;
Expand All @@ -386,13 +386,15 @@ int PythonEngine::numberOfArguments(ScriptObject& classInstanceObject, std::stri
if (PyMethod_Check(method)) {
PyObject* func = PyMethod_Function(method); // Borrowed
if (auto* code = PyFunction_GetCode(func)) { // Borrowed
auto* co = (PyCodeObject*)code;
// cppcheck-suppress cstyleCast
const auto* co = (PyCodeObject*)code;
numberOfArguments = co->co_argcount - 1; // This includes `self`
}
} else if (PyFunction_Check(method)) {
// Shouldn't enter this block here
if (auto code = PyFunction_GetCode(method)) {
auto* co = (PyCodeObject*)code;
if (auto * code = PyFunction_GetCode(method)) {
// cppcheck-suppress cstyleCast
const auto* co = (PyCodeObject*)code;
numberOfArguments = co->co_argcount;
}
}
Expand Down
12 changes: 6 additions & 6 deletions python/engine/test/PythonEngine_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

#include <gtest/gtest.h>

#include "measure/ModelMeasure.hpp"
#include "measure/OSArgument.hpp"
#include "measure/OSMeasure.hpp"
#include "measure/OSRunner.hpp"
#include "model/Model.hpp"
#include "scriptengine/ScriptEngine.hpp"
#include "../../../src/measure/ModelMeasure.hpp"
#include "../../../src/measure/OSArgument.hpp"
#include "../../../src/measure/OSMeasure.hpp"
#include "../../../src/measure/OSRunner.hpp"
#include "../../../src/model/Model.hpp"
#include "../../../src/scriptengine/ScriptEngine.hpp"

#include <fmt/format.h>

Expand Down
2 changes: 1 addition & 1 deletion ruby/bindings/InitRubyBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
***********************************************************************************************************************/

#include "InitRubyBindings.hpp"
#include "RubyEval.hpp"
#include "../interpreter/RubyEval.hpp"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of normalizing the way the includes are used.


// #define HAVE_ISFINITE 1
#include <ruby.h>
Expand Down
4 changes: 2 additions & 2 deletions ruby/engine/RubyEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
***********************************************************************************************************************/

#include "RubyEngine.hpp"
#include "InitRubyBindings.hpp"
#include "RubyException.hpp"
#include "../bindings/InitRubyBindings.hpp"
#include "../interpreter/RubyException.hpp"
#include <embedded_files.hxx>
#include <csignal>
#include <stdexcept>
Expand Down
10 changes: 5 additions & 5 deletions ruby/engine/test/RubyEngine_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

#include <gtest/gtest.h>

#include "measure/ModelMeasure.hpp"
#include "measure/OSArgument.hpp"
#include "measure/OSMeasure.hpp"
#include "model/Model.hpp"
#include "scriptengine/ScriptEngine.hpp"
#include "../../../src/measure/ModelMeasure.hpp"
#include "../../../src/measure/OSArgument.hpp"
#include "../../../src/measure/OSMeasure.hpp"
#include "../../../src/model/Model.hpp"
#include "../../../src/scriptengine/ScriptEngine.hpp"

#include <fmt/format.h>

Expand Down
20 changes: 10 additions & 10 deletions ruby/interpreter/RubyEval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#ifndef RUBYEVAL_included
#define RUBYEVAL_included

#include "ruby.h"
#include "./RubyException.hpp"
#include <ruby.h>
#include "RubyException.hpp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curios , why are using relative path above but keeps the hpp name here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the question, could you rephrase please?


namespace openstudio {

Expand Down Expand Up @@ -49,21 +49,21 @@ inline VALUE evalString(const std::string& t_str) {
// Generally speaking, the backtrace is there, but not for the case where it's a stack too deep error
const ID ID_backtrace = rb_intern_const("backtrace");
if (exception_class != rb_eSysStackError && rb_respond_to(errinfo, ID_backtrace)) {
std::vector<std::string> backtrace_lines;
// std::vector<std::string> backtrace_lines;
std::string btlines;
/*volatile*/ VALUE backtrace;
if (!NIL_P(backtrace = rb_funcall(errinfo, ID_backtrace, 0))) {
VALUE backtracejoin = rb_ary_join(backtrace, rb_str_new2("\n"));
btlines = StringValuePtr(backtracejoin);

// Get the backing C array of the ruby array
VALUE* elements = RARRAY_PTR(backtrace);
for (long c = 0; c < RARRAY_LEN(backtrace); ++c) {
VALUE entry = elements[c];
[[maybe_unused]] char* backtrace_line = RSTRING_PTR(entry);
char* backtrace_line2 = StringValuePtr(entry);
backtrace_lines.emplace_back(backtrace_line2);
}
// VALUE* elements = RARRAY_PTR(backtrace);
// for (long c = 0; c < RARRAY_LEN(backtrace); ++c) {
// VALUE entry = elements[c];
// [[maybe_unused]] char* backtrace_line = RSTRING_PTR(entry);
// char* backtrace_line2 = StringValuePtr(entry);
// backtrace_lines.emplace_back(backtrace_line2);
// }
}

if (!btlines.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion ruby/module/openstudio_rb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See also https://openstudio.net/license
***********************************************************************************************************************/

#include "InitRubyBindings.hpp"
#include "../bindings/InitRubyBindings.hpp"
#include <RubyAPI.hpp>
#include <iostream>
#include <ruby.h>
Expand Down
Loading
Loading