summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2018-03-24 16:35:30 +0100
committerDavid Tardon <dtardon@redhat.com>2018-03-24 16:36:53 +0100
commitd74029f409b124b731cd2f4a7bfc0bc93aaf438c (patch)
tree014ed69e0ea96c86c832752a20bdbcaa57eab42e
parentcf5bfaf2991c0c0ef37d2968ff2cf756b0b02089 (diff)
avoid manual memory allocation
-rw-r--r--src/lib/SW602MemoryStream.cpp9
-rw-r--r--src/lib/SW602MemoryStream.h4
2 files changed, 6 insertions, 7 deletions
diff --git a/src/lib/SW602MemoryStream.cpp b/src/lib/SW602MemoryStream.cpp
index c10faf0..5eb2a69 100644
--- a/src/lib/SW602MemoryStream.cpp
+++ b/src/lib/SW602MemoryStream.cpp
@@ -15,18 +15,15 @@ namespace libsw602
{
SW602MemoryStream::SW602MemoryStream(const unsigned char *data, unsigned length)
- : m_data(0)
+ : m_data(new unsigned char[length])
, m_length(length)
, m_pos(0)
{
- unsigned char *buffer = new unsigned char[length];
- std::copy(data, data + length, buffer);
- m_data = buffer;
+ std::copy(data, data + length, m_data.get());
}
SW602MemoryStream::~SW602MemoryStream()
{
- delete[] m_data;
}
bool SW602MemoryStream::isStructured()
@@ -73,7 +70,7 @@ const unsigned char *SW602MemoryStream::read(unsigned long numBytes, unsigned lo
m_pos += numBytes;
numBytesRead = numBytes;
- return m_data + oldPos;
+ return m_data.get() + oldPos;
}
int SW602MemoryStream::seek(const long offset, librevenge::RVNG_SEEK_TYPE seekType)
diff --git a/src/lib/SW602MemoryStream.h b/src/lib/SW602MemoryStream.h
index e422c7f..f4dcf54 100644
--- a/src/lib/SW602MemoryStream.h
+++ b/src/lib/SW602MemoryStream.h
@@ -10,6 +10,8 @@
#ifndef INCLUDED_SW602MEMORYSTREAM_H
#define INCLUDED_SW602MEMORYSTREAM_H
+#include <memory>
+
#include <librevenge-stream/librevenge-stream.h>
namespace libsw602
@@ -38,7 +40,7 @@ public:
virtual bool isEnd();
private:
- const unsigned char *m_data;
+ const std::unique_ptr<unsigned char> m_data;
const long m_length;
long m_pos;
};