Skip to content

Commit 0821655

Browse files
committed
gndtruth_extractor: Fix segfault on error opening file
1 parent 5ba236e commit 0821655

File tree

5 files changed

+97
-4
lines changed

5 files changed

+97
-4
lines changed

plugins/gndtruth_extractor/src/gndtruth_extractor.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class GndTruthMsgPackSerializer
8080
class GndTruthSerializer {
8181
public:
8282
virtual ~GndTruthSerializer() = 0;
83-
virtual void open_file(const std::string& filename) = 0;
83+
virtual bool open_file(const std::string& filename) = 0;
8484
virtual void serialize(const Sync& sync, const GndTruth& gt) = 0;
8585
virtual void close_file() = 0;
8686

@@ -103,10 +103,12 @@ class GndTruthSerializerImpl
103103
GndTruthSerializerImpl(Logger logger) : base1(logger), GndTruthSerializer() {}
104104
virtual ~GndTruthSerializerImpl() override;
105105
using base1::open_file;
106-
virtual void open_file(const std::string& filename) override {
106+
107+
[[nodiscard]]
108+
virtual bool open_file(const std::string& filename) override {
107109
std::string default_name = this->outputstream_.make_default_filename(
108110
this->serializer_.make_default_filename(default_filename));
109-
base1::open_file(filename, default_name);
111+
return base1::open_file(filename, default_name);
110112
}
111113
virtual void serialize(const Sync& sync, const GndTruth& gt) override {
112114
base1::serialize(sync, gt);
@@ -219,7 +221,10 @@ class GndTruthExtractor : public Controller {
219221
private:
220222
void open_file() {
221223
if (serializer_) {
222-
serializer_->open_file(config_.output_file);
224+
bool ok = serializer_->open_file(config_.output_file);
225+
if (!ok) {
226+
throw cloe::ModelAbort("cannot open file: {}", config_.output_file);
227+
}
223228
}
224229
}
225230
void close_file() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from pathlib import Path
2+
from conan import ConanFile
3+
4+
5+
class CloeTest(ConanFile):
6+
python_requires = "cloe-launch-profile/[~=0.19.0]@cloe/develop"
7+
python_requires_extend = "cloe-launch-profile.Base"
8+
9+
default_options = {
10+
"cloe-engine:server": False,
11+
}
12+
13+
@property
14+
def cloe_launch_env(self):
15+
return {
16+
"CLOE_LOG_LEVEL": "debug",
17+
"CLOE_STRICT_MODE": "1",
18+
"CLOE_WRITE_OUTPUT": "0",
19+
"CLOE_ROOT": Path(self.recipe_folder) / "../../..",
20+
}
21+
22+
def set_version(self):
23+
self.version = self.project_version("../../../VERSION")
24+
25+
def requirements(self):
26+
self.requires(f"cloe-engine/{self.version}@cloe/develop")
27+
self.requires(f"cloe-plugin-basic/{self.version}@cloe/develop")
28+
self.requires(f"cloe-plugin-minimator/{self.version}@cloe/develop")
29+
self.requires(f"cloe-plugin-gndtruth-extractor/{self.version}@cloe/develop")
30+
31+
if self.options["cloe-engine"].server:
32+
self.requires("boost/[<1.70]", override=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": "4",
3+
"include": [
4+
"${CLOE_ROOT}/tests/controller_basic.json"
5+
],
6+
"simulators": [
7+
{
8+
"binding": "minimator"
9+
}
10+
],
11+
"vehicles": [
12+
{
13+
"name": "default",
14+
"from": {
15+
"simulator": "minimator",
16+
"index": 0
17+
}
18+
}
19+
],
20+
"server": {
21+
"listen": false,
22+
"listen_port": 23456
23+
},
24+
"triggers": [
25+
{"event": "start", "action": "realtime_factor=-1"},
26+
{"event": "time=60", "action": "succeed"}
27+
]
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bats
2+
3+
cd "${BATS_TEST_DIRNAME}"
4+
export CLOE_ROOT="${BATS_TEST_DIRNAME}/../../.."
5+
load "${CLOE_ROOT}/tests/setup_bats.bash"
6+
load "${CLOE_ROOT}/tests/setup_testname.bash"
7+
8+
@test "$(testname 'Expect run failure' 'test_gndtruth_invalid_file.json' '29e8ff3b-86f3-4320-ba69-05600df1f836')" {
9+
cloe-engine check test_gndtruth_invalid_file.json
10+
run cloe-engine run test_gndtruth_invalid_file.json
11+
assert_exit_failure $status
12+
test $status -eq $CLOE_EXIT_ABORTED
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "4",
3+
"include": [
4+
"config_minimator_smoketest.json"
5+
],
6+
"controllers": [
7+
{
8+
"binding": "gndtruth_extractor",
9+
"vehicle": "default",
10+
"args": {
11+
"output_file": "/tmp/nonexistant/file/that/will/not/be/created.json.gz"
12+
}
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)