Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Mar 2019 12:57:33 +0100
From:      Willem Jan Withagen <wjw@digiware.nl>
To:        FreeBSD Toolchain <freebsd-toolchain@freebsd.org>
Subject:   Is this a programming error, or a compiler error..
Message-ID:  <bc4f8f4f-55c9-63ed-1ce8-b53d95a0696a@digiware.nl>

next in thread | raw e-mail | index | archive | help
Hi,

I'm getting a crash in a Ceph test program in the following pice of code:

struct entity_addrvec_t {
   vector<entity_addr_t> v;
.....
   entity_addr_t legacy_addr() const {
     for (auto& a : v) {
       if (a.type == entity_addr_t::TYPE_LEGACY) {
         return a;
       }
     }
     return entity_addr_t();
   }
......

Where the loop is taken, even if v.size() == 0
So v content is pointing to random memory and itterating over the next 
pointer results in a crash.

I would expect the loop not to be executed....

--WjW




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bc4f8f4f-55c9-63ed-1ce8-b53d95a0696a>