Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e57cf2d6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "PDL: Tighten checks for nonexistent fields"

parents f85b89b6 070f89ec
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -160,12 +160,7 @@ Size ParentDef::GetSize(bool without_payload) const {
Size ParentDef::GetOffsetForField(std::string field_name, bool from_end) const {
  // Check first if the field exists.
  if (fields_.GetField(field_name) == nullptr) {
    if (field_name != "payload" && field_name != "body") {
      ERROR() << "Can't find a field offset for nonexistent field named: " << field_name;
    } else {
      // TODO: Why is this a good idea?
      return Size();
    }
    ERROR() << "Can't find a field offset for nonexistent field named: " << field_name << " in " << name_;
  }

  // We have to use a generic lambda to conditionally change iteration direction
@@ -196,16 +191,18 @@ Size ParentDef::GetOffsetForField(std::string field_name, bool from_end) const {

  // We need the offset until a payload or body field.
  if (parent_ != nullptr) {
    if (parent_->fields_.HasPayload()) {
      auto parent_payload_offset = parent_->GetOffsetForField("payload", from_end);
    if (!parent_payload_offset.empty()) {
      size += parent_payload_offset;
    } else {
      parent_payload_offset = parent_->GetOffsetForField("body", from_end);
      if (!parent_payload_offset.empty()) {
      if (parent_payload_offset.empty()) {
        ERROR() << "Empty offset for payload in " << parent_->name_ << " finding the offset for field: " << field_name;
      }
      size += parent_payload_offset;
    } else {
        return Size();
      auto parent_body_offset = parent_->GetOffsetForField("body", from_end);
      if (parent_body_offset.empty()) {
        ERROR() << "Empty offset for body in " << parent_->name_ << " finding the offset for field: " << field_name;
      }
      size += parent_body_offset;
    }
  }