Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Base DAQ
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BIAS
DAQs
Base DAQ
Commits
a7a8f6a5
Commit
a7a8f6a5
authored
1 year ago
by
Valerio Pastore
Browse files
Options
Downloads
Patches
Plain Diff
fix structure dangling pointer
parent
0687e980
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/Base_Packet.h
+16
-12
16 additions, 12 deletions
include/Base_Packet.h
with
16 additions
and
12 deletions
include/Base_Packet.h
+
16
−
12
View file @
a7a8f6a5
...
...
@@ -21,25 +21,26 @@ namespace inaf::oasbo::PacketLib {
class
BasePacketStructure
{
protected:
using
Structure
=
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
;
std
::
string
source
;
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
structure
;
Structure
structure
;
uint
byteSize
;
std
::
vector
<
uint
>
fieldSizes
;
std
::
unordered_map
<
uint
,
uint
>
indexToOffsetsMap
;
std
::
unordered_map
<
std
::
string
,
uint
>
fieldNameToIndexMap
;
std
::
unordered_map
<
uint
,
std
::
string
>
indexToFieldNameMap
;
std
::
function
<
Structure
(
std
::
string
)
>
sourceReadingFunc
;
virtual
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
readStructureFromSource
(
std
::
string
source
)
=
0
;
void
updateFieldSizes
(
const
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
&
paramsTuple
)
{
const
Structure
&
paramsTuple
)
{
std
::
for_each
(
paramsTuple
.
begin
(),
paramsTuple
.
end
(),
[
&
](
const
std
::
tuple
<
uint
,
std
::
string
,
uint
>
&
tup
)
{
this
->
fieldSizes
.
push_back
(
std
::
get
<
2
>
(
tup
));
});
}
void
updateFieldOffsets
(
const
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
&
paramsTuple
)
{
const
Structure
&
paramsTuple
)
{
uint
offset
=
0
;
for
(
size_t
i
=
0
;
i
<
paramsTuple
.
size
();
i
++
)
{
indexToOffsetsMap
[
i
]
=
offset
;
...
...
@@ -47,7 +48,7 @@ protected:
}
}
void
updateFieldNameAndIndexMap
(
const
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
&
paramsTuple
)
{
const
Structure
&
paramsTuple
)
{
std
::
for_each
(
paramsTuple
.
begin
(),
paramsTuple
.
end
(),
[
&
](
const
std
::
tuple
<
uint
,
std
::
string
,
uint
>
&
tup
)
{
this
->
fieldNameToIndexMap
[
std
::
get
<
1
>
(
tup
)]
=
std
::
get
<
0
>
(
...
...
@@ -58,7 +59,7 @@ protected:
}
void
updateStructure
(
std
::
string
source
)
{
this
->
source
=
source
;
this
->
structure
=
readStructureFromSource
(
source
);
this
->
structure
=
sourceReadingFunc
(
source
);
updateFieldSizes
(
structure
);
updateFieldOffsets
(
structure
);
updateFieldNameAndIndexMap
(
structure
);
...
...
@@ -69,7 +70,9 @@ protected:
public
:
virtual
~
BasePacketStructure
()
=
default
;
BasePacketStructure
(
std
::
string
source
)
:
source
(
source
){};
BasePacketStructure
(
std
::
string
source
,
std
::
function
<
Structure
(
std
::
string
)
>
sourceReadingFunc
)
:
source
(
source
),
sourceReadingFunc
(
sourceReadingFunc
){
this
->
updateStructure
(
source
);
};
BasePacketStructure
(
const
BasePacketStructure
&
other
){
this
->
source
=
other
.
source
;
this
->
byteSize
=
other
.
byteSize
;
...
...
@@ -77,6 +80,7 @@ public:
this
->
indexToOffsetsMap
=
other
.
indexToOffsetsMap
;
this
->
fieldNameToIndexMap
=
other
.
fieldNameToIndexMap
;
this
->
indexToFieldNameMap
=
other
.
indexToFieldNameMap
;
this
->
sourceReadingFunc
=
other
.
sourceReadingFunc
;
}
void
changeSource
(
std
::
string
source
)
{
...
...
@@ -262,7 +266,7 @@ protected:
public
:
BasePacketTempl
(
BasePacketStructure
&
structure
)
{
this
->
structure
=
&
structure
;
this
->
structure
=
new
BasePacketStructure
(
structure
)
;
this
->
binaryPointer
=
new
uint8_t
[
structure
.
getByteSize
()];
}
...
...
@@ -312,7 +316,7 @@ public:
uint
max_writable
=
this
->
structure
->
getByteSize
();
if
(
size
>
max_writable
)
{
std
::
cerr
<<
"Error: you are trying to copy "
<<
size
<<
"byte where the max size is: "
<<
max_writable
<<
"
byte where the max size is: "
<<
max_writable
<<
std
::
endl
;
std
::
cerr
<<
"
\t
I copy only until "
<<
max_writable
<<
" byte"
<<
std
::
endl
;
...
...
@@ -328,13 +332,13 @@ public:
uint
max_writable
=
this
->
structure
->
getByteSize
();
if
(
offset
>
max_writable
)
{
std
::
cerr
<<
"Error: you are trying to copy starting from "
<<
offset
<<
"byte where the max size is: "
<<
max_writable
<<
offset
<<
"
byte where the max size is: "
<<
max_writable
<<
std
::
endl
;
return
-
1
;
}
if
(
size
+
offset
>
max_writable
)
{
std
::
cerr
<<
"Error: you are trying to copy "
<<
size
+
offset
<<
"byte where the max size is: "
<<
max_writable
<<
"
byte where the max size is: "
<<
max_writable
<<
std
::
endl
;
std
::
cerr
<<
"
\t
I copy only until "
<<
max_writable
<<
" byte"
<<
std
::
endl
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment