Skip to content

Commit 14392fa

Browse files
committed
fix: values of local variables that are children of structs, arrays, bitfields or unions are set to invalid values when the setOffset() function of the parent is called.
For example when a child of the Json built in data type is used as a reference argument to a function the values of the child and all its children become zero. For those four pattern types `setOffset()` changes the offsets of all the children and if the children are local the offset is set to the offset of the parent pattern which is clearly wrong. The fix consists on removing the code that changes the offsets of local variables in the four (five?) setOffset() functions. Also fixed unions using local variables to determine the pattern size.
1 parent 55b67de commit 14392fa

4 files changed

Lines changed: 10 additions & 30 deletions

File tree

lib/include/pl/patterns/pattern_array_dynamic.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ namespace pl::ptrn {
5151

5252
void setOffset(u64 offset) override {
5353
for (auto &entry : this->m_entries) {
54-
if (entry->getSection() == this->getSection()) {
55-
if (entry->getSection() != ptrn::Pattern::PatternLocalSectionId)
56-
entry->setOffset(entry->getOffset() - this->getOffset() + offset);
57-
else
58-
entry->setOffset(offset);
59-
}
54+
if (entry->getSection() == this->getSection() && entry->getSection() != ptrn::Pattern::PatternLocalSectionId)
55+
entry->setOffset(entry->getOffset() - this->getOffset() + offset);
6056
}
6157

6258
Pattern::setOffset(offset);

lib/include/pl/patterns/pattern_bitfield.hpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,8 @@ namespace pl::ptrn {
388388

389389
void setOffset(u64 offset) override {
390390
for (auto &entry : this->m_entries) {
391-
if (entry->getSection() == this->getSection()) {
392-
if (entry->getSection() != ptrn::Pattern::PatternLocalSectionId)
393-
entry->setOffset(entry->getOffset() - this->getOffset() + offset);
394-
else
395-
entry->setOffset(offset);
396-
}
391+
if (entry->getSection() == this->getSection() && entry->getSection() != ptrn::Pattern::PatternLocalSectionId)
392+
entry->setOffset(entry->getOffset() - this->getOffset() + offset);
397393
}
398394

399395
PatternBitfieldMember::setOffset(offset);
@@ -759,12 +755,8 @@ namespace pl::ptrn {
759755

760756
void setOffset(u64 offset) override {
761757
for (auto &field : this->m_fields) {
762-
if (field->getSection() == this->getSection()) {
763-
if (field->getSection() != ptrn::Pattern::PatternLocalSectionId)
764-
field->setOffset(field->getOffset() - this->getOffset() + offset);
765-
else
766-
field->setOffset(offset);
767-
}
758+
if (field->getSection() == this->getSection() && field->getSection() != ptrn::Pattern::PatternLocalSectionId)
759+
field->setOffset(field->getOffset() - this->getOffset() + offset);
768760
}
769761

770762
PatternBitfieldMember::setOffset(offset);

lib/include/pl/patterns/pattern_struct.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ namespace pl::ptrn {
7272

7373
void setOffset(u64 offset) override {
7474
for (auto &member : this->m_members) {
75-
if (member->getSection() == this->getSection()) {
76-
if (member->getSection() != ptrn::Pattern::PatternLocalSectionId)
77-
member->setOffset(member->getOffset() - this->getOffset() + offset);
78-
else
79-
member->setOffset(offset);
80-
}
75+
if (member->getSection() == this->getSection() && member->getSection() != ptrn::Pattern::PatternLocalSectionId)
76+
member->setOffset(member->getOffset() - this->getOffset() + offset);
8177
}
8278

8379
Pattern::setOffset(offset);

lib/include/pl/patterns/pattern_union.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,8 @@ namespace pl::ptrn {
7171

7272
void setOffset(u64 offset) override {
7373
for (auto &member : this->m_members) {
74-
if (member->getSection() == this->getSection()) {
75-
if (member->getSection() != ptrn::Pattern::PatternLocalSectionId)
76-
member->setOffset(member->getOffset() - this->getOffset() + offset);
77-
else
78-
member->setOffset(offset);
79-
}
74+
if (member->getSection() == this->getSection() && member->getSection() != ptrn::Pattern::PatternLocalSectionId)
75+
member->setOffset(member->getOffset() - this->getOffset() + offset);
8076
}
8177

8278
Pattern::setOffset(offset);

0 commit comments

Comments
 (0)