Boost C++ Libraries: Ticket #2752: Wrong size check in bounded_array::resize https://svn.boost.org/trac10/ticket/2752 <p> The resize methods in the bounded_array class, in the file boost/numeric/ublas/storage.hpp, are defined as </p> <pre class="wiki"> // Resizing BOOST_UBLAS_INLINE void resize (size_type size) { BOOST_UBLAS_CHECK (size_ &lt;= N, bad_size ()); size_ = size; } BOOST_UBLAS_INLINE void resize (size_type size, value_type init) { BOOST_UBLAS_CHECK (size_ &lt;= N, bad_size ()); if (size &gt; size_) std::fill (data_ + size_, data_ + size, init); size_ = size; } </pre><p> Shouldn't the BOOST_UBLAS_CHECKs test for size &lt; N? As the checks are written now, it is possible to assign a new size that is larger than N. </p> <p> Ulf </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2752 Trac 1.4.3 Steven Watanabe Thu, 12 Feb 2009 17:35:19 GMT <link>https://svn.boost.org/trac10/ticket/2752#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2752#comment:1</guid> <description> <p> How can the size be larger than N? </p> <p> It should be okay to set the size equal to N, because there is storage for N elements, right? If size is greater than N, then it will be caught by the BOOST_UBLAS_CHECK. </p> <p> What am I missing? </p> </description> <category>Ticket</category> </item> <item> <author>Ulf Olin <ulf.olin@…></author> <pubDate>Thu, 12 Feb 2009 18:43:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2752#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2752#comment:2</guid> <description> <p> Say that you have have created a bounded_array with three elements (N=3 and size_=3). Then you, by mistake, try to resize that bounded_array to hold four elements. That is, your code is </p> <pre class="wiki">#include &lt;boost/numeric/ublas/storage.hpp&gt; int main () { using namespace boost::numeric::ublas; bounded_array&lt;double, 3&gt; a (3); a.resize(4); // Should result in an exception, but it doesn't! } </pre><p> The solution for the definition of the resize function is either to check the function argument, size, instead of the member size_, or to first do the assignment statement and then the check. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Gunter</dc:creator> <pubDate>Mon, 05 Oct 2009 21:51:20 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2752#comment:3 https://svn.boost.org/trac10/ticket/2752#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> fixed long time ago in <a class="changeset" href="https://svn.boost.org/trac10/changeset/52145" title="ublas/expression_types.hpp: added typedef ublas_expression::self_type ...">[52145]</a> </p> Ticket