Daniel Carvalho has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/43591 )

Change subject: base: Avoid dereferencing end() in findNearest
......................................................................

base: Avoid dereferencing end() in findNearest

When used with next_addr, findNearest will return the
next (even larger) address than the nearest larger
address. The problem is that when there is no valid
next, the function was dereferencing addrMap.end().

Fix this by marking next address as 0, since 0 is
not larger than any other address.

Places that use this function should be revisited
to make sure they account for this behavior, as
reported in the following Jira issue:
https://gem5.atlassian.net/browse/GEM5-936

Change-Id: I29ed80ff921b205209aeb5db05ffd3019d8595ce
Signed-off-by: Daniel R. Carvalho <[email protected]>
---
M src/base/loader/symtab.hh
1 file changed, 10 insertions(+), 3 deletions(-)



diff --git a/src/base/loader/symtab.hh b/src/base/loader/symtab.hh
index 0449f54..063afe7 100644
--- a/src/base/loader/symtab.hh
+++ b/src/base/loader/symtab.hh
@@ -343,8 +343,9 @@
     }

     /**
-     * Find the nearest symbol equal to or less than the supplied
-     * address (e.g., the label for the enclosing function).
+     * Find the nearest symbol equal to or less than the supplied address
+     * (e.g., the label for the enclosing function). If there is no valid
+     * next address, next_addr is assigned 0.
      *
      * @param addr      The address to look up.
      * @param next_addr Address of following symbol (to determine the valid
@@ -358,7 +359,13 @@
         if (!upperBound(addr, i))
             return end();

-        next_addr = i->first;
+ // If there is no next address, make it 0 since 0 is not larger than
+        // any other address, so it is clear that next is not valid
+        if (i == addrMap.end()) {
+            next_addr = 0;
+        } else {
+            next_addr = i->first;
+        }
         --i;
         return symbols.begin() + i->second;
     }

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/43591
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I29ed80ff921b205209aeb5db05ffd3019d8595ce
Gerrit-Change-Number: 43591
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to