Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
dcdb
dcdb
Commits
a9e4962b
Commit
a9e4962b
authored
Mar 01, 2021
by
Michael Ott
Browse files
Fix segfaults due to erasing elements of the querries container in the inner loop
parent
41186ff3
Changes
1
Hide whitespace changes
Inline
Side-by-side
tools/dcdbquery/query.cpp
View file @
a9e4962b
...
...
@@ -396,29 +396,34 @@ void DCDBQuery::prepareQuery(std::list<std::string> sensors, std::list<std::stri
void
DCDBQuery
::
execute
()
{
std
::
string
prevSensorName
;
for
(
auto
q
:
queries
)
{
if
(
q
.
first
.
name
!=
prevSensorName
)
{
auto
q
=
queries
.
begin
();
while
(
q
!=
queries
.
end
())
{
if
(
q
->
first
.
name
!=
prevSensorName
)
{
// Find all queries for the same sensor
std
::
pair
<
queryMap_t
::
iterator
,
queryMap_t
::
iterator
>
range
=
queries
.
equal_range
(
q
.
first
);
std
::
pair
<
queryMap_t
::
iterator
,
queryMap_t
::
iterator
>
range
=
queries
.
equal_range
(
q
->
first
);
/* Base scaling factor and unit of the public sensor */
baseUnit
=
DCDB
::
UnitConv
::
fromString
(
q
.
first
.
unit
);
baseScalingFactor
=
q
.
first
.
scaling_factor
;
baseUnit
=
DCDB
::
UnitConv
::
fromString
(
q
->
first
.
unit
);
baseScalingFactor
=
q
->
first
.
scaling_factor
;
std
::
list
<
DCDB
::
SensorDataStoreReading
>
results
;
DCDB
::
Sensor
sensor
(
connection
,
q
.
first
);
DCDB
::
Sensor
sensor
(
connection
,
q
->
first
);
// Query aggregates first
auto
it
=
range
.
first
;
while
(
it
!=
range
.
second
)
{
while
(
it
!=
range
.
second
)
{
if
(
it
->
second
.
aggregate
!=
DCDB
::
AGGREGATE_NONE
)
{
sensor
.
query
(
results
,
start_ts
,
end_ts
,
it
->
second
.
aggregate
);
if
(
results
.
size
()
>
0
)
{
genOutput
(
results
,
it
,
std
::
next
(
it
));
results
.
clear
();
// Remove the query from the list so it doesn't show up in the raw values below anymore
if
(
it
==
range
.
first
)
{
range
.
first
=
std
::
next
(
it
);
}
if
(
it
==
q
)
{
q
=
std
::
next
(
q
);
}
it
=
queries
.
erase
(
it
);
continue
;
}
...
...
@@ -427,7 +432,7 @@ void DCDBQuery::execute() {
}
// Query raw values next
for
(
auto
it
=
range
.
first
;
it
!=
range
.
second
;
it
++
)
{
for
(
auto
it
=
range
.
first
;
it
!=
range
.
second
;
it
++
)
{
if
(
it
->
second
.
aggregate
==
DCDB
::
AGGREGATE_NONE
)
{
sensor
.
query
(
results
,
start_ts
,
end_ts
,
DCDB
::
AGGREGATE_NONE
);
break
;
...
...
@@ -439,8 +444,9 @@ void DCDBQuery::execute() {
}
prevSensorName
=
q
.
first
.
name
;
prevSensorName
=
q
->
first
.
name
;
}
q
++
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment