diff --git a/liboctave/util/oct-locbuf.cc b/liboctave/util/oct-locbuf.cc --- a/liboctave/util/oct-locbuf.cc +++ b/liboctave/util/oct-locbuf.cc @@ -57,10 +57,11 @@ namespace octave ? sizeof (double) : sizeof (long)) - 1; - active++; + // Always allocate, even for zero-size buffers so that local buffers + // always have valid addresses, same as for directly using operator + // new. - if (! size) - return; + active++; // Align size. Note that size_t is unsigned, so size-1 must correctly // wrap around. diff --git a/liboctave/util/oct-locbuf.h b/liboctave/util/oct-locbuf.h --- a/liboctave/util/oct-locbuf.h +++ b/liboctave/util/oct-locbuf.h @@ -38,12 +38,12 @@ namespace octave class local_buffer { public: - local_buffer (size_t size) - : data (0) - { - if (size) - data = new T [size]; - } + + // Always allocate, even for zero-size buffers so that local + // buffers always have valid addresses, same as for directly using + // operator new. + + local_buffer (size_t size) : data (new T [size]) { } // No copying!