summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-03-04 20:58:26 +0000
committerAndras Timar <andras.timar@collabora.com>2017-04-23 20:45:56 +0200
commit9cc023171311931337cf3f58d0a777e583ddcf1e (patch)
tree4f4d75b3ea6856b862db191fb7f9058ffd22e876
parent3f5c33f4bc1d0e367d12abb73a9f94484d290960 (diff)
Resolves: ofz#727 don't allow negative sizes or indexes
remove extra size in favour of vector size and don't resize and memcpy data, just use vector::insert Change-Id: I8efb91a8c11fbd862c0458042554cf7e94b813cd Reviewed-on: https://gerrit.libreoffice.org/34893 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com> (cherry picked from commit 789dc289b8b7ff79a6195e8648d0ac6be5cf13bb) (cherry picked from commit f4e6a22c27ef5ce3ecb046ecd88a1dc0b37c7870)
-rw-r--r--hwpfilter/source/hstream.cxx21
-rw-r--r--hwpfilter/source/hstream.hxx11
2 files changed, 15 insertions, 17 deletions
diff --git a/hwpfilter/source/hstream.cxx b/hwpfilter/source/hstream.cxx
index 6a0d59f48048..6b5bf98cb35d 100644
--- a/hwpfilter/source/hstream.cxx
+++ b/hwpfilter/source/hstream.cxx
@@ -22,38 +22,37 @@
#include "hstream.hxx"
HStream::HStream()
- : size(0)
- , pos(0)
+ : pos(0)
{
}
-void HStream::addData(const byte *buf, int aToAdd)
+void HStream::addData(const byte *buf, size_t aToAdd)
{
- seq.resize(size + aToAdd);
- memcpy(seq.data() + size, buf, aToAdd);
- size += aToAdd;
+ seq.insert(seq.end(), buf, buf + aToAdd);
}
-int HStream::readBytes(byte * buf, int aToRead)
+size_t HStream::readBytes(byte * buf, size_t aToRead)
{
+ auto size = seq.size();
if (aToRead >= (size - pos))
aToRead = size - pos;
- for (int i = 0; i < aToRead; i++)
+ for (size_t i = 0; i < aToRead; ++i)
buf[i] = seq[pos++];
return aToRead;
}
-int HStream::skipBytes(int aToSkip)
+size_t HStream::skipBytes(size_t aToSkip)
{
+ auto size = seq.size();
if (aToSkip >= (size - pos))
aToSkip = size - pos;
pos += aToSkip;
return aToSkip;
}
-int HStream::available() const
+size_t HStream::available() const
{
- return size - pos;
+ return seq.size() - pos;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hstream.hxx b/hwpfilter/source/hstream.hxx
index 4374b92674e3..e6654f707dde 100644
--- a/hwpfilter/source/hstream.hxx
+++ b/hwpfilter/source/hstream.hxx
@@ -34,24 +34,23 @@ class HStream
/**
*
*/
- void addData( const byte *buf, int aToAdd);
+ void addData( const byte *buf, size_t aToAdd);
/**
* Read some byte to buf as given size
*/
- int readBytes( byte *buf, int aToRead);
+ size_t readBytes( byte *buf, size_t aToRead);
/**
* Skip some byte from stream as given size
*/
- int skipBytes( int aToSkip );
+ size_t skipBytes( size_t aToSkip );
/**
* @returns Size of remained stream
*/
- int available() const;
+ size_t available() const;
private:
- int size;
std::vector<byte> seq;
- int pos;
+ size_t pos;
};
#endif