Skip to content

Commit 0eaf363

Browse files
authored
Merge branch 'BehaviorTree:master' into master
2 parents d8ca1f1 + aa085b7 commit 0eaf363

File tree

6 files changed

+63
-6
lines changed

6 files changed

+63
-6
lines changed

.github/workflows/sonarcube.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Sonarcube Scan
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-latest
12+
env:
13+
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
18+
- name: Install Build Wrapper
19+
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v4
20+
21+
- name: Install Dependencies
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y libzmq3-dev libsqlite3-dev
25+
26+
- name: Install googletest
27+
uses: Bacondish2023/setup-googletest@v1
28+
29+
- name: Run Build Wrapper
30+
run: |
31+
mkdir build
32+
cmake -S . -B build
33+
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release
34+
- name: SonarQube Scan
35+
uses: SonarSource/sonarqube-scan-action@v4
36+
env:
37+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Put the name of your token here
38+
with:
39+
args: >
40+
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ else()
2222
add_definitions(-Wpedantic -fno-omit-frame-pointer)
2323
endif()
2424

25+
# create compile_commands.json
26+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
27+
2528

2629
#---- project configuration ----
2730
option(BTCPP_SHARED_LIBS "Build shared libraries" ON)

include/behaviortree_cpp/bt_factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class Tree
149149
[[nodiscard]] Blackboard::Ptr rootBlackboard();
150150

151151
//Call the visitor for each node of the tree.
152-
void applyVisitor(const std::function<void(const TreeNode*)>& visitor);
152+
void applyVisitor(const std::function<void(const TreeNode*)>& visitor) const;
153153

154154
//Call the visitor for each node of the tree.
155155
void applyVisitor(const std::function<void(TreeNode*)>& visitor);

include/behaviortree_cpp/utils/convert_impl.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ inline void checkTruncation(const From& from)
9393
if constexpr(std::is_integral_v<From> && std::is_floating_point_v<To>)
9494
{
9595
// Check if value can be represented exactly in the target type
96-
To as_float = static_cast<To>(from);
97-
From back_conv = static_cast<From>(as_float);
98-
if(back_conv != from)
96+
constexpr auto max_exact = (1LL << std::numeric_limits<double>::digits) - 1;
97+
if(from > max_exact || from < -max_exact)
9998
{
100-
throw std::runtime_error("Loss of precision in conversion to floating point");
99+
throw std::runtime_error("Loss of precision when converting a large integer number "
100+
"to floating point:" +
101+
std::to_string(from));
101102
}
102103
}
103104
// Handle floating point to integer

sonar-project.properties

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sonar.projectKey=BehaviorTree_BehaviorTree.CPP
2+
sonar.organization=behaviortree
3+
4+
# This is the name and version displayed in the SonarCloud UI.
5+
#sonar.projectName=BehaviorTree.CPP
6+
#sonar.projectVersion=1.0
7+
8+
9+
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
10+
#sonar.sources=.
11+
12+
# Encoding of the source code. Default is default system encoding
13+
#sonar.sourceEncoding=UTF-8

src/bt_factory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ Blackboard::Ptr Tree::rootBlackboard()
597597
return {};
598598
}
599599

600-
void Tree::applyVisitor(const std::function<void(const TreeNode*)>& visitor)
600+
void Tree::applyVisitor(const std::function<void(const TreeNode*)>& visitor) const
601601
{
602602
BT::applyRecursiveVisitor(static_cast<const TreeNode*>(rootNode()), visitor);
603603
}

0 commit comments

Comments
 (0)