Changeset 2380886 in rtems-tools


Ignore:
Timestamp:
Jul 16, 2021, 6:01:08 PM (2 months ago)
Author:
Alex White <alex.white@…>
Branches:
master
Children:
68348ad
Parents:
74bb938
git-author:
Alex White <alex.white@…> (07/16/21 18:01:08)
git-committer:
Joel Sherrill <joel@…> (07/20/21 18:24:28)
Message:

AddressToLineMapper?.h: Remove pointer to temporary string

CID 1505281: Pointer to local outside scope

Closes #4473

Location:
tester/covoar
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tester/covoar/AddressToLineMapper.cc

    r74bb938 r2380886  
    2020  }
    2121
    22   const std::string& SourceLine::path() const
     22  const std::string SourceLine::path() const
    2323  {
    24     return path_;
     24    if (!path_) {
     25      return "unknown";
     26    } else {
     27      return *path_;
     28    }
    2529  }
    2630
     
    3236  void AddressLineRange::addSourceLine(const rld::dwarf::address& address)
    3337  {
    34     auto insertResult = sourcePaths.insert(address.path());
     38    auto insertResult = sourcePaths.insert(
     39      std::make_shared<std::string>(address.path()));
    3540
    3641    sourceLines.emplace_back(
  • tester/covoar/AddressToLineMapper.h

    r74bb938 r2380886  
    99
    1010#include <cstdint>
     11#include <memory>
    1112#include <set>
    1213#include <string>
     
    2728    SourceLine()
    2829    : address(0),
    29       path_("unknown"),
     30      path_(nullptr),
    3031      line_num(-1),
    3132      is_end_sequence(true)
     
    3536    SourceLine(
    3637      uint64_t addr,
    37       const std::string& src,
     38      const std::shared_ptr<std::string>& src,
    3839      int line,
    3940      bool end_sequence
     
    6566     *  @return Returns the source file path of this address
    6667     */
    67     const std::string& path() const;
     68    const std::string path() const;
    6869
    6970    /*!
     
    8586     *  source file path of the address.
    8687     */
    87     const std::string& path_;
     88    const std::shared_ptr<std::string> path_;
    8889
    8990    /*!
     
    101102  typedef std::vector<SourceLine> SourceLines;
    102103
    103   typedef std::set<std::string> SourcePaths;
     104  /* This allows comparison of strings owned by shared_ptrs. */
     105  struct SharedStringCmp {
     106    bool operator()(
     107      const std::shared_ptr<std::string>& lhs,
     108      const std::shared_ptr<std::string>& rhs
     109    ) const {
     110      return *lhs < *rhs;
     111    }
     112  };
     113
     114  typedef std::set<std::shared_ptr<std::string>, SharedStringCmp> SourcePaths;
    104115
    105116  /*! @class AddressLineRange
Note: See TracChangeset for help on using the changeset viewer.