Uploaded image for project: 'Mesos'
  1. Mesos
  2. MESOS-7877

Audit test code for undefined behavior in accessing container elements

    XMLWordPrintableJSON

Details

    • Mesosphere Sprint 62, Mesosphere Sprint 63, Mesosphere Sprint 64, Mesosphere Sprint 65
    • 2

    Description

      We do not always make sure we never access elements from empty containers, e.g., we use patterns like the following

      Future<vector<Offer>> offers;
      
      // Satisfy offers.
      
      EXPECT_FALSE(offers.empty());
      
      const auto& offer = (*offers)[0];
      

      While the intention here is to diagnose an empty offers, the code still exhibits undefined behavior in the element access if offers was indeed empty (compilers might aggressively exploit undefined behavior to e.g., remove "impossible" code). Instead one should prevent accessing any elements of an empty container, e.g.,

      ASSERT_FALSE(offers.empty()); // Prevent execution of rest of test body.
      

      We should audit and fix existing test code for such incorrect checks and variations involving e.g., EXPECT_NE.

      Attachments

        Activity

          People

            gkleiman Gastón Kleiman
            bbannier Benjamin Bannier
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: