From ffec628c64faa4d15dc006240b17c0a7213c2b2a Mon Sep 17 00:00:00 2001 From: Eddie Elizondo Date: Mon, 15 Nov 2021 10:34:43 -0500 Subject: [PATCH] Add comment to sorting function --- src/cc/usdt/usdt.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cc/usdt/usdt.cc b/src/cc/usdt/usdt.cc index bd3f26517127..e3d0c4417e37 100644 --- a/src/cc/usdt/usdt.cc +++ b/src/cc/usdt/usdt.cc @@ -220,6 +220,10 @@ void Probe::add_location(uint64_t addr, const std::string &bin_path, const char } void Probe::finalize_locations() { + // The following comparator needs to establish a strict weak ordering relation. Such + // that when x < y == true, y < x == false. Otherwise it leads to undefined behavior. + // To guarantee this, it uses std::tie which allows the lambda to have a lexicographical + // comparison and hence, guarantee the strict weak ordering. std::sort(locations_.begin(), locations_.end(), [](const Location &a, const Location &b) { return std::tie(a.bin_path_, a.address_) < std::tie(b.bin_path_, b.address_);