# HG changeset patch # User John W. Eaton # Date 1492192841 14400 # Node ID 5e0350f5e2ddeefd19f952e3ef4d4f0a16f7cd39 # Parent d4ef04757ead7031ed3016fe391b1988a69a97c0 always return valid address for local buffers * oct-locbuf.h, oct-locbuf.cc (local_buffer::local_buffer): Always allocate, even for zero-size buffers. (chunk_buffer::chunk_buffer): Likewise. diff -r d4ef04757ead -r 5e0350f5e2dd liboctave/util/oct-locbuf.cc --- a/liboctave/util/oct-locbuf.cc Thu Apr 13 14:25:16 2017 -0400 +++ b/liboctave/util/oct-locbuf.cc Fri Apr 14 14:00:41 2017 -0400 @@ -57,10 +57,11 @@ ? 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 -r d4ef04757ead -r 5e0350f5e2dd liboctave/util/oct-locbuf.h --- a/liboctave/util/oct-locbuf.h Thu Apr 13 14:25:16 2017 -0400 +++ b/liboctave/util/oct-locbuf.h Fri Apr 14 14:00:41 2017 -0400 @@ -38,12 +38,12 @@ 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!